Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12629 lines
298 KiB

  1. /*++ BUILD Version: 0186 // Increment this if a change has global effects
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. wdm.h
  5. Abstract:
  6. This module defines the WDM types, constants, and functions that are
  7. exposed to device drivers.
  8. Revision History:
  9. --*/
  10. #ifndef _WDMDDK_
  11. #define _WDMDDK_
  12. #define _NTDDK_
  13. #define NT_INCLUDED
  14. #define _CTYPE_DISABLE_MACROS
  15. #include <excpt.h>
  16. #include <ntdef.h>
  17. #include <ntstatus.h>
  18. #include <bugcodes.h>
  19. #include <exlevels.h>
  20. #include <ntiologc.h>
  21. #include <ntpoapi.h>
  22. //
  23. // Define types that are not exported.
  24. //
  25. typedef struct _KTHREAD *PKTHREAD;
  26. typedef struct _ETHREAD *PETHREAD;
  27. typedef struct _EPROCESS *PEPROCESS;
  28. typedef struct _KINTERRUPT *PKINTERRUPT;
  29. typedef struct _IO_TIMER *PIO_TIMER;
  30. typedef struct _OBJECT_TYPE *POBJECT_TYPE;
  31. typedef struct _CALLBACK_OBJECT *PCALLBACK_OBJECT;
  32. #if defined(_M_ALPHA)
  33. void *__rdthread(void);
  34. #pragma intrinsic(__rdthread)
  35. unsigned char __swpirql(unsigned char);
  36. #pragma intrinsic(__swpirql)
  37. void *__rdpcr(void);
  38. #pragma intrinsic(__rdpcr)
  39. #define PCR ((PKPCR)__rdpcr())
  40. #define KeGetCurrentThread() ((struct _KTHREAD *) __rdthread())
  41. KIRQL KeGetCurrentIrql();
  42. #endif // defined(_M_ALPHA)
  43. #if defined(_M_MRX000)
  44. #define KIPCR 0xfffff000
  45. #define PCR ((volatile KPCR * const)KIPCR)
  46. #define KeGetCurrentThread() PCR->CurrentThread
  47. #define KeGetCurrentIrql() PCR->CurrentIrql
  48. #endif // defined(_M_MRX000)
  49. #if defined(_M_IX86)
  50. PKTHREAD NTAPI KeGetCurrentThread();
  51. #endif // defined(_M_IX86)
  52. #define PsGetCurrentProcess() IoGetCurrentProcess()
  53. #define PsGetCurrentThread() ((PETHREAD) (KeGetCurrentThread()))
  54. extern NTSYSAPI CCHAR KeNumberProcessors;
  55. typedef union _SLIST_HEADER {
  56. ULONGLONG Alignment;
  57. struct {
  58. SINGLE_LIST_ENTRY Next;
  59. USHORT Depth;
  60. USHORT Sequence;
  61. };
  62. } SLIST_HEADER, *PSLIST_HEADER;
  63. //
  64. // Define fastcall decoration for functions.
  65. //
  66. #if defined(_M_IX86)
  67. #define FASTCALL _fastcall
  68. #else
  69. #define FASTCALL
  70. #endif
  71. #define POOL_TAGGING 1
  72. #ifndef DBG
  73. #define DBG 0
  74. #endif
  75. #if DBG
  76. #define IF_DEBUG if (TRUE)
  77. #else
  78. #define IF_DEBUG if (FALSE)
  79. #endif
  80. #if DEVL
  81. //
  82. // Global flag set by NtPartyByNumber(6) controls behaviour of
  83. // NT. See \nt\sdk\inc\ntexapi.h for flag definitions
  84. //
  85. extern ULONG NtGlobalFlag;
  86. #define IF_NTOS_DEBUG( FlagName ) \
  87. if (NtGlobalFlag & (FLG_ ## FlagName))
  88. #else
  89. #define IF_NTOS_DEBUG( FlagName ) if (FALSE)
  90. #endif
  91. //
  92. // Kernel definitions that need to be here for forward reference purposes
  93. //
  94. // begin_ntndis
  95. //
  96. // Processor modes.
  97. //
  98. typedef CCHAR KPROCESSOR_MODE;
  99. typedef enum _MODE {
  100. KernelMode,
  101. UserMode,
  102. MaximumMode
  103. } MODE;
  104. // end_ntndis
  105. //
  106. // APC function types
  107. //
  108. //
  109. // Put in an empty definition for the KAPC so that the
  110. // routines can reference it before it is declared.
  111. //
  112. struct _KAPC;
  113. typedef
  114. VOID
  115. (*PKNORMAL_ROUTINE) (
  116. IN PVOID NormalContext,
  117. IN PVOID SystemArgument1,
  118. IN PVOID SystemArgument2
  119. );
  120. typedef
  121. VOID
  122. (*PKKERNEL_ROUTINE) (
  123. IN struct _KAPC *Apc,
  124. IN OUT PKNORMAL_ROUTINE *NormalRoutine,
  125. IN OUT PVOID *NormalContext,
  126. IN OUT PVOID *SystemArgument1,
  127. IN OUT PVOID *SystemArgument2
  128. );
  129. typedef
  130. VOID
  131. (*PKRUNDOWN_ROUTINE) (
  132. IN struct _KAPC *Apc
  133. );
  134. typedef
  135. BOOLEAN
  136. (*PKSYNCHRONIZE_ROUTINE) (
  137. IN PVOID SynchronizeContext
  138. );
  139. typedef
  140. BOOLEAN
  141. (*PKTRANSFER_ROUTINE) (
  142. VOID
  143. );
  144. //
  145. //
  146. // Asynchronous Procedure Call (APC) object
  147. //
  148. typedef struct _KAPC {
  149. CSHORT Type;
  150. CSHORT Size;
  151. ULONG Spare0;
  152. struct _KTHREAD *Thread;
  153. LIST_ENTRY ApcListEntry;
  154. PKKERNEL_ROUTINE KernelRoutine;
  155. PKRUNDOWN_ROUTINE RundownRoutine;
  156. PKNORMAL_ROUTINE NormalRoutine;
  157. PVOID NormalContext;
  158. //
  159. // N.B. The following two members MUST be together.
  160. //
  161. PVOID SystemArgument1;
  162. PVOID SystemArgument2;
  163. CCHAR ApcStateIndex;
  164. KPROCESSOR_MODE ApcMode;
  165. BOOLEAN Inserted;
  166. } KAPC, *PKAPC, *RESTRICTED_POINTER PRKAPC;
  167. // begin_ntndis
  168. //
  169. // DPC routine
  170. //
  171. struct _KDPC;
  172. typedef
  173. VOID
  174. (*PKDEFERRED_ROUTINE) (
  175. IN struct _KDPC *Dpc,
  176. IN PVOID DeferredContext,
  177. IN PVOID SystemArgument1,
  178. IN PVOID SystemArgument2
  179. );
  180. //
  181. // Define DPC importance.
  182. //
  183. // LowImportance - Queue DPC at end of target DPC queue.
  184. // MediumImportance - Queue DPC at front of target DPC queue.
  185. // HighImportance - Queue DPC at front of target DPC DPC queue and interrupt
  186. // the target processor if the DPC is targeted and the system is an MP
  187. // system.
  188. //
  189. // N.B. If the target processor is the same as the processor on which the DPC
  190. // is queued on, then the processor is always interrupted if the DPC queue
  191. // was previously empty.
  192. //
  193. typedef enum _KDPC_IMPORTANCE {
  194. LowImportance,
  195. MediumImportance,
  196. HighImportance
  197. } KDPC_IMPORTANCE;
  198. //
  199. // Deferred Procedure Call (DPC) object
  200. //
  201. typedef struct _KDPC {
  202. CSHORT Type;
  203. UCHAR Number;
  204. UCHAR Importance;
  205. LIST_ENTRY DpcListEntry;
  206. PKDEFERRED_ROUTINE DeferredRoutine;
  207. PVOID DeferredContext;
  208. PVOID SystemArgument1;
  209. PVOID SystemArgument2;
  210. PULONG Lock;
  211. } KDPC, *PKDPC, *RESTRICTED_POINTER PRKDPC;
  212. //
  213. // Interprocessor interrupt worker routine function prototype.
  214. //
  215. typedef PULONG PKIPI_CONTEXT;
  216. typedef
  217. VOID
  218. (*PKIPI_WORKER)(
  219. IN PKIPI_CONTEXT PacketContext,
  220. IN PVOID Parameter1,
  221. IN PVOID Parameter2,
  222. IN PVOID Parameter3
  223. );
  224. //
  225. // Define interprocessor interrupt performance counters.
  226. //
  227. typedef struct _KIPI_COUNTS {
  228. ULONG Freeze;
  229. ULONG Packet;
  230. ULONG DPC;
  231. ULONG APC;
  232. ULONG FlushSingleTb;
  233. ULONG FlushMultipleTb;
  234. ULONG FlushEntireTb;
  235. ULONG GenericCall;
  236. ULONG ChangeColor;
  237. ULONG SweepDcache;
  238. ULONG SweepIcache;
  239. ULONG SweepIcacheRange;
  240. ULONG FlushIoBuffers;
  241. ULONG GratuitousDPC;
  242. } KIPI_COUNTS, *PKIPI_COUNTS;
  243. #if defined(NT_UP)
  244. #define HOT_STATISTIC(a) a
  245. #else
  246. #define HOT_STATISTIC(a) (KeGetCurrentPrcb()->a)
  247. #endif
  248. //
  249. // I/O system definitions.
  250. //
  251. // Define a Memory Descriptor List (MDL)
  252. //
  253. // An MDL describes pages in a virtual buffer in terms of physical pages. The
  254. // pages associated with the buffer are described in an array that is allocated
  255. // just after the MDL header structure itself. In a future compiler this will
  256. // be placed at:
  257. //
  258. // ULONG Pages[];
  259. //
  260. // Until this declaration is permitted, however, one simply calculates the
  261. // base of the array by adding one to the base MDL pointer:
  262. //
  263. // Pages = (PULONG) (Mdl + 1);
  264. //
  265. // Notice that while in the context of the subject thread, the base virtual
  266. // address of a buffer mapped by an MDL may be referenced using the following:
  267. //
  268. // Mdl->StartVa | Mdl->ByteOffset
  269. //
  270. // NOTE: If MDL_64_BIT_VA flag is set, the StartVa field contains
  271. // the Virtual Page Number (VirtualAddress / PAGE_SIZE).
  272. // HENCE, the reference to the base virtual address becomes:
  273. //
  274. // (PVOID64)(((LONG LONG)Mdl->StartVa << PAGE_SHIFT) | Mdl->ByteOffset)
  275. //
  276. typedef struct _MDL {
  277. struct _MDL *Next;
  278. CSHORT Size;
  279. CSHORT MdlFlags;
  280. struct _EPROCESS *Process;
  281. PVOID MappedSystemVa;
  282. PVOID StartVa;
  283. ULONG ByteCount;
  284. ULONG ByteOffset;
  285. } MDL, *PMDL;
  286. #define MDL_MAPPED_TO_SYSTEM_VA 0x0001
  287. #define MDL_PAGES_LOCKED 0x0002
  288. #define MDL_SOURCE_IS_NONPAGED_POOL 0x0004
  289. #define MDL_ALLOCATED_FIXED_SIZE 0x0008
  290. #define MDL_PARTIAL 0x0010
  291. #define MDL_PARTIAL_HAS_BEEN_MAPPED 0x0020
  292. #define MDL_IO_PAGE_READ 0x0040
  293. #define MDL_WRITE_OPERATION 0x0080
  294. #define MDL_PARENT_MAPPED_SYSTEM_VA 0x0100
  295. #define MDL_LOCK_HELD 0x0200
  296. #define MDL_SYSTEM_VA 0x0400
  297. #define MDL_IO_SPACE 0x0800
  298. #define MDL_NETWORK_HEADER 0x1000
  299. #define MDL_MAPPING_CAN_FAIL 0x2000
  300. #define MDL_ALLOCATED_MUST_SUCCEED 0x4000
  301. #define MDL_64_BIT_VA 0x8000
  302. #define MDL_MAPPING_FLAGS (MDL_MAPPED_TO_SYSTEM_VA | \
  303. MDL_PAGES_LOCKED | \
  304. MDL_SOURCE_IS_NONPAGED_POOL | \
  305. MDL_PARTIAL_HAS_BEEN_MAPPED | \
  306. MDL_PARENT_MAPPED_SYSTEM_VA | \
  307. MDL_LOCK_HELD | \
  308. MDL_SYSTEM_VA | \
  309. MDL_IO_SPACE )
  310. // end_ntndis
  311. //
  312. // switch to DBG when appropriate
  313. //
  314. #if DBG
  315. #define PAGED_CODE() \
  316. if (KeGetCurrentIrql() > APC_LEVEL) { \
  317. KdPrint(( "EX: Pageable code called at IRQL %d\n", KeGetCurrentIrql() )); \
  318. ASSERT(FALSE); \
  319. }
  320. #else
  321. #define PAGED_CODE()
  322. #endif
  323. //
  324. // A PCI driver can read the complete 256 bytes of configuration
  325. // information for any PCI device by calling:
  326. //
  327. // ULONG
  328. // HalGetBusData (
  329. // IN BUS_DATA_TYPE PCIConfiguration,
  330. // IN ULONG PciBusNumber,
  331. // IN PCI_SLOT_NUMBER VirtualSlotNumber,
  332. // IN PPCI_COMMON_CONFIG &PCIDeviceConfig,
  333. // IN ULONG sizeof (PCIDeviceConfig)
  334. // );
  335. //
  336. // A return value of 0 means that the specified PCI bus does not exist.
  337. //
  338. // A return value of 2, with a VendorID of PCI_INVALID_VENDORID means
  339. // that the PCI bus does exist, but there is no device at the specified
  340. // VirtualSlotNumber (PCI Device/Function number).
  341. //
  342. //
  343. // begin_ntminiport
  344. typedef struct _PCI_SLOT_NUMBER {
  345. union {
  346. struct {
  347. ULONG DeviceNumber:5;
  348. ULONG FunctionNumber:3;
  349. ULONG Reserved:24;
  350. } bits;
  351. ULONG AsULONG;
  352. } u;
  353. } PCI_SLOT_NUMBER, *PPCI_SLOT_NUMBER;
  354. #define PCI_TYPE0_ADDRESSES 6
  355. #define PCI_TYPE1_ADDRESSES 2
  356. typedef struct _PCI_COMMON_CONFIG {
  357. USHORT VendorID; // (ro)
  358. USHORT DeviceID; // (ro)
  359. USHORT Command; // Device control
  360. USHORT Status;
  361. UCHAR RevisionID; // (ro)
  362. UCHAR ProgIf; // (ro)
  363. UCHAR SubClass; // (ro)
  364. UCHAR BaseClass; // (ro)
  365. UCHAR CacheLineSize; // (ro+)
  366. UCHAR LatencyTimer; // (ro+)
  367. UCHAR HeaderType; // (ro)
  368. UCHAR BIST; // Built in self test
  369. union {
  370. struct _PCI_HEADER_TYPE_0 {
  371. ULONG BaseAddresses[PCI_TYPE0_ADDRESSES];
  372. ULONG CIS;
  373. USHORT SubVendorID;
  374. USHORT SubSystemID;
  375. ULONG ROMBaseAddress;
  376. ULONG Reserved2[2];
  377. UCHAR InterruptLine; //
  378. UCHAR InterruptPin; // (ro)
  379. UCHAR MinimumGrant; // (ro)
  380. UCHAR MaximumLatency; // (ro)
  381. } type0;
  382. } u;
  383. UCHAR DeviceSpecific[192];
  384. } PCI_COMMON_CONFIG, *PPCI_COMMON_CONFIG;
  385. #define PCI_COMMON_HDR_LENGTH (FIELD_OFFSET (PCI_COMMON_CONFIG, DeviceSpecific))
  386. #define PCI_MAX_DEVICES 32
  387. #define PCI_MAX_FUNCTION 8
  388. #define PCI_INVALID_VENDORID 0xFFFF
  389. //
  390. // Bit encodings for PCI_COMMON_CONFIG.HeaderType
  391. //
  392. #define PCI_MULTIFUNCTION 0x80
  393. #define PCI_DEVICE_TYPE 0x00
  394. #define PCI_BRIDGE_TYPE 0x01
  395. //
  396. // Bit encodings for PCI_COMMON_CONFIG.Command
  397. //
  398. #define PCI_ENABLE_IO_SPACE 0x0001
  399. #define PCI_ENABLE_MEMORY_SPACE 0x0002
  400. #define PCI_ENABLE_BUS_MASTER 0x0004
  401. #define PCI_ENABLE_SPECIAL_CYCLES 0x0008
  402. #define PCI_ENABLE_WRITE_AND_INVALIDATE 0x0010
  403. #define PCI_ENABLE_VGA_COMPATIBLE_PALETTE 0x0020
  404. #define PCI_ENABLE_PARITY 0x0040 // (ro+)
  405. #define PCI_ENABLE_WAIT_CYCLE 0x0080 // (ro+)
  406. #define PCI_ENABLE_SERR 0x0100 // (ro+)
  407. #define PCI_ENABLE_FAST_BACK_TO_BACK 0x0200 // (ro)
  408. //
  409. // Bit encodings for PCI_COMMON_CONFIG.Status
  410. //
  411. #define PCI_STATUS_FAST_BACK_TO_BACK 0x0080 // (ro)
  412. #define PCI_STATUS_DATA_PARITY_DETECTED 0x0100
  413. #define PCI_STATUS_DEVSEL 0x0600 // 2 bits wide
  414. #define PCI_STATUS_SIGNALED_TARGET_ABORT 0x0800
  415. #define PCI_STATUS_RECEIVED_TARGET_ABORT 0x1000
  416. #define PCI_STATUS_RECEIVED_MASTER_ABORT 0x2000
  417. #define PCI_STATUS_SIGNALED_SYSTEM_ERROR 0x4000
  418. #define PCI_STATUS_DETECTED_PARITY_ERROR 0x8000
  419. //
  420. // Bit encodes for PCI_COMMON_CONFIG.u.type0.BaseAddresses
  421. //
  422. #define PCI_ADDRESS_IO_SPACE 0x00000001 // (ro)
  423. #define PCI_ADDRESS_MEMORY_TYPE_MASK 0x00000006 // (ro)
  424. #define PCI_ADDRESS_MEMORY_PREFETCHABLE 0x00000008 // (ro)
  425. #define PCI_TYPE_32BIT 0
  426. #define PCI_TYPE_20BIT 2
  427. #define PCI_TYPE_64BIT 4
  428. //
  429. // Bit encodes for PCI_COMMON_CONFIG.u.type0.ROMBaseAddresses
  430. //
  431. #define PCI_ROMADDRESS_ENABLED 0x00000001
  432. //
  433. // Reference notes for PCI configuration fields:
  434. //
  435. // ro these field are read only. changes to these fields are ignored
  436. //
  437. // ro+ these field are intended to be read only and should be initialized
  438. // by the system to their proper values. However, driver may change
  439. // these settings.
  440. //
  441. // ---
  442. //
  443. // All resources comsumed by a PCI device start as unitialized
  444. // under NT. An uninitialized memory or I/O base address can be
  445. // determined by checking it's corrisponding enabled bit in the
  446. // PCI_COMMON_CONFIG.Command value. An InterruptLine is unitialized
  447. // if it contains the value of -1.
  448. //
  449. // end_ntminiport
  450. //
  451. // Define an access token from a programmer's viewpoint. The structure is
  452. // completely opaque and the programer is only allowed to have pointers
  453. // to tokens.
  454. //
  455. typedef PVOID PACCESS_TOKEN; // winnt
  456. //
  457. // Pointer to a SECURITY_DESCRIPTOR opaque data type.
  458. //
  459. typedef PVOID PSECURITY_DESCRIPTOR; // winnt
  460. //
  461. // Define a pointer to the Security ID data type (an opaque data type)
  462. //
  463. typedef PVOID PSID; // winnt
  464. typedef ULONG ACCESS_MASK;
  465. typedef ACCESS_MASK *PACCESS_MASK;
  466. // end_winnt
  467. //
  468. // The following are masks for the predefined standard access types
  469. //
  470. #define DELETE (0x00010000L)
  471. #define READ_CONTROL (0x00020000L)
  472. #define WRITE_DAC (0x00040000L)
  473. #define WRITE_OWNER (0x00080000L)
  474. #define SYNCHRONIZE (0x00100000L)
  475. #define STANDARD_RIGHTS_REQUIRED (0x000F0000L)
  476. #define STANDARD_RIGHTS_READ (READ_CONTROL)
  477. #define STANDARD_RIGHTS_WRITE (READ_CONTROL)
  478. #define STANDARD_RIGHTS_EXECUTE (READ_CONTROL)
  479. #define STANDARD_RIGHTS_ALL (0x001F0000L)
  480. #define SPECIFIC_RIGHTS_ALL (0x0000FFFFL)
  481. //
  482. // AccessSystemAcl access type
  483. //
  484. #define ACCESS_SYSTEM_SECURITY (0x01000000L)
  485. //
  486. // MaximumAllowed access type
  487. //
  488. #define MAXIMUM_ALLOWED (0x02000000L)
  489. //
  490. // These are the generic rights.
  491. //
  492. #define GENERIC_READ (0x80000000L)
  493. #define GENERIC_WRITE (0x40000000L)
  494. #define GENERIC_EXECUTE (0x20000000L)
  495. #define GENERIC_ALL (0x10000000L)
  496. //
  497. // Define the generic mapping array. This is used to denote the
  498. // mapping of each generic access right to a specific access mask.
  499. //
  500. typedef struct _GENERIC_MAPPING {
  501. ACCESS_MASK GenericRead;
  502. ACCESS_MASK GenericWrite;
  503. ACCESS_MASK GenericExecute;
  504. ACCESS_MASK GenericAll;
  505. } GENERIC_MAPPING;
  506. typedef GENERIC_MAPPING *PGENERIC_MAPPING;
  507. ////////////////////////////////////////////////////////////////////////
  508. // //
  509. // LUID_AND_ATTRIBUTES //
  510. // //
  511. ////////////////////////////////////////////////////////////////////////
  512. //
  513. //
  514. #include <pshpack4.h>
  515. typedef struct _LUID_AND_ATTRIBUTES {
  516. LUID Luid;
  517. ULONG Attributes;
  518. } LUID_AND_ATTRIBUTES, * PLUID_AND_ATTRIBUTES;
  519. typedef LUID_AND_ATTRIBUTES LUID_AND_ATTRIBUTES_ARRAY[ANYSIZE_ARRAY];
  520. typedef LUID_AND_ATTRIBUTES_ARRAY *PLUID_AND_ATTRIBUTES_ARRAY;
  521. #include <poppack.h>
  522. // This is the *current* ACL revision
  523. #define ACL_REVISION (2)
  524. // This is the history of ACL revisions. Add a new one whenever
  525. // ACL_REVISION is updated
  526. #define ACL_REVISION1 (1)
  527. #define ACL_REVISION2 (2)
  528. #define ACL_REVISION3 (3)
  529. typedef struct _ACL {
  530. UCHAR AclRevision;
  531. UCHAR Sbz1;
  532. USHORT AclSize;
  533. USHORT AceCount;
  534. USHORT Sbz2;
  535. } ACL;
  536. typedef ACL *PACL;
  537. //
  538. // Current security descriptor revision value
  539. //
  540. #define SECURITY_DESCRIPTOR_REVISION (1)
  541. #define SECURITY_DESCRIPTOR_REVISION1 (1)
  542. //
  543. // Privilege attributes
  544. //
  545. #define SE_PRIVILEGE_ENABLED_BY_DEFAULT (0x00000001L)
  546. #define SE_PRIVILEGE_ENABLED (0x00000002L)
  547. #define SE_PRIVILEGE_USED_FOR_ACCESS (0x80000000L)
  548. //
  549. // Privilege Set Control flags
  550. //
  551. #define PRIVILEGE_SET_ALL_NECESSARY (1)
  552. //
  553. // Privilege Set - This is defined for a privilege set of one.
  554. // If more than one privilege is needed, then this structure
  555. // will need to be allocated with more space.
  556. //
  557. // Note: don't change this structure without fixing the INITIAL_PRIVILEGE_SET
  558. // structure (defined in se.h)
  559. //
  560. typedef struct _PRIVILEGE_SET {
  561. ULONG PrivilegeCount;
  562. ULONG Control;
  563. LUID_AND_ATTRIBUTES Privilege[ANYSIZE_ARRAY];
  564. } PRIVILEGE_SET, * PPRIVILEGE_SET;
  565. //
  566. // These must be converted to LUIDs before use.
  567. //
  568. #define SE_MIN_WELL_KNOWN_PRIVILEGE (2L)
  569. #define SE_CREATE_TOKEN_PRIVILEGE (2L)
  570. #define SE_ASSIGNPRIMARYTOKEN_PRIVILEGE (3L)
  571. #define SE_LOCK_MEMORY_PRIVILEGE (4L)
  572. #define SE_INCREASE_QUOTA_PRIVILEGE (5L)
  573. //
  574. // Unsolicited Input is obsolete and unused.
  575. //
  576. #define SE_UNSOLICITED_INPUT_PRIVILEGE (6L)
  577. #define SE_MACHINE_ACCOUNT_PRIVILEGE (6L)
  578. #define SE_TCB_PRIVILEGE (7L)
  579. #define SE_SECURITY_PRIVILEGE (8L)
  580. #define SE_TAKE_OWNERSHIP_PRIVILEGE (9L)
  581. #define SE_LOAD_DRIVER_PRIVILEGE (10L)
  582. #define SE_SYSTEM_PROFILE_PRIVILEGE (11L)
  583. #define SE_SYSTEMTIME_PRIVILEGE (12L)
  584. #define SE_PROF_SINGLE_PROCESS_PRIVILEGE (13L)
  585. #define SE_INC_BASE_PRIORITY_PRIVILEGE (14L)
  586. #define SE_CREATE_PAGEFILE_PRIVILEGE (15L)
  587. #define SE_CREATE_PERMANENT_PRIVILEGE (16L)
  588. #define SE_BACKUP_PRIVILEGE (17L)
  589. #define SE_RESTORE_PRIVILEGE (18L)
  590. #define SE_SHUTDOWN_PRIVILEGE (19L)
  591. #define SE_DEBUG_PRIVILEGE (20L)
  592. #define SE_AUDIT_PRIVILEGE (21L)
  593. #define SE_SYSTEM_ENVIRONMENT_PRIVILEGE (22L)
  594. #define SE_CHANGE_NOTIFY_PRIVILEGE (23L)
  595. #define SE_REMOTE_SHUTDOWN_PRIVILEGE (24L)
  596. #define SE_MAX_WELL_KNOWN_PRIVILEGE (SE_REMOTE_SHUTDOWN_PRIVILEGE)
  597. //
  598. // Impersonation Level
  599. //
  600. // Impersonation level is represented by a pair of bits in Windows.
  601. // If a new impersonation level is added or lowest value is changed from
  602. // 0 to something else, fix the Windows CreateFile call.
  603. //
  604. typedef enum _SECURITY_IMPERSONATION_LEVEL {
  605. SecurityAnonymous,
  606. SecurityIdentification,
  607. SecurityImpersonation,
  608. SecurityDelegation
  609. } SECURITY_IMPERSONATION_LEVEL, * PSECURITY_IMPERSONATION_LEVEL;
  610. #define SECURITY_MAX_IMPERSONATION_LEVEL SecurityDelegation
  611. #define DEFAULT_IMPERSONATION_LEVEL SecurityImpersonation
  612. typedef enum _PROXY_CLASS {
  613. ProxyFull,
  614. ProxyService,
  615. ProxyTree,
  616. ProxyDirectory
  617. } PROXY_CLASS, * PPROXY_CLASS;
  618. typedef struct _SECURITY_TOKEN_PROXY_DATA {
  619. ULONG Length;
  620. PROXY_CLASS ProxyClass;
  621. UNICODE_STRING PathInfo;
  622. ACCESS_MASK ContainerMask;
  623. ACCESS_MASK ObjectMask;
  624. } SECURITY_TOKEN_PROXY_DATA, *PSECURITY_TOKEN_PROXY_DATA;
  625. typedef struct _SECURITY_TOKEN_AUDIT_DATA {
  626. ULONG Length;
  627. ACCESS_MASK GrantMask;
  628. ACCESS_MASK DenyMask;
  629. } SECURITY_TOKEN_AUDIT_DATA, *PSECURITY_TOKEN_AUDIT_DATA;
  630. //
  631. // Security Tracking Mode
  632. //
  633. #define SECURITY_DYNAMIC_TRACKING (TRUE)
  634. #define SECURITY_STATIC_TRACKING (FALSE)
  635. typedef BOOLEAN SECURITY_CONTEXT_TRACKING_MODE,
  636. * PSECURITY_CONTEXT_TRACKING_MODE;
  637. //
  638. // Quality Of Service
  639. //
  640. typedef struct _SECURITY_QUALITY_OF_SERVICE {
  641. ULONG Length;
  642. SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
  643. SECURITY_CONTEXT_TRACKING_MODE ContextTrackingMode;
  644. BOOLEAN EffectiveOnly;
  645. } SECURITY_QUALITY_OF_SERVICE, * PSECURITY_QUALITY_OF_SERVICE;
  646. //
  647. // Used to represent information related to a thread impersonation
  648. //
  649. typedef struct _SE_IMPERSONATION_STATE {
  650. PACCESS_TOKEN Token;
  651. BOOLEAN CopyOnOpen;
  652. BOOLEAN EffectiveOnly;
  653. SECURITY_IMPERSONATION_LEVEL Level;
  654. } SE_IMPERSONATION_STATE, *PSE_IMPERSONATION_STATE;
  655. typedef ULONG SECURITY_INFORMATION, *PSECURITY_INFORMATION;
  656. #define OWNER_SECURITY_INFORMATION (0X00000001L)
  657. #define GROUP_SECURITY_INFORMATION (0X00000002L)
  658. #define DACL_SECURITY_INFORMATION (0X00000004L)
  659. #define SACL_SECURITY_INFORMATION (0X00000008L)
  660. #define LOW_PRIORITY 0 // Lowest thread priority level
  661. #define LOW_REALTIME_PRIORITY 16 // Lowest realtime priority level
  662. #define HIGH_PRIORITY 31 // Highest thread priority level
  663. #define MAXIMUM_PRIORITY 32 // Number of thread priority levels
  664. // begin_winnt
  665. #define MAXIMUM_WAIT_OBJECTS 64 // Maximum number of wait objects
  666. #define MAXIMUM_SUSPEND_COUNT MAXCHAR // Maximum times thread can be suspended
  667. // end_winnt
  668. //
  669. // Thread affinity
  670. //
  671. typedef ULONG KAFFINITY;
  672. typedef KAFFINITY *PKAFFINITY;
  673. //
  674. // Thread priority
  675. //
  676. typedef LONG KPRIORITY;
  677. //
  678. // Spin Lock
  679. //
  680. typedef ULONG KSPIN_LOCK; // winnt ntndis
  681. typedef KSPIN_LOCK *PKSPIN_LOCK;
  682. //
  683. // Interrupt routine (first level dispatch)
  684. //
  685. typedef
  686. VOID
  687. (*PKINTERRUPT_ROUTINE) (
  688. VOID
  689. );
  690. //
  691. // Profile source types
  692. //
  693. typedef enum _KPROFILE_SOURCE {
  694. ProfileTime,
  695. ProfileAlignmentFixup,
  696. ProfileTotalIssues,
  697. ProfilePipelineDry,
  698. ProfileLoadInstructions,
  699. ProfilePipelineFrozen,
  700. ProfileBranchInstructions,
  701. ProfileTotalNonissues,
  702. ProfileDcacheMisses,
  703. ProfileIcacheMisses,
  704. ProfileCacheMisses,
  705. ProfileBranchMispredictions,
  706. ProfileStoreInstructions,
  707. ProfileFpInstructions,
  708. ProfileIntegerInstructions,
  709. Profile2Issue,
  710. Profile3Issue,
  711. Profile4Issue,
  712. ProfileSpecialInstructions,
  713. ProfileTotalCycles,
  714. ProfileIcacheIssues,
  715. ProfileDcacheAccesses,
  716. ProfileMemoryBarrierCycles,
  717. ProfileLoadLinkedIssues,
  718. ProfileMaximum
  719. } KPROFILE_SOURCE;
  720. //
  721. // for move macros
  722. //
  723. #include <string.h>
  724. //
  725. // If debugging support enabled, define an ASSERT macro that works. Otherwise
  726. // define the ASSERT macro to expand to an empty expression.
  727. //
  728. #if DBG
  729. NTSYSAPI
  730. VOID
  731. NTAPI
  732. RtlAssert(
  733. PVOID FailedAssertion,
  734. PVOID FileName,
  735. ULONG LineNumber,
  736. PCHAR Message
  737. );
  738. #define ASSERT( exp ) \
  739. if (!(exp)) \
  740. RtlAssert( #exp, __FILE__, __LINE__, NULL )
  741. #define ASSERTMSG( msg, exp ) \
  742. if (!(exp)) \
  743. RtlAssert( #exp, __FILE__, __LINE__, msg )
  744. #else
  745. #define ASSERT( exp )
  746. #define ASSERTMSG( msg, exp )
  747. #endif // DBG
  748. //
  749. // Doubly-linked list manipulation routines. Implemented as macros
  750. // but logically these are procedures.
  751. //
  752. //
  753. // VOID
  754. // InitializeListHead(
  755. // PLIST_ENTRY ListHead
  756. // );
  757. //
  758. #define InitializeListHead(ListHead) (\
  759. (ListHead)->Flink = (ListHead)->Blink = (ListHead))
  760. //
  761. // BOOLEAN
  762. // IsListEmpty(
  763. // PLIST_ENTRY ListHead
  764. // );
  765. //
  766. #define IsListEmpty(ListHead) \
  767. ((ListHead)->Flink == (ListHead))
  768. //
  769. // PLIST_ENTRY
  770. // RemoveHeadList(
  771. // PLIST_ENTRY ListHead
  772. // );
  773. //
  774. #define RemoveHeadList(ListHead) \
  775. (ListHead)->Flink;\
  776. {RemoveEntryList((ListHead)->Flink)}
  777. //
  778. // PLIST_ENTRY
  779. // RemoveTailList(
  780. // PLIST_ENTRY ListHead
  781. // );
  782. //
  783. #define RemoveTailList(ListHead) \
  784. (ListHead)->Blink;\
  785. {RemoveEntryList((ListHead)->Blink)}
  786. //
  787. // VOID
  788. // RemoveEntryList(
  789. // PLIST_ENTRY Entry
  790. // );
  791. //
  792. #define RemoveEntryList(Entry) {\
  793. PLIST_ENTRY _EX_Blink;\
  794. PLIST_ENTRY _EX_Flink;\
  795. _EX_Flink = (Entry)->Flink;\
  796. _EX_Blink = (Entry)->Blink;\
  797. _EX_Blink->Flink = _EX_Flink;\
  798. _EX_Flink->Blink = _EX_Blink;\
  799. }
  800. //
  801. // VOID
  802. // InsertTailList(
  803. // PLIST_ENTRY ListHead,
  804. // PLIST_ENTRY Entry
  805. // );
  806. //
  807. #define InsertTailList(ListHead,Entry) {\
  808. PLIST_ENTRY _EX_Blink;\
  809. PLIST_ENTRY _EX_ListHead;\
  810. _EX_ListHead = (ListHead);\
  811. _EX_Blink = _EX_ListHead->Blink;\
  812. (Entry)->Flink = _EX_ListHead;\
  813. (Entry)->Blink = _EX_Blink;\
  814. _EX_Blink->Flink = (Entry);\
  815. _EX_ListHead->Blink = (Entry);\
  816. }
  817. //
  818. // VOID
  819. // InsertHeadList(
  820. // PLIST_ENTRY ListHead,
  821. // PLIST_ENTRY Entry
  822. // );
  823. //
  824. #define InsertHeadList(ListHead,Entry) {\
  825. PLIST_ENTRY _EX_Flink;\
  826. PLIST_ENTRY _EX_ListHead;\
  827. _EX_ListHead = (ListHead);\
  828. _EX_Flink = _EX_ListHead->Flink;\
  829. (Entry)->Flink = _EX_Flink;\
  830. (Entry)->Blink = _EX_ListHead;\
  831. _EX_Flink->Blink = (Entry);\
  832. _EX_ListHead->Flink = (Entry);\
  833. }
  834. //
  835. //
  836. // PSINGLE_LIST_ENTRY
  837. // PopEntryList(
  838. // PSINGLE_LIST_ENTRY ListHead
  839. // );
  840. //
  841. #define PopEntryList(ListHead) \
  842. (ListHead)->Next;\
  843. {\
  844. PSINGLE_LIST_ENTRY FirstEntry;\
  845. FirstEntry = (ListHead)->Next;\
  846. if (FirstEntry != NULL) { \
  847. (ListHead)->Next = FirstEntry->Next;\
  848. } \
  849. }
  850. //
  851. // VOID
  852. // PushEntryList(
  853. // PSINGLE_LIST_ENTRY ListHead,
  854. // PSINGLE_LIST_ENTRY Entry
  855. // );
  856. //
  857. #define PushEntryList(ListHead,Entry) \
  858. (Entry)->Next = (ListHead)->Next; \
  859. (ListHead)->Next = (Entry)
  860. //
  861. // Subroutines for dealing with the Registry
  862. //
  863. typedef NTSTATUS (*PRTL_QUERY_REGISTRY_ROUTINE)(
  864. IN PWSTR ValueName,
  865. IN ULONG ValueType,
  866. IN PVOID ValueData,
  867. IN ULONG ValueLength,
  868. IN PVOID Context,
  869. IN PVOID EntryContext
  870. );
  871. typedef struct _RTL_QUERY_REGISTRY_TABLE {
  872. PRTL_QUERY_REGISTRY_ROUTINE QueryRoutine;
  873. ULONG Flags;
  874. PWSTR Name;
  875. PVOID EntryContext;
  876. ULONG DefaultType;
  877. PVOID DefaultData;
  878. ULONG DefaultLength;
  879. } RTL_QUERY_REGISTRY_TABLE, *PRTL_QUERY_REGISTRY_TABLE;
  880. //
  881. // The following flags specify how the Name field of a RTL_QUERY_REGISTRY_TABLE
  882. // entry is interpreted. A NULL name indicates the end of the table.
  883. //
  884. #define RTL_QUERY_REGISTRY_SUBKEY 0x00000001 // Name is a subkey and remainder of
  885. // table or until next subkey are value
  886. // names for that subkey to look at.
  887. #define RTL_QUERY_REGISTRY_TOPKEY 0x00000002 // Reset current key to original key for
  888. // this and all following table entries.
  889. #define RTL_QUERY_REGISTRY_REQUIRED 0x00000004 // Fail if no match found for this table
  890. // entry.
  891. #define RTL_QUERY_REGISTRY_NOVALUE 0x00000008 // Used to mark a table entry that has no
  892. // value name, just wants a call out, not
  893. // an enumeration of all values.
  894. #define RTL_QUERY_REGISTRY_NOEXPAND 0x00000010 // Used to suppress the expansion of
  895. // REG_MULTI_SZ into multiple callouts or
  896. // to prevent the expansion of environment
  897. // variable values in REG_EXPAND_SZ
  898. #define RTL_QUERY_REGISTRY_DIRECT 0x00000020 // QueryRoutine field ignored. EntryContext
  899. // field points to location to store value.
  900. // For null terminated strings, EntryContext
  901. // points to UNICODE_STRING structure that
  902. // that describes maximum size of buffer.
  903. // If .Buffer field is NULL then a buffer is
  904. // allocated.
  905. //
  906. #define RTL_QUERY_REGISTRY_DELETE 0x00000040 // Used to delete value keys after they
  907. // are queried.
  908. NTSYSAPI
  909. NTSTATUS
  910. NTAPI
  911. RtlQueryRegistryValues(
  912. IN ULONG RelativeTo,
  913. IN PWSTR Path,
  914. IN PRTL_QUERY_REGISTRY_TABLE QueryTable,
  915. IN PVOID Context,
  916. IN PVOID Environment OPTIONAL
  917. );
  918. NTSYSAPI
  919. NTSTATUS
  920. NTAPI
  921. RtlWriteRegistryValue(
  922. IN ULONG RelativeTo,
  923. IN PWSTR Path,
  924. IN PWSTR ValueName,
  925. IN ULONG ValueType,
  926. IN PVOID ValueData,
  927. IN ULONG ValueLength
  928. );
  929. NTSYSAPI
  930. NTSTATUS
  931. NTAPI
  932. RtlDeleteRegistryValue(
  933. IN ULONG RelativeTo,
  934. IN PWSTR Path,
  935. IN PWSTR ValueName
  936. );
  937. //
  938. // The following values for the RelativeTo parameter determine what the
  939. // Path parameter to RtlQueryRegistryValues is relative to.
  940. //
  941. #define RTL_REGISTRY_ABSOLUTE 0 // Path is a full path
  942. #define RTL_REGISTRY_SERVICES 1 // \Registry\Machine\System\CurrentControlSet\Services
  943. #define RTL_REGISTRY_CONTROL 2 // \Registry\Machine\System\CurrentControlSet\Control
  944. #define RTL_REGISTRY_WINDOWS_NT 3 // \Registry\Machine\Software\Microsoft\Windows NT\CurrentVersion
  945. #define RTL_REGISTRY_DEVICEMAP 4 // \Registry\Machine\Hardware\DeviceMap
  946. #define RTL_REGISTRY_USER 5 // \Registry\User\CurrentUser
  947. #define RTL_REGISTRY_MAXIMUM 6
  948. #define RTL_REGISTRY_HANDLE 0x40000000 // Low order bits are registry handle
  949. #define RTL_REGISTRY_OPTIONAL 0x80000000 // Indicates the key node is optional
  950. NTSYSAPI
  951. NTSTATUS
  952. NTAPI
  953. RtlIntegerToUnicodeString (
  954. ULONG Value,
  955. ULONG Base,
  956. PUNICODE_STRING String
  957. );
  958. NTSYSAPI
  959. NTSTATUS
  960. NTAPI
  961. RtlUnicodeStringToInteger (
  962. PUNICODE_STRING String,
  963. ULONG Base,
  964. PULONG Value
  965. );
  966. //
  967. // String manipulation routines
  968. //
  969. #ifdef _NTSYSTEM_
  970. #define NLS_MB_CODE_PAGE_TAG NlsMbCodePageTag
  971. #define NLS_MB_OEM_CODE_PAGE_TAG NlsMbOemCodePageTag
  972. #else
  973. #define NLS_MB_CODE_PAGE_TAG (*NlsMbCodePageTag)
  974. #define NLS_MB_OEM_CODE_PAGE_TAG (*NlsMbOemCodePageTag)
  975. #endif // _NTSYSTEM_
  976. extern BOOLEAN NLS_MB_CODE_PAGE_TAG; // TRUE -> Multibyte CP, FALSE -> Singlebyte
  977. extern BOOLEAN NLS_MB_OEM_CODE_PAGE_TAG; // TRUE -> Multibyte CP, FALSE -> Singlebyte
  978. NTSYSAPI
  979. VOID
  980. NTAPI
  981. RtlInitString(
  982. PSTRING DestinationString,
  983. PCSZ SourceString
  984. );
  985. NTSYSAPI
  986. VOID
  987. NTAPI
  988. RtlInitAnsiString(
  989. PANSI_STRING DestinationString,
  990. PCSZ SourceString
  991. );
  992. NTSYSAPI
  993. VOID
  994. NTAPI
  995. RtlInitUnicodeString(
  996. PUNICODE_STRING DestinationString,
  997. PCWSTR SourceString
  998. );
  999. //
  1000. // NLS String functions
  1001. //
  1002. NTSYSAPI
  1003. NTSTATUS
  1004. NTAPI
  1005. RtlAnsiStringToUnicodeString(
  1006. PUNICODE_STRING DestinationString,
  1007. PANSI_STRING SourceString,
  1008. BOOLEAN AllocateDestinationString
  1009. );
  1010. NTSYSAPI
  1011. NTSTATUS
  1012. NTAPI
  1013. RtlUnicodeStringToAnsiString(
  1014. PANSI_STRING DestinationString,
  1015. PUNICODE_STRING SourceString,
  1016. BOOLEAN AllocateDestinationString
  1017. );
  1018. NTSYSAPI
  1019. LONG
  1020. NTAPI
  1021. RtlCompareUnicodeString(
  1022. PUNICODE_STRING String1,
  1023. PUNICODE_STRING String2,
  1024. BOOLEAN CaseInSensitive
  1025. );
  1026. NTSYSAPI
  1027. BOOLEAN
  1028. NTAPI
  1029. RtlEqualUnicodeString(
  1030. PUNICODE_STRING String1,
  1031. PUNICODE_STRING String2,
  1032. BOOLEAN CaseInSensitive
  1033. );
  1034. NTSYSAPI
  1035. VOID
  1036. NTAPI
  1037. RtlCopyUnicodeString(
  1038. PUNICODE_STRING DestinationString,
  1039. PUNICODE_STRING SourceString
  1040. );
  1041. NTSYSAPI
  1042. NTSTATUS
  1043. NTAPI
  1044. RtlAppendUnicodeStringToString (
  1045. PUNICODE_STRING Destination,
  1046. PUNICODE_STRING Source
  1047. );
  1048. NTSYSAPI
  1049. NTSTATUS
  1050. NTAPI
  1051. RtlAppendUnicodeToString (
  1052. PUNICODE_STRING Destination,
  1053. PWSTR Source
  1054. );
  1055. NTSYSAPI
  1056. VOID
  1057. NTAPI
  1058. RtlFreeUnicodeString(
  1059. PUNICODE_STRING UnicodeString
  1060. );
  1061. NTSYSAPI
  1062. VOID
  1063. NTAPI
  1064. RtlFreeAnsiString(
  1065. PANSI_STRING AnsiString
  1066. );
  1067. NTSYSAPI
  1068. ULONG
  1069. NTAPI
  1070. RtlxAnsiStringToUnicodeSize(
  1071. PANSI_STRING AnsiString
  1072. );
  1073. //
  1074. // NTSYSAPI
  1075. // ULONG
  1076. // NTAPI
  1077. // RtlAnsiStringToUnicodeSize(
  1078. // PANSI_STRING AnsiString
  1079. // );
  1080. //
  1081. #define RtlAnsiStringToUnicodeSize(STRING) ( \
  1082. NLS_MB_CODE_PAGE_TAG ? \
  1083. RtlxAnsiStringToUnicodeSize(STRING) : \
  1084. ((STRING)->Length + sizeof((UCHAR)NULL)) * sizeof(WCHAR) \
  1085. )
  1086. //
  1087. // Fast primitives to compare, move, and zero memory
  1088. //
  1089. // begin_winnt begin_ntndis
  1090. #if defined(_M_IX86) || defined(_M_MRX000) || defined(_M_ALPHA)
  1091. #if defined(_M_MRX000) && (_MSC_VER >= 1100) && !(defined(MIDL_PASS) || defined(RC_INVOKED))
  1092. NTSYSAPI
  1093. ULONG
  1094. NTAPI
  1095. RtlEqualMemory64 (
  1096. CONST PVOID64 Source1,
  1097. CONST PVOID64 Source2,
  1098. ULONG Length
  1099. );
  1100. NTSYSAPI
  1101. VOID
  1102. NTAPI
  1103. RtlMoveMemory64 (
  1104. PVOID64 Destination,
  1105. CONST PVOID64 Source,
  1106. ULONG Length
  1107. );
  1108. NTSYSAPI
  1109. VOID
  1110. NTAPI
  1111. RtlFillMemory64 (
  1112. PVOID64 Destination,
  1113. ULONG Length,
  1114. UCHAR Fill
  1115. );
  1116. NTSYSAPI
  1117. VOID
  1118. NTAPI
  1119. RtlZeroMemory64 (
  1120. PVOID64 Destination,
  1121. ULONG Length
  1122. );
  1123. #endif
  1124. #if defined(_M_MRX000)
  1125. NTSYSAPI
  1126. ULONG
  1127. NTAPI
  1128. RtlEqualMemory (
  1129. CONST VOID *Source1,
  1130. CONST VOID *Source2,
  1131. ULONG Length
  1132. );
  1133. #else
  1134. #define RtlEqualMemory(Destination,Source,Length) (!memcmp((Destination),(Source),(Length)))
  1135. #endif
  1136. #define RtlMoveMemory(Destination,Source,Length) memmove((Destination),(Source),(Length))
  1137. #define RtlCopyMemory(Destination,Source,Length) memcpy((Destination),(Source),(Length))
  1138. #define RtlFillMemory(Destination,Length,Fill) memset((Destination),(Fill),(Length))
  1139. #define RtlZeroMemory(Destination,Length) memset((Destination),0,(Length))
  1140. #else // _M_PPC
  1141. NTSYSAPI
  1142. ULONG
  1143. NTAPI
  1144. RtlEqualMemory (
  1145. CONST VOID *Source1,
  1146. CONST VOID *Source2,
  1147. ULONG Length
  1148. );
  1149. NTSYSAPI
  1150. VOID
  1151. NTAPI
  1152. RtlCopyMemory (
  1153. VOID UNALIGNED *Destination,
  1154. CONST VOID UNALIGNED *Source,
  1155. ULONG Length
  1156. );
  1157. NTSYSAPI
  1158. VOID
  1159. NTAPI
  1160. RtlCopyMemory32 (
  1161. VOID UNALIGNED *Destination,
  1162. CONST VOID UNALIGNED *Source,
  1163. ULONG Length
  1164. );
  1165. NTSYSAPI
  1166. VOID
  1167. NTAPI
  1168. RtlMoveMemory (
  1169. VOID UNALIGNED *Destination,
  1170. CONST VOID UNALIGNED *Source,
  1171. ULONG Length
  1172. );
  1173. NTSYSAPI
  1174. VOID
  1175. NTAPI
  1176. RtlFillMemory (
  1177. VOID UNALIGNED *Destination,
  1178. ULONG Length,
  1179. UCHAR Fill
  1180. );
  1181. NTSYSAPI
  1182. VOID
  1183. NTAPI
  1184. RtlZeroMemory (
  1185. VOID UNALIGNED *Destination,
  1186. ULONG Length
  1187. );
  1188. #endif
  1189. // end_winnt end_ntndis
  1190. #if defined(_M_MRX000) && (_MSC_VER >= 1100) && !(defined(MIDL_PASS) || defined(RC_INVOKED))
  1191. NTSYSAPI
  1192. ULONG
  1193. NTAPI
  1194. RtlCompareMemory64 (
  1195. PVOID64 Source1,
  1196. PVOID64 Source2,
  1197. ULONG Length
  1198. );
  1199. #endif
  1200. NTSYSAPI
  1201. ULONG
  1202. NTAPI
  1203. RtlCompareMemory (
  1204. PVOID Source1,
  1205. PVOID Source2,
  1206. ULONG Length
  1207. );
  1208. #if defined(_M_ALPHA)
  1209. //
  1210. // Guaranteed byte granularity memory copy function.
  1211. //
  1212. NTSYSAPI
  1213. VOID
  1214. NTAPI
  1215. RtlCopyBytes (
  1216. PVOID Destination,
  1217. CONST VOID *Source,
  1218. ULONG Length
  1219. );
  1220. //
  1221. // Guaranteed byte granularity memory zero function.
  1222. //
  1223. NTSYSAPI
  1224. VOID
  1225. NTAPI
  1226. RtlZeroBytes (
  1227. PVOID Destination,
  1228. ULONG Length
  1229. );
  1230. //
  1231. // Guaranteed byte granularity memory fill function.
  1232. //
  1233. NTSYSAPI
  1234. VOID
  1235. NTAPI
  1236. RtlFillBytes (
  1237. PVOID Destination,
  1238. ULONG Length,
  1239. UCHAR Fill
  1240. );
  1241. #else
  1242. #define RtlCopyBytes RtlCopyMemory
  1243. #define RtlZeroBytes RtlZeroMemory
  1244. #define RtlFillBytes RtlFillMemory
  1245. #endif
  1246. //
  1247. // Define kernel debugger print prototypes and macros.
  1248. //
  1249. VOID
  1250. NTAPI
  1251. DbgBreakPoint(
  1252. VOID
  1253. );
  1254. #define DBG_STATUS_CONTROL_C 1
  1255. #define DBG_STATUS_SYSRQ 2
  1256. #define DBG_STATUS_BUGCHECK_FIRST 3
  1257. #define DBG_STATUS_BUGCHECK_SECOND 4
  1258. #define DBG_STATUS_FATAL 5
  1259. #if DBG
  1260. #define KdPrint(_x_) DbgPrint _x_
  1261. #define KdBreakPoint() DbgBreakPoint()
  1262. #else
  1263. #define KdPrint(_x_)
  1264. #define KdBreakPoint()
  1265. #endif
  1266. #ifndef _DBGNT_
  1267. ULONG
  1268. _cdecl
  1269. DbgPrint(
  1270. PCH Format,
  1271. ...
  1272. );
  1273. #endif // _DBGNT_
  1274. //
  1275. // Large integer arithmetic routines.
  1276. //
  1277. #if defined(MIDL_PASS) || defined(__cplusplus) || !defined(_M_IX86)
  1278. //
  1279. // Large integer add - 64-bits + 64-bits -> 64-bits
  1280. //
  1281. NTSYSAPI
  1282. LARGE_INTEGER
  1283. NTAPI
  1284. RtlLargeIntegerAdd (
  1285. LARGE_INTEGER Addend1,
  1286. LARGE_INTEGER Addend2
  1287. );
  1288. //
  1289. // Enlarged integer multiply - 32-bits * 32-bits -> 64-bits
  1290. //
  1291. NTSYSAPI
  1292. LARGE_INTEGER
  1293. NTAPI
  1294. RtlEnlargedIntegerMultiply (
  1295. LONG Multiplicand,
  1296. LONG Multiplier
  1297. );
  1298. //
  1299. // Unsigned enlarged integer multiply - 32-bits * 32-bits -> 64-bits
  1300. //
  1301. NTSYSAPI
  1302. LARGE_INTEGER
  1303. NTAPI
  1304. RtlEnlargedUnsignedMultiply (
  1305. ULONG Multiplicand,
  1306. ULONG Multiplier
  1307. );
  1308. //
  1309. // Enlarged integer divide - 64-bits / 32-bits > 32-bits
  1310. //
  1311. NTSYSAPI
  1312. ULONG
  1313. NTAPI
  1314. RtlEnlargedUnsignedDivide (
  1315. IN ULARGE_INTEGER Dividend,
  1316. IN ULONG Divisor,
  1317. IN PULONG Remainder
  1318. );
  1319. //
  1320. // Large integer negation - -(64-bits)
  1321. //
  1322. NTSYSAPI
  1323. LARGE_INTEGER
  1324. NTAPI
  1325. RtlLargeIntegerNegate (
  1326. LARGE_INTEGER Subtrahend
  1327. );
  1328. //
  1329. // Large integer subtract - 64-bits - 64-bits -> 64-bits.
  1330. //
  1331. NTSYSAPI
  1332. LARGE_INTEGER
  1333. NTAPI
  1334. RtlLargeIntegerSubtract (
  1335. LARGE_INTEGER Minuend,
  1336. LARGE_INTEGER Subtrahend
  1337. );
  1338. #else
  1339. #pragma warning(disable:4035) // re-enable below
  1340. //
  1341. // Large integer add - 64-bits + 64-bits -> 64-bits
  1342. //
  1343. __inline LARGE_INTEGER
  1344. NTAPI
  1345. RtlLargeIntegerAdd (
  1346. LARGE_INTEGER Addend1,
  1347. LARGE_INTEGER Addend2
  1348. )
  1349. {
  1350. __asm {
  1351. mov eax,Addend1.LowPart ; (eax)=add1.low
  1352. mov edx,Addend1.HighPart ; (edx)=add1.hi
  1353. add eax,Addend2.LowPart ; (eax)=sum.low
  1354. adc edx,Addend2.HighPart ; (edx)=sum.hi
  1355. }
  1356. }
  1357. //
  1358. // Enlarged integer multiply - 32-bits * 32-bits -> 64-bits
  1359. //
  1360. __inline LARGE_INTEGER
  1361. NTAPI
  1362. RtlEnlargedIntegerMultiply (
  1363. LONG Multiplicand,
  1364. LONG Multiplier
  1365. )
  1366. {
  1367. __asm {
  1368. mov eax, Multiplicand
  1369. imul Multiplier
  1370. }
  1371. }
  1372. //
  1373. // Unsigned enlarged integer multiply - 32-bits * 32-bits -> 64-bits
  1374. //
  1375. __inline LARGE_INTEGER
  1376. NTAPI
  1377. RtlEnlargedUnsignedMultiply (
  1378. ULONG Multiplicand,
  1379. ULONG Multiplier
  1380. )
  1381. {
  1382. __asm {
  1383. mov eax, Multiplicand
  1384. mul Multiplier
  1385. }
  1386. }
  1387. //
  1388. // Enlarged integer divide - 64-bits / 32-bits > 32-bits
  1389. //
  1390. __inline ULONG
  1391. NTAPI
  1392. RtlEnlargedUnsignedDivide (
  1393. IN ULARGE_INTEGER Dividend,
  1394. IN ULONG Divisor,
  1395. IN PULONG Remainder
  1396. )
  1397. {
  1398. __asm {
  1399. mov eax, Dividend.LowPart
  1400. mov edx, Dividend.HighPart
  1401. mov ecx, Remainder
  1402. div Divisor ; eax = eax:edx / divisor
  1403. or ecx, ecx ; save remainer?
  1404. jz short done
  1405. mov [ecx], edx
  1406. done:
  1407. }
  1408. }
  1409. //
  1410. // Large integer negation - -(64-bits)
  1411. //
  1412. __inline LARGE_INTEGER
  1413. NTAPI
  1414. RtlLargeIntegerNegate (
  1415. LARGE_INTEGER Subtrahend
  1416. )
  1417. {
  1418. __asm {
  1419. mov eax, Subtrahend.LowPart
  1420. mov edx, Subtrahend.HighPart
  1421. neg edx ; (edx) = 2s comp of hi part
  1422. neg eax ; if ((eax) == 0) CF = 0
  1423. ; else CF = 1
  1424. sbb edx,0 ; (edx) = (edx) - CF
  1425. }
  1426. }
  1427. //
  1428. // Large integer subtract - 64-bits - 64-bits -> 64-bits.
  1429. //
  1430. __inline LARGE_INTEGER
  1431. NTAPI
  1432. RtlLargeIntegerSubtract (
  1433. LARGE_INTEGER Minuend,
  1434. LARGE_INTEGER Subtrahend
  1435. )
  1436. {
  1437. __asm {
  1438. mov eax, Minuend.LowPart
  1439. mov edx, Minuend.HighPart
  1440. sub eax, Subtrahend.LowPart
  1441. sbb edx, Subtrahend.HighPart
  1442. }
  1443. }
  1444. #pragma warning(default:4035)
  1445. #endif
  1446. //
  1447. // Extended large integer magic divide - 64-bits / 32-bits -> 64-bits
  1448. //
  1449. NTSYSAPI
  1450. LARGE_INTEGER
  1451. NTAPI
  1452. RtlExtendedMagicDivide (
  1453. LARGE_INTEGER Dividend,
  1454. LARGE_INTEGER MagicDivisor,
  1455. CCHAR ShiftCount
  1456. );
  1457. //
  1458. // Large Integer divide - 64-bits / 32-bits -> 64-bits
  1459. //
  1460. NTSYSAPI
  1461. LARGE_INTEGER
  1462. NTAPI
  1463. RtlExtendedLargeIntegerDivide (
  1464. LARGE_INTEGER Dividend,
  1465. ULONG Divisor,
  1466. PULONG Remainder
  1467. );
  1468. //
  1469. // Extended integer multiply - 32-bits * 64-bits -> 64-bits
  1470. //
  1471. NTSYSAPI
  1472. LARGE_INTEGER
  1473. NTAPI
  1474. RtlExtendedIntegerMultiply (
  1475. LARGE_INTEGER Multiplicand,
  1476. LONG Multiplier
  1477. );
  1478. //
  1479. // Large integer and - 64-bite & 64-bits -> 64-bits.
  1480. //
  1481. #define RtlLargeIntegerAnd(Result, Source, Mask) \
  1482. { \
  1483. Result.HighPart = Source.HighPart & Mask.HighPart; \
  1484. Result.LowPart = Source.LowPart & Mask.LowPart; \
  1485. }
  1486. //
  1487. // Large integer conversion routines.
  1488. //
  1489. #if defined(MIDL_PASS) || defined(__cplusplus) || !defined(_M_IX86)
  1490. //
  1491. // Convert signed integer to large integer.
  1492. //
  1493. NTSYSAPI
  1494. LARGE_INTEGER
  1495. NTAPI
  1496. RtlConvertLongToLargeInteger (
  1497. LONG SignedInteger
  1498. );
  1499. //
  1500. // Convert unsigned integer to large integer.
  1501. //
  1502. NTSYSAPI
  1503. LARGE_INTEGER
  1504. NTAPI
  1505. RtlConvertUlongToLargeInteger (
  1506. ULONG UnsignedInteger
  1507. );
  1508. //
  1509. // Large integer shift routines.
  1510. //
  1511. NTSYSAPI
  1512. LARGE_INTEGER
  1513. NTAPI
  1514. RtlLargeIntegerShiftLeft (
  1515. LARGE_INTEGER LargeInteger,
  1516. CCHAR ShiftCount
  1517. );
  1518. NTSYSAPI
  1519. LARGE_INTEGER
  1520. NTAPI
  1521. RtlLargeIntegerShiftRight (
  1522. LARGE_INTEGER LargeInteger,
  1523. CCHAR ShiftCount
  1524. );
  1525. NTSYSAPI
  1526. LARGE_INTEGER
  1527. NTAPI
  1528. RtlLargeIntegerArithmeticShift (
  1529. LARGE_INTEGER LargeInteger,
  1530. CCHAR ShiftCount
  1531. );
  1532. #else
  1533. #pragma warning(disable:4035) // re-enable below
  1534. //
  1535. // Convert signed integer to large integer.
  1536. //
  1537. __inline LARGE_INTEGER
  1538. NTAPI
  1539. RtlConvertLongToLargeInteger (
  1540. LONG SignedInteger
  1541. )
  1542. {
  1543. __asm {
  1544. mov eax, SignedInteger
  1545. cdq ; (edx:eax) = signed LargeInt
  1546. }
  1547. }
  1548. //
  1549. // Convert unsigned integer to large integer.
  1550. //
  1551. __inline LARGE_INTEGER
  1552. NTAPI
  1553. RtlConvertUlongToLargeInteger (
  1554. ULONG UnsignedInteger
  1555. )
  1556. {
  1557. __asm {
  1558. sub edx, edx ; zero highpart
  1559. mov eax, UnsignedInteger
  1560. }
  1561. }
  1562. //
  1563. // Large integer shift routines.
  1564. //
  1565. __inline LARGE_INTEGER
  1566. NTAPI
  1567. RtlLargeIntegerShiftLeft (
  1568. LARGE_INTEGER LargeInteger,
  1569. CCHAR ShiftCount
  1570. )
  1571. {
  1572. __asm {
  1573. mov cl, ShiftCount
  1574. and cl, 0x3f ; mod 64
  1575. cmp cl, 32
  1576. jc short sl10
  1577. mov edx, LargeInteger.LowPart ; ShiftCount >= 32
  1578. xor eax, eax ; lowpart is zero
  1579. shl edx, cl ; store highpart
  1580. jmp short done
  1581. sl10:
  1582. mov eax, LargeInteger.LowPart ; ShiftCount < 32
  1583. mov edx, LargeInteger.HighPart
  1584. shld edx, eax, cl
  1585. shl eax, cl
  1586. done:
  1587. }
  1588. }
  1589. __inline LARGE_INTEGER
  1590. NTAPI
  1591. RtlLargeIntegerShiftRight (
  1592. LARGE_INTEGER LargeInteger,
  1593. CCHAR ShiftCount
  1594. )
  1595. {
  1596. __asm {
  1597. mov cl, ShiftCount
  1598. and cl, 0x3f ; mod 64
  1599. cmp cl, 32
  1600. jc short sr10
  1601. mov eax, LargeInteger.HighPart ; ShiftCount >= 32
  1602. xor edx, edx ; lowpart is zero
  1603. shr eax, cl ; store highpart
  1604. jmp short done
  1605. sr10:
  1606. mov eax, LargeInteger.LowPart ; ShiftCount < 32
  1607. mov edx, LargeInteger.HighPart
  1608. shrd eax, edx, cl
  1609. shr edx, cl
  1610. done:
  1611. }
  1612. }
  1613. __inline LARGE_INTEGER
  1614. NTAPI
  1615. RtlLargeIntegerArithmeticShift (
  1616. LARGE_INTEGER LargeInteger,
  1617. CCHAR ShiftCount
  1618. )
  1619. {
  1620. __asm {
  1621. mov cl, ShiftCount
  1622. and cl, 3fh ; mod 64
  1623. cmp cl, 32
  1624. jc short sar10
  1625. mov eax, LargeInteger.HighPart
  1626. sar eax, cl
  1627. bt eax, 31 ; sign bit set?
  1628. sbb edx, edx ; duplicate sign bit into highpart
  1629. jmp short done
  1630. sar10:
  1631. mov eax, LargeInteger.LowPart ; (eax) = LargeInteger.LowPart
  1632. mov edx, LargeInteger.HighPart ; (edx) = LargeInteger.HighPart
  1633. shrd eax, edx, cl
  1634. sar edx, cl
  1635. done:
  1636. }
  1637. }
  1638. #pragma warning(default:4035)
  1639. #endif
  1640. //
  1641. // Large integer comparison routines.
  1642. //
  1643. // BOOLEAN
  1644. // RtlLargeIntegerGreaterThan (
  1645. // LARGE_INTEGER Operand1,
  1646. // LARGE_INTEGER Operand2
  1647. // );
  1648. //
  1649. // BOOLEAN
  1650. // RtlLargeIntegerGreaterThanOrEqualTo (
  1651. // LARGE_INTEGER Operand1,
  1652. // LARGE_INTEGER Operand2
  1653. // );
  1654. //
  1655. // BOOLEAN
  1656. // RtlLargeIntegerEqualTo (
  1657. // LARGE_INTEGER Operand1,
  1658. // LARGE_INTEGER Operand2
  1659. // );
  1660. //
  1661. // BOOLEAN
  1662. // RtlLargeIntegerNotEqualTo (
  1663. // LARGE_INTEGER Operand1,
  1664. // LARGE_INTEGER Operand2
  1665. // );
  1666. //
  1667. // BOOLEAN
  1668. // RtlLargeIntegerLessThan (
  1669. // LARGE_INTEGER Operand1,
  1670. // LARGE_INTEGER Operand2
  1671. // );
  1672. //
  1673. // BOOLEAN
  1674. // RtlLargeIntegerLessThanOrEqualTo (
  1675. // LARGE_INTEGER Operand1,
  1676. // LARGE_INTEGER Operand2
  1677. // );
  1678. //
  1679. // BOOLEAN
  1680. // RtlLargeIntegerGreaterThanZero (
  1681. // LARGE_INTEGER Operand
  1682. // );
  1683. //
  1684. // BOOLEAN
  1685. // RtlLargeIntegerGreaterOrEqualToZero (
  1686. // LARGE_INTEGER Operand
  1687. // );
  1688. //
  1689. // BOOLEAN
  1690. // RtlLargeIntegerEqualToZero (
  1691. // LARGE_INTEGER Operand
  1692. // );
  1693. //
  1694. // BOOLEAN
  1695. // RtlLargeIntegerNotEqualToZero (
  1696. // LARGE_INTEGER Operand
  1697. // );
  1698. //
  1699. // BOOLEAN
  1700. // RtlLargeIntegerLessThanZero (
  1701. // LARGE_INTEGER Operand
  1702. // );
  1703. //
  1704. // BOOLEAN
  1705. // RtlLargeIntegerLessOrEqualToZero (
  1706. // LARGE_INTEGER Operand
  1707. // );
  1708. //
  1709. #define RtlLargeIntegerGreaterThan(X,Y) ( \
  1710. (((X).HighPart == (Y).HighPart) && ((X).LowPart > (Y).LowPart)) || \
  1711. ((X).HighPart > (Y).HighPart) \
  1712. )
  1713. #define RtlLargeIntegerGreaterThanOrEqualTo(X,Y) ( \
  1714. (((X).HighPart == (Y).HighPart) && ((X).LowPart >= (Y).LowPart)) || \
  1715. ((X).HighPart > (Y).HighPart) \
  1716. )
  1717. #define RtlLargeIntegerEqualTo(X,Y) ( \
  1718. !(((X).LowPart ^ (Y).LowPart) | ((X).HighPart ^ (Y).HighPart)) \
  1719. )
  1720. #define RtlLargeIntegerNotEqualTo(X,Y) ( \
  1721. (((X).LowPart ^ (Y).LowPart) | ((X).HighPart ^ (Y).HighPart)) \
  1722. )
  1723. #define RtlLargeIntegerLessThan(X,Y) ( \
  1724. (((X).HighPart == (Y).HighPart) && ((X).LowPart < (Y).LowPart)) || \
  1725. ((X).HighPart < (Y).HighPart) \
  1726. )
  1727. #define RtlLargeIntegerLessThanOrEqualTo(X,Y) ( \
  1728. (((X).HighPart == (Y).HighPart) && ((X).LowPart <= (Y).LowPart)) || \
  1729. ((X).HighPart < (Y).HighPart) \
  1730. )
  1731. #define RtlLargeIntegerGreaterThanZero(X) ( \
  1732. (((X).HighPart == 0) && ((X).LowPart > 0)) || \
  1733. ((X).HighPart > 0 ) \
  1734. )
  1735. #define RtlLargeIntegerGreaterOrEqualToZero(X) ( \
  1736. (X).HighPart >= 0 \
  1737. )
  1738. #define RtlLargeIntegerEqualToZero(X) ( \
  1739. !((X).LowPart | (X).HighPart) \
  1740. )
  1741. #define RtlLargeIntegerNotEqualToZero(X) ( \
  1742. ((X).LowPart | (X).HighPart) \
  1743. )
  1744. #define RtlLargeIntegerLessThanZero(X) ( \
  1745. ((X).HighPart < 0) \
  1746. )
  1747. #define RtlLargeIntegerLessOrEqualToZero(X) ( \
  1748. ((X).HighPart < 0) || !((X).LowPart | (X).HighPart) \
  1749. )
  1750. //
  1751. // Time conversion routines
  1752. //
  1753. typedef struct _TIME_FIELDS {
  1754. CSHORT Year; // range [1601...]
  1755. CSHORT Month; // range [1..12]
  1756. CSHORT Day; // range [1..31]
  1757. CSHORT Hour; // range [0..23]
  1758. CSHORT Minute; // range [0..59]
  1759. CSHORT Second; // range [0..59]
  1760. CSHORT Milliseconds;// range [0..999]
  1761. CSHORT Weekday; // range [0..6] == [Sunday..Saturday]
  1762. } TIME_FIELDS;
  1763. typedef TIME_FIELDS *PTIME_FIELDS;
  1764. //
  1765. // The following macros store and retrieve USHORTS and ULONGS from potentially
  1766. // unaligned addresses, avoiding alignment faults. they should probably be
  1767. // rewritten in assembler
  1768. //
  1769. #define SHORT_SIZE (sizeof(USHORT))
  1770. #define SHORT_MASK (SHORT_SIZE - 1)
  1771. #define LONG_SIZE (sizeof(LONG))
  1772. #define LONG_MASK (LONG_SIZE - 1)
  1773. #define LOWBYTE_MASK 0x00FF
  1774. #define FIRSTBYTE(VALUE) (VALUE & LOWBYTE_MASK)
  1775. #define SECONDBYTE(VALUE) ((VALUE >> 8) & LOWBYTE_MASK)
  1776. #define THIRDBYTE(VALUE) ((VALUE >> 16) & LOWBYTE_MASK)
  1777. #define FOURTHBYTE(VALUE) ((VALUE >> 24) & LOWBYTE_MASK)
  1778. //
  1779. // if MIPS Big Endian, order of bytes is reversed.
  1780. //
  1781. #define SHORT_LEAST_SIGNIFICANT_BIT 0
  1782. #define SHORT_MOST_SIGNIFICANT_BIT 1
  1783. #define LONG_LEAST_SIGNIFICANT_BIT 0
  1784. #define LONG_3RD_MOST_SIGNIFICANT_BIT 1
  1785. #define LONG_2ND_MOST_SIGNIFICANT_BIT 2
  1786. #define LONG_MOST_SIGNIFICANT_BIT 3
  1787. //++
  1788. //
  1789. // VOID
  1790. // RtlStoreUshort (
  1791. // PUSHORT ADDRESS
  1792. // USHORT VALUE
  1793. // )
  1794. //
  1795. // Routine Description:
  1796. //
  1797. // This macro stores a USHORT value in at a particular address, avoiding
  1798. // alignment faults.
  1799. //
  1800. // Arguments:
  1801. //
  1802. // ADDRESS - where to store USHORT value
  1803. // VALUE - USHORT to store
  1804. //
  1805. // Return Value:
  1806. //
  1807. // none.
  1808. //
  1809. //--
  1810. #define RtlStoreUshort(ADDRESS,VALUE) \
  1811. if ((ULONG)ADDRESS & SHORT_MASK) { \
  1812. ((PUCHAR) ADDRESS)[SHORT_LEAST_SIGNIFICANT_BIT] = (UCHAR)(FIRSTBYTE(VALUE)); \
  1813. ((PUCHAR) ADDRESS)[SHORT_MOST_SIGNIFICANT_BIT ] = (UCHAR)(SECONDBYTE(VALUE)); \
  1814. } \
  1815. else { \
  1816. *((PUSHORT) ADDRESS) = (USHORT) VALUE; \
  1817. }
  1818. //++
  1819. //
  1820. // VOID
  1821. // RtlStoreUlong (
  1822. // PULONG ADDRESS
  1823. // ULONG VALUE
  1824. // )
  1825. //
  1826. // Routine Description:
  1827. //
  1828. // This macro stores a ULONG value in at a particular address, avoiding
  1829. // alignment faults.
  1830. //
  1831. // Arguments:
  1832. //
  1833. // ADDRESS - where to store ULONG value
  1834. // VALUE - ULONG to store
  1835. //
  1836. // Return Value:
  1837. //
  1838. // none.
  1839. //
  1840. // Note:
  1841. // Depending on the machine, we might want to call storeushort in the
  1842. // unaligned case.
  1843. //
  1844. //--
  1845. #define RtlStoreUlong(ADDRESS,VALUE) \
  1846. if ((ULONG)ADDRESS & LONG_MASK) { \
  1847. ((PUCHAR) ADDRESS)[LONG_LEAST_SIGNIFICANT_BIT ] = (UCHAR)(FIRSTBYTE(VALUE)); \
  1848. ((PUCHAR) ADDRESS)[LONG_3RD_MOST_SIGNIFICANT_BIT ] = (UCHAR)(SECONDBYTE(VALUE)); \
  1849. ((PUCHAR) ADDRESS)[LONG_2ND_MOST_SIGNIFICANT_BIT ] = (UCHAR)(THIRDBYTE(VALUE)); \
  1850. ((PUCHAR) ADDRESS)[LONG_MOST_SIGNIFICANT_BIT ] = (UCHAR)(FOURTHBYTE(VALUE)); \
  1851. } \
  1852. else { \
  1853. *((PULONG) ADDRESS) = (ULONG) VALUE; \
  1854. }
  1855. //++
  1856. //
  1857. // VOID
  1858. // RtlRetrieveUshort (
  1859. // PUSHORT DESTINATION_ADDRESS
  1860. // PUSHORT SOURCE_ADDRESS
  1861. // )
  1862. //
  1863. // Routine Description:
  1864. //
  1865. // This macro retrieves a USHORT value from the SOURCE address, avoiding
  1866. // alignment faults. The DESTINATION address is assumed to be aligned.
  1867. //
  1868. // Arguments:
  1869. //
  1870. // DESTINATION_ADDRESS - where to store USHORT value
  1871. // SOURCE_ADDRESS - where to retrieve USHORT value from
  1872. //
  1873. // Return Value:
  1874. //
  1875. // none.
  1876. //
  1877. //--
  1878. #define RtlRetrieveUshort(DEST_ADDRESS,SRC_ADDRESS) \
  1879. if ((ULONG)SRC_ADDRESS & SHORT_MASK) { \
  1880. ((PUCHAR) DEST_ADDRESS)[0] = ((PUCHAR) SRC_ADDRESS)[0]; \
  1881. ((PUCHAR) DEST_ADDRESS)[1] = ((PUCHAR) SRC_ADDRESS)[1]; \
  1882. } \
  1883. else { \
  1884. *((PUSHORT) DEST_ADDRESS) = *((PUSHORT) SRC_ADDRESS); \
  1885. } \
  1886. //++
  1887. //
  1888. // VOID
  1889. // RtlRetrieveUlong (
  1890. // PULONG DESTINATION_ADDRESS
  1891. // PULONG SOURCE_ADDRESS
  1892. // )
  1893. //
  1894. // Routine Description:
  1895. //
  1896. // This macro retrieves a ULONG value from the SOURCE address, avoiding
  1897. // alignment faults. The DESTINATION address is assumed to be aligned.
  1898. //
  1899. // Arguments:
  1900. //
  1901. // DESTINATION_ADDRESS - where to store ULONG value
  1902. // SOURCE_ADDRESS - where to retrieve ULONG value from
  1903. //
  1904. // Return Value:
  1905. //
  1906. // none.
  1907. //
  1908. // Note:
  1909. // Depending on the machine, we might want to call retrieveushort in the
  1910. // unaligned case.
  1911. //
  1912. //--
  1913. #define RtlRetrieveUlong(DEST_ADDRESS,SRC_ADDRESS) \
  1914. if ((ULONG)SRC_ADDRESS & LONG_MASK) { \
  1915. ((PUCHAR) DEST_ADDRESS)[0] = ((PUCHAR) SRC_ADDRESS)[0]; \
  1916. ((PUCHAR) DEST_ADDRESS)[1] = ((PUCHAR) SRC_ADDRESS)[1]; \
  1917. ((PUCHAR) DEST_ADDRESS)[2] = ((PUCHAR) SRC_ADDRESS)[2]; \
  1918. ((PUCHAR) DEST_ADDRESS)[3] = ((PUCHAR) SRC_ADDRESS)[3]; \
  1919. } \
  1920. else { \
  1921. *((PULONG) DEST_ADDRESS) = *((PULONG) SRC_ADDRESS); \
  1922. }
  1923. #define RtlEqualLuid(L1, L2) (((L1)->HighPart == (L2)->HighPart) && \
  1924. ((L1)->LowPart == (L2)->LowPart))
  1925. #if !defined(MIDL_PASS)
  1926. __inline LUID
  1927. NTAPI
  1928. RtlConvertLongToLuid(
  1929. LONG Long
  1930. )
  1931. {
  1932. LUID TempLuid;
  1933. LARGE_INTEGER TempLi;
  1934. TempLi = RtlConvertLongToLargeInteger(Long);
  1935. TempLuid.LowPart = TempLi.LowPart;
  1936. TempLuid.HighPart = TempLi.HighPart;
  1937. return(TempLuid);
  1938. }
  1939. __inline LUID
  1940. NTAPI
  1941. RtlConvertUlongToLuid(
  1942. ULONG Ulong
  1943. )
  1944. {
  1945. LUID TempLuid;
  1946. TempLuid.LowPart = Ulong;
  1947. TempLuid.HighPart = 0;
  1948. return(TempLuid);
  1949. }
  1950. #endif
  1951. //
  1952. // Define the various device type values. Note that values used by Microsoft
  1953. // Corporation are in the range 0-32767, and 32768-65535 are reserved for use
  1954. // by customers.
  1955. //
  1956. #define DEVICE_TYPE ULONG
  1957. #define FILE_DEVICE_BEEP 0x00000001
  1958. #define FILE_DEVICE_CD_ROM 0x00000002
  1959. #define FILE_DEVICE_CD_ROM_FILE_SYSTEM 0x00000003
  1960. #define FILE_DEVICE_CONTROLLER 0x00000004
  1961. #define FILE_DEVICE_DATALINK 0x00000005
  1962. #define FILE_DEVICE_DFS 0x00000006
  1963. #define FILE_DEVICE_DISK 0x00000007
  1964. #define FILE_DEVICE_DISK_FILE_SYSTEM 0x00000008
  1965. #define FILE_DEVICE_FILE_SYSTEM 0x00000009
  1966. #define FILE_DEVICE_INPORT_PORT 0x0000000a
  1967. #define FILE_DEVICE_KEYBOARD 0x0000000b
  1968. #define FILE_DEVICE_MAILSLOT 0x0000000c
  1969. #define FILE_DEVICE_MIDI_IN 0x0000000d
  1970. #define FILE_DEVICE_MIDI_OUT 0x0000000e
  1971. #define FILE_DEVICE_MOUSE 0x0000000f
  1972. #define FILE_DEVICE_MULTI_UNC_PROVIDER 0x00000010
  1973. #define FILE_DEVICE_NAMED_PIPE 0x00000011
  1974. #define FILE_DEVICE_NETWORK 0x00000012
  1975. #define FILE_DEVICE_NETWORK_BROWSER 0x00000013
  1976. #define FILE_DEVICE_NETWORK_FILE_SYSTEM 0x00000014
  1977. #define FILE_DEVICE_NULL 0x00000015
  1978. #define FILE_DEVICE_PARALLEL_PORT 0x00000016
  1979. #define FILE_DEVICE_PHYSICAL_NETCARD 0x00000017
  1980. #define FILE_DEVICE_PRINTER 0x00000018
  1981. #define FILE_DEVICE_SCANNER 0x00000019
  1982. #define FILE_DEVICE_SERIAL_MOUSE_PORT 0x0000001a
  1983. #define FILE_DEVICE_SERIAL_PORT 0x0000001b
  1984. #define FILE_DEVICE_SCREEN 0x0000001c
  1985. #define FILE_DEVICE_SOUND 0x0000001d
  1986. #define FILE_DEVICE_STREAMS 0x0000001e
  1987. #define FILE_DEVICE_TAPE 0x0000001f
  1988. #define FILE_DEVICE_TAPE_FILE_SYSTEM 0x00000020
  1989. #define FILE_DEVICE_TRANSPORT 0x00000021
  1990. #define FILE_DEVICE_UNKNOWN 0x00000022
  1991. #define FILE_DEVICE_VIDEO 0x00000023
  1992. #define FILE_DEVICE_VIRTUAL_DISK 0x00000024
  1993. #define FILE_DEVICE_WAVE_IN 0x00000025
  1994. #define FILE_DEVICE_WAVE_OUT 0x00000026
  1995. #define FILE_DEVICE_8042_PORT 0x00000027
  1996. #define FILE_DEVICE_NETWORK_REDIRECTOR 0x00000028
  1997. #define FILE_DEVICE_BATTERY 0x00000029
  1998. #define FILE_DEVICE_BUS_EXTENDER 0x0000002a
  1999. #define FILE_DEVICE_MODEM 0x0000002b
  2000. #define FILE_DEVICE_VDM 0x0000002c
  2001. #define FILE_DEVICE_MASS_STORAGE 0x0000002d
  2002. //
  2003. // Macro definition for defining IOCTL and FSCTL function control codes. Note
  2004. // that function codes 0-2047 are reserved for Microsoft Corporation, and
  2005. // 2048-4095 are reserved for customers.
  2006. //
  2007. #define CTL_CODE( DeviceType, Function, Method, Access ) ( \
  2008. ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
  2009. )
  2010. //
  2011. // Define the method codes for how buffers are passed for I/O and FS controls
  2012. //
  2013. #define METHOD_BUFFERED 0
  2014. #define METHOD_IN_DIRECT 1
  2015. #define METHOD_OUT_DIRECT 2
  2016. #define METHOD_NEITHER 3
  2017. //
  2018. // Define the access check value for any access
  2019. //
  2020. //
  2021. // The FILE_READ_ACCESS and FILE_WRITE_ACCESS constants are also defined in
  2022. // ntioapi.h as FILE_READ_DATA and FILE_WRITE_DATA. The values for these
  2023. // constants *MUST* always be in sync.
  2024. //
  2025. #define FILE_ANY_ACCESS 0
  2026. #define FILE_READ_ACCESS ( 0x0001 ) // file & pipe
  2027. #define FILE_WRITE_ACCESS ( 0x0002 ) // file & pipe
  2028. // begin_winnt
  2029. //
  2030. // Define access rights to files and directories
  2031. //
  2032. //
  2033. // The FILE_READ_DATA and FILE_WRITE_DATA constants are also defined in
  2034. // devioctl.h as FILE_READ_ACCESS and FILE_WRITE_ACCESS. The values for these
  2035. // constants *MUST* always be in sync.
  2036. // The values are redefined in devioctl.h because they must be available to
  2037. // both DOS and NT.
  2038. //
  2039. #define FILE_READ_DATA ( 0x0001 ) // file & pipe
  2040. #define FILE_LIST_DIRECTORY ( 0x0001 ) // directory
  2041. #define FILE_WRITE_DATA ( 0x0002 ) // file & pipe
  2042. #define FILE_ADD_FILE ( 0x0002 ) // directory
  2043. #define FILE_APPEND_DATA ( 0x0004 ) // file
  2044. #define FILE_ADD_SUBDIRECTORY ( 0x0004 ) // directory
  2045. #define FILE_CREATE_PIPE_INSTANCE ( 0x0004 ) // named pipe
  2046. #define FILE_READ_EA ( 0x0008 ) // file & directory
  2047. #define FILE_WRITE_EA ( 0x0010 ) // file & directory
  2048. #define FILE_EXECUTE ( 0x0020 ) // file
  2049. #define FILE_TRAVERSE ( 0x0020 ) // directory
  2050. #define FILE_DELETE_CHILD ( 0x0040 ) // directory
  2051. #define FILE_READ_ATTRIBUTES ( 0x0080 ) // all
  2052. #define FILE_WRITE_ATTRIBUTES ( 0x0100 ) // all
  2053. #define FILE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x1FF)
  2054. #define FILE_GENERIC_READ (STANDARD_RIGHTS_READ |\
  2055. FILE_READ_DATA |\
  2056. FILE_READ_ATTRIBUTES |\
  2057. FILE_READ_EA |\
  2058. SYNCHRONIZE)
  2059. #define FILE_GENERIC_WRITE (STANDARD_RIGHTS_WRITE |\
  2060. FILE_WRITE_DATA |\
  2061. FILE_WRITE_ATTRIBUTES |\
  2062. FILE_WRITE_EA |\
  2063. FILE_APPEND_DATA |\
  2064. SYNCHRONIZE)
  2065. #define FILE_GENERIC_EXECUTE (STANDARD_RIGHTS_EXECUTE |\
  2066. FILE_READ_ATTRIBUTES |\
  2067. FILE_EXECUTE |\
  2068. SYNCHRONIZE)
  2069. // end_winnt
  2070. //
  2071. // Define share access rights to files and directories
  2072. //
  2073. #define FILE_SHARE_READ 0x00000001 // winnt
  2074. #define FILE_SHARE_WRITE 0x00000002 // winnt
  2075. #define FILE_SHARE_DELETE 0x00000004 // winnt
  2076. #define FILE_SHARE_VALID_FLAGS 0x00000007
  2077. //
  2078. // Define the file attributes values
  2079. //
  2080. // Note: 0x00000008 is reserved for use for the old DOS VOLID (volume ID)
  2081. // and is therefore not considered valid in NT.
  2082. //
  2083. // Note: 0x00000010 is reserved for use for the old DOS SUBDIRECTORY flag
  2084. // and is therefore not considered valid in NT. This flag has
  2085. // been disassociated with file attributes since the other flags are
  2086. // protected with READ_ and WRITE_ATTRIBUTES access to the file.
  2087. //
  2088. // Note: Note also that the order of these flags is set to allow both the
  2089. // FAT and the Pinball File Systems to directly set the attributes
  2090. // flags in attributes words without having to pick each flag out
  2091. // individually. The order of these flags should not be changed!
  2092. //
  2093. #define FILE_ATTRIBUTE_READONLY 0x00000001 // winnt
  2094. #define FILE_ATTRIBUTE_HIDDEN 0x00000002 // winnt
  2095. #define FILE_ATTRIBUTE_SYSTEM 0x00000004 // winnt
  2096. #define FILE_ATTRIBUTE_DIRECTORY 0x00000010 // winnt
  2097. #define FILE_ATTRIBUTE_ARCHIVE 0x00000020 // winnt
  2098. #define FILE_ATTRIBUTE_NORMAL 0x00000080 // winnt
  2099. #define FILE_ATTRIBUTE_TEMPORARY 0x00000100 // winnt
  2100. #define FILE_ATTRIBUTE_RESERVED0 0x00000200
  2101. #define FILE_ATTRIBUTE_RESERVED1 0x00000400
  2102. #define FILE_ATTRIBUTE_COMPRESSED 0x00000800 // winnt
  2103. #define FILE_ATTRIBUTE_OFFLINE 0x00001000 // winnt
  2104. #define FILE_ATTRIBUTE_PROPERTY_SET 0x00002000
  2105. #define FILE_ATTRIBUTE_VALID_FLAGS 0x00003fb7
  2106. #define FILE_ATTRIBUTE_VALID_SET_FLAGS 0x00003fa7
  2107. //
  2108. // Define the create disposition values
  2109. //
  2110. #define FILE_SUPERSEDE 0x00000000
  2111. #define FILE_OPEN 0x00000001
  2112. #define FILE_CREATE 0x00000002
  2113. #define FILE_OPEN_IF 0x00000003
  2114. #define FILE_OVERWRITE 0x00000004
  2115. #define FILE_OVERWRITE_IF 0x00000005
  2116. #define FILE_MAXIMUM_DISPOSITION 0x00000005
  2117. //
  2118. // Define the create/open option flags
  2119. //
  2120. #define FILE_DIRECTORY_FILE 0x00000001
  2121. #define FILE_WRITE_THROUGH 0x00000002
  2122. #define FILE_SEQUENTIAL_ONLY 0x00000004
  2123. #define FILE_NO_INTERMEDIATE_BUFFERING 0x00000008
  2124. #define FILE_SYNCHRONOUS_IO_ALERT 0x00000010
  2125. #define FILE_SYNCHRONOUS_IO_NONALERT 0x00000020
  2126. #define FILE_NON_DIRECTORY_FILE 0x00000040
  2127. #define FILE_CREATE_TREE_CONNECTION 0x00000080
  2128. #define FILE_COMPLETE_IF_OPLOCKED 0x00000100
  2129. #define FILE_NO_EA_KNOWLEDGE 0x00000200
  2130. //UNUSED 0x00000400
  2131. #define FILE_RANDOM_ACCESS 0x00000800
  2132. #define FILE_DELETE_ON_CLOSE 0x00001000
  2133. #define FILE_OPEN_BY_FILE_ID 0x00002000
  2134. #define FILE_OPEN_FOR_BACKUP_INTENT 0x00004000
  2135. #define FILE_NO_COMPRESSION 0x00008000
  2136. #define FILE_RESERVE_OPFILTER 0x00100000
  2137. #define FILE_TRANSACTED_MODE 0x00200000
  2138. #define FILE_OPEN_OFFLINE_FILE 0x00400000
  2139. #define FILE_OPEN_FOR_FREE_SPACE_QUERY 0x00800000
  2140. #define FILE_VALID_OPTION_FLAGS 0x00ffffff
  2141. #define FILE_VALID_PIPE_OPTION_FLAGS 0x00000032
  2142. #define FILE_VALID_MAILSLOT_OPTION_FLAGS 0x00000032
  2143. #define FILE_VALID_SET_FLAGS 0x00000036
  2144. //
  2145. // Define the I/O status information return values for NtCreateFile/NtOpenFile
  2146. //
  2147. #define FILE_SUPERSEDED 0x00000000
  2148. #define FILE_OPENED 0x00000001
  2149. #define FILE_CREATED 0x00000002
  2150. #define FILE_OVERWRITTEN 0x00000003
  2151. #define FILE_EXISTS 0x00000004
  2152. #define FILE_DOES_NOT_EXIST 0x00000005
  2153. //
  2154. // Define special ByteOffset parameters for read and write operations
  2155. //
  2156. #define FILE_WRITE_TO_END_OF_FILE 0xffffffff
  2157. #define FILE_USE_FILE_POINTER_POSITION 0xfffffffe
  2158. //
  2159. // Define alignment requirement values
  2160. //
  2161. #define FILE_BYTE_ALIGNMENT 0x00000000
  2162. #define FILE_WORD_ALIGNMENT 0x00000001
  2163. #define FILE_LONG_ALIGNMENT 0x00000003
  2164. #define FILE_QUAD_ALIGNMENT 0x00000007
  2165. #define FILE_OCTA_ALIGNMENT 0x0000000f
  2166. #define FILE_32_BYTE_ALIGNMENT 0x0000001f
  2167. #define FILE_64_BYTE_ALIGNMENT 0x0000003f
  2168. #define FILE_128_BYTE_ALIGNMENT 0x0000007f
  2169. #define FILE_256_BYTE_ALIGNMENT 0x000000ff
  2170. #define FILE_512_BYTE_ALIGNMENT 0x000001ff
  2171. //
  2172. // Define the maximum length of a filename string
  2173. //
  2174. #define MAXIMUM_FILENAME_LENGTH 256
  2175. //
  2176. // Define the various device characteristics flags
  2177. //
  2178. #define FILE_REMOVABLE_MEDIA 0x00000001
  2179. #define FILE_READ_ONLY_DEVICE 0x00000002
  2180. #define FILE_FLOPPY_DISKETTE 0x00000004
  2181. #define FILE_WRITE_ONCE_MEDIA 0x00000008
  2182. #define FILE_REMOTE_DEVICE 0x00000010
  2183. #define FILE_DEVICE_IS_MOUNTED 0x00000020
  2184. #define FILE_VIRTUAL_VOLUME 0x00000040
  2185. //
  2186. // Define the base asynchronous I/O argument types
  2187. //
  2188. typedef struct _IO_STATUS_BLOCK {
  2189. NTSTATUS Status;
  2190. ULONG Information;
  2191. } IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;
  2192. //
  2193. // Define an Asynchronous Procedure Call from I/O viewpoint
  2194. //
  2195. typedef
  2196. VOID
  2197. (*PIO_APC_ROUTINE) (
  2198. IN PVOID ApcContext,
  2199. IN PIO_STATUS_BLOCK IoStatusBlock,
  2200. IN ULONG Reserved
  2201. );
  2202. //
  2203. // Define the file information class values
  2204. //
  2205. // WARNING: The order of the following values are assumed by the I/O system.
  2206. // Any changes made here should be reflected there as well.
  2207. //
  2208. typedef enum _FILE_INFORMATION_CLASS {
  2209. FileDirectoryInformation = 1,
  2210. FileFullDirectoryInformation,
  2211. FileBothDirectoryInformation,
  2212. FileBasicInformation,
  2213. FileStandardInformation,
  2214. FileInternalInformation,
  2215. FileEaInformation,
  2216. FileAccessInformation,
  2217. FileNameInformation,
  2218. FileRenameInformation,
  2219. FileLinkInformation,
  2220. FileNamesInformation,
  2221. FileDispositionInformation,
  2222. FilePositionInformation,
  2223. FileFullEaInformation,
  2224. FileModeInformation,
  2225. FileAlignmentInformation,
  2226. FileAllInformation,
  2227. FileAllocationInformation,
  2228. FileEndOfFileInformation,
  2229. FileAlternateNameInformation,
  2230. FileStreamInformation,
  2231. FilePipeInformation,
  2232. FilePipeLocalInformation,
  2233. FilePipeRemoteInformation,
  2234. FileMailslotQueryInformation,
  2235. FileMailslotSetInformation,
  2236. FileCompressionInformation,
  2237. FileCopyOnWriteInformation,
  2238. FileCompletionInformation,
  2239. FileMoveClusterInformation,
  2240. FileOleClassIdInformation,
  2241. FileOleStateBitsInformation,
  2242. FileNetworkOpenInformation,
  2243. FileObjectIdInformation,
  2244. FileOleAllInformation,
  2245. FileOleDirectoryInformation,
  2246. FileContentIndexInformation,
  2247. FileInheritContentIndexInformation,
  2248. FileOleInformation,
  2249. FileMaximumInformation
  2250. } FILE_INFORMATION_CLASS, *PFILE_INFORMATION_CLASS;
  2251. //
  2252. // Define the various structures which are returned on query operations
  2253. //
  2254. typedef struct _FILE_BASIC_INFORMATION {
  2255. LARGE_INTEGER CreationTime;
  2256. LARGE_INTEGER LastAccessTime;
  2257. LARGE_INTEGER LastWriteTime;
  2258. LARGE_INTEGER ChangeTime;
  2259. ULONG FileAttributes;
  2260. } FILE_BASIC_INFORMATION, *PFILE_BASIC_INFORMATION;
  2261. typedef struct _FILE_STANDARD_INFORMATION {
  2262. LARGE_INTEGER AllocationSize;
  2263. LARGE_INTEGER EndOfFile;
  2264. ULONG NumberOfLinks;
  2265. BOOLEAN DeletePending;
  2266. BOOLEAN Directory;
  2267. } FILE_STANDARD_INFORMATION, *PFILE_STANDARD_INFORMATION;
  2268. typedef struct _FILE_POSITION_INFORMATION {
  2269. LARGE_INTEGER CurrentByteOffset;
  2270. } FILE_POSITION_INFORMATION, *PFILE_POSITION_INFORMATION;
  2271. typedef struct _FILE_ALIGNMENT_INFORMATION {
  2272. ULONG AlignmentRequirement;
  2273. } FILE_ALIGNMENT_INFORMATION, *PFILE_ALIGNMENT_INFORMATION;
  2274. typedef struct _FILE_NETWORK_OPEN_INFORMATION {
  2275. LARGE_INTEGER CreationTime;
  2276. LARGE_INTEGER LastAccessTime;
  2277. LARGE_INTEGER LastWriteTime;
  2278. LARGE_INTEGER ChangeTime;
  2279. LARGE_INTEGER AllocationSize;
  2280. LARGE_INTEGER EndOfFile;
  2281. ULONG FileAttributes;
  2282. } FILE_NETWORK_OPEN_INFORMATION, *PFILE_NETWORK_OPEN_INFORMATION;
  2283. typedef struct _FILE_DISPOSITION_INFORMATION {
  2284. BOOLEAN DeleteFile;
  2285. } FILE_DISPOSITION_INFORMATION, *PFILE_DISPOSITION_INFORMATION;
  2286. typedef struct _FILE_END_OF_FILE_INFORMATION {
  2287. LARGE_INTEGER EndOfFile;
  2288. } FILE_END_OF_FILE_INFORMATION, *PFILE_END_OF_FILE_INFORMATION;
  2289. typedef struct _FILE_FULL_EA_INFORMATION {
  2290. ULONG NextEntryOffset;
  2291. UCHAR Flags;
  2292. UCHAR EaNameLength;
  2293. USHORT EaValueLength;
  2294. CHAR EaName[1];
  2295. } FILE_FULL_EA_INFORMATION, *PFILE_FULL_EA_INFORMATION;
  2296. //
  2297. // Define the file system information class values
  2298. //
  2299. // WARNING: The order of the following values are assumed by the I/O system.
  2300. // Any changes made here should be reflected there as well.
  2301. typedef enum _FSINFOCLASS {
  2302. FileFsVolumeInformation = 1,
  2303. FileFsLabelInformation,
  2304. FileFsSizeInformation,
  2305. FileFsDeviceInformation,
  2306. FileFsAttributeInformation,
  2307. FileFsControlInformation,
  2308. FileFsFullSizeInformation,
  2309. FileFsMaximumInformation
  2310. } FS_INFORMATION_CLASS, *PFS_INFORMATION_CLASS;
  2311. typedef struct _FILE_FS_DEVICE_INFORMATION {
  2312. DEVICE_TYPE DeviceType;
  2313. ULONG Characteristics;
  2314. } FILE_FS_DEVICE_INFORMATION, *PFILE_FS_DEVICE_INFORMATION;
  2315. //
  2316. // Define the I/O bus interface types.
  2317. //
  2318. typedef enum _INTERFACE_TYPE {
  2319. InterfaceTypeUndefined = -1,
  2320. Internal,
  2321. Isa,
  2322. Eisa,
  2323. MicroChannel,
  2324. TurboChannel,
  2325. PCIBus,
  2326. VMEBus,
  2327. NuBus,
  2328. PCMCIABus,
  2329. CBus,
  2330. MPIBus,
  2331. MPSABus,
  2332. ProcessorInternal,
  2333. InternalPowerBus,
  2334. PNPISABus,
  2335. MaximumInterfaceType
  2336. }INTERFACE_TYPE, *PINTERFACE_TYPE;
  2337. //
  2338. // Define types of bus information.
  2339. //
  2340. typedef enum _BUS_DATA_TYPE {
  2341. ConfigurationSpaceUndefined = -1,
  2342. Cmos,
  2343. EisaConfiguration,
  2344. Pos,
  2345. CbusConfiguration,
  2346. PCIConfiguration,
  2347. VMEConfiguration,
  2348. NuBusConfiguration,
  2349. PCMCIAConfiguration,
  2350. MPIConfiguration,
  2351. MPSAConfiguration,
  2352. PNPISAConfiguration,
  2353. MaximumBusDataType
  2354. } BUS_DATA_TYPE, *PBUS_DATA_TYPE;
  2355. //
  2356. // Define the DMA transfer widths.
  2357. //
  2358. typedef enum _DMA_WIDTH {
  2359. Width8Bits,
  2360. Width16Bits,
  2361. Width32Bits,
  2362. MaximumDmaWidth
  2363. }DMA_WIDTH, *PDMA_WIDTH;
  2364. //
  2365. // Define DMA transfer speeds.
  2366. //
  2367. typedef enum _DMA_SPEED {
  2368. Compatible,
  2369. TypeA,
  2370. TypeB,
  2371. TypeC,
  2372. MaximumDmaSpeed
  2373. }DMA_SPEED, *PDMA_SPEED;
  2374. //
  2375. // Define I/O Driver error log packet structure. This structure is filled in
  2376. // by the driver.
  2377. //
  2378. typedef struct _IO_ERROR_LOG_PACKET {
  2379. UCHAR MajorFunctionCode;
  2380. UCHAR RetryCount;
  2381. USHORT DumpDataSize;
  2382. USHORT NumberOfStrings;
  2383. USHORT StringOffset;
  2384. USHORT EventCategory;
  2385. NTSTATUS ErrorCode;
  2386. ULONG UniqueErrorValue;
  2387. NTSTATUS FinalStatus;
  2388. ULONG SequenceNumber;
  2389. ULONG IoControlCode;
  2390. LARGE_INTEGER DeviceOffset;
  2391. ULONG DumpData[1];
  2392. }IO_ERROR_LOG_PACKET, *PIO_ERROR_LOG_PACKET;
  2393. //
  2394. // Define the I/O error log message. This message is sent by the error log
  2395. // thread over the lpc port.
  2396. //
  2397. typedef struct _IO_ERROR_LOG_MESSAGE {
  2398. USHORT Type;
  2399. USHORT Size;
  2400. USHORT DriverNameLength;
  2401. LARGE_INTEGER TimeStamp;
  2402. ULONG DriverNameOffset;
  2403. IO_ERROR_LOG_PACKET EntryData;
  2404. }IO_ERROR_LOG_MESSAGE, *PIO_ERROR_LOG_MESSAGE;
  2405. //
  2406. // Define the maximum message size that will be sent over the LPC to the
  2407. // application reading the error log entries.
  2408. //
  2409. #define IO_ERROR_LOG_MESSAGE_LENGTH PORT_MAXIMUM_MESSAGE_LENGTH
  2410. //
  2411. // Define the maximum packet size a driver can allocate.
  2412. //
  2413. #define ERROR_LOG_MAXIMUM_SIZE (IO_ERROR_LOG_MESSAGE_LENGTH + sizeof(IO_ERROR_LOG_PACKET) - \
  2414. sizeof(IO_ERROR_LOG_MESSAGE) - (sizeof(WCHAR) * 40))
  2415. #define PORT_MAXIMUM_MESSAGE_LENGTH 256
  2416. //
  2417. // Registry Specific Access Rights.
  2418. //
  2419. #define KEY_QUERY_VALUE (0x0001)
  2420. #define KEY_SET_VALUE (0x0002)
  2421. #define KEY_CREATE_SUB_KEY (0x0004)
  2422. #define KEY_ENUMERATE_SUB_KEYS (0x0008)
  2423. #define KEY_NOTIFY (0x0010)
  2424. #define KEY_CREATE_LINK (0x0020)
  2425. #define KEY_READ ((STANDARD_RIGHTS_READ |\
  2426. KEY_QUERY_VALUE |\
  2427. KEY_ENUMERATE_SUB_KEYS |\
  2428. KEY_NOTIFY) \
  2429. & \
  2430. (~SYNCHRONIZE))
  2431. #define KEY_WRITE ((STANDARD_RIGHTS_WRITE |\
  2432. KEY_SET_VALUE |\
  2433. KEY_CREATE_SUB_KEY) \
  2434. & \
  2435. (~SYNCHRONIZE))
  2436. #define KEY_EXECUTE ((KEY_READ) \
  2437. & \
  2438. (~SYNCHRONIZE))
  2439. #define KEY_ALL_ACCESS ((STANDARD_RIGHTS_ALL |\
  2440. KEY_QUERY_VALUE |\
  2441. KEY_SET_VALUE |\
  2442. KEY_CREATE_SUB_KEY |\
  2443. KEY_ENUMERATE_SUB_KEYS |\
  2444. KEY_NOTIFY |\
  2445. KEY_CREATE_LINK) \
  2446. & \
  2447. (~SYNCHRONIZE))
  2448. //
  2449. // Open/Create Options
  2450. //
  2451. #define REG_OPTION_RESERVED (0x00000000L) // Parameter is reserved
  2452. #define REG_OPTION_NON_VOLATILE (0x00000000L) // Key is preserved
  2453. // when system is rebooted
  2454. #define REG_OPTION_VOLATILE (0x00000001L) // Key is not preserved
  2455. // when system is rebooted
  2456. #define REG_OPTION_CREATE_LINK (0x00000002L) // Created key is a
  2457. // symbolic link
  2458. #define REG_OPTION_BACKUP_RESTORE (0x00000004L) // open for backup or restore
  2459. // special access rules
  2460. // privilege required
  2461. #define REG_OPTION_OPEN_LINK (0x00000008L) // Open symbolic link
  2462. #define REG_LEGAL_OPTION \
  2463. (REG_OPTION_RESERVED |\
  2464. REG_OPTION_NON_VOLATILE |\
  2465. REG_OPTION_VOLATILE |\
  2466. REG_OPTION_CREATE_LINK |\
  2467. REG_OPTION_BACKUP_RESTORE |\
  2468. REG_OPTION_OPEN_LINK)
  2469. //
  2470. // Key creation/open disposition
  2471. //
  2472. #define REG_CREATED_NEW_KEY (0x00000001L) // New Registry Key created
  2473. #define REG_OPENED_EXISTING_KEY (0x00000002L) // Existing Key opened
  2474. //
  2475. // Key restore flags
  2476. //
  2477. #define REG_WHOLE_HIVE_VOLATILE (0x00000001L) // Restore whole hive volatile
  2478. #define REG_REFRESH_HIVE (0x00000002L) // Unwind changes to last flush
  2479. #define REG_NO_LAZY_FLUSH (0x00000004L) // Never lazy flush this hive
  2480. //
  2481. // Key query structures
  2482. //
  2483. typedef struct _KEY_BASIC_INFORMATION {
  2484. LARGE_INTEGER LastWriteTime;
  2485. ULONG TitleIndex;
  2486. ULONG NameLength;
  2487. WCHAR Name[1]; // Variable length string
  2488. } KEY_BASIC_INFORMATION, *PKEY_BASIC_INFORMATION;
  2489. typedef struct _KEY_NODE_INFORMATION {
  2490. LARGE_INTEGER LastWriteTime;
  2491. ULONG TitleIndex;
  2492. ULONG ClassOffset;
  2493. ULONG ClassLength;
  2494. ULONG NameLength;
  2495. WCHAR Name[1]; // Variable length string
  2496. // Class[1]; // Variable length string not declared
  2497. } KEY_NODE_INFORMATION, *PKEY_NODE_INFORMATION;
  2498. typedef struct _KEY_FULL_INFORMATION {
  2499. LARGE_INTEGER LastWriteTime;
  2500. ULONG TitleIndex;
  2501. ULONG ClassOffset;
  2502. ULONG ClassLength;
  2503. ULONG SubKeys;
  2504. ULONG MaxNameLen;
  2505. ULONG MaxClassLen;
  2506. ULONG Values;
  2507. ULONG MaxValueNameLen;
  2508. ULONG MaxValueDataLen;
  2509. WCHAR Class[1]; // Variable length
  2510. } KEY_FULL_INFORMATION, *PKEY_FULL_INFORMATION;
  2511. typedef enum _KEY_INFORMATION_CLASS {
  2512. KeyBasicInformation,
  2513. KeyNodeInformation,
  2514. KeyFullInformation
  2515. } KEY_INFORMATION_CLASS;
  2516. typedef struct _KEY_WRITE_TIME_INFORMATION {
  2517. LARGE_INTEGER LastWriteTime;
  2518. } KEY_WRITE_TIME_INFORMATION, *PKEY_WRITE_TIME_INFORMATION;
  2519. typedef enum _KEY_SET_INFORMATION_CLASS {
  2520. KeyWriteTimeInformation
  2521. } KEY_SET_INFORMATION_CLASS;
  2522. //
  2523. // Value entry query structures
  2524. //
  2525. typedef struct _KEY_VALUE_BASIC_INFORMATION {
  2526. ULONG TitleIndex;
  2527. ULONG Type;
  2528. ULONG NameLength;
  2529. WCHAR Name[1]; // Variable size
  2530. } KEY_VALUE_BASIC_INFORMATION, *PKEY_VALUE_BASIC_INFORMATION;
  2531. typedef struct _KEY_VALUE_FULL_INFORMATION {
  2532. ULONG TitleIndex;
  2533. ULONG Type;
  2534. ULONG DataOffset;
  2535. ULONG DataLength;
  2536. ULONG NameLength;
  2537. WCHAR Name[1]; // Variable size
  2538. // Data[1]; // Variable size data not declared
  2539. } KEY_VALUE_FULL_INFORMATION, *PKEY_VALUE_FULL_INFORMATION;
  2540. typedef struct _KEY_VALUE_PARTIAL_INFORMATION {
  2541. ULONG TitleIndex;
  2542. ULONG Type;
  2543. ULONG DataLength;
  2544. UCHAR Data[1]; // Variable size
  2545. } KEY_VALUE_PARTIAL_INFORMATION, *PKEY_VALUE_PARTIAL_INFORMATION;
  2546. typedef struct _KEY_VALUE_ENTRY {
  2547. PUNICODE_STRING ValueName;
  2548. ULONG DataLength;
  2549. ULONG DataOffset;
  2550. ULONG Type;
  2551. } KEY_VALUE_ENTRY, *PKEY_VALUE_ENTRY;
  2552. typedef enum _KEY_VALUE_INFORMATION_CLASS {
  2553. KeyValueBasicInformation,
  2554. KeyValueFullInformation,
  2555. KeyValuePartialInformation
  2556. } KEY_VALUE_INFORMATION_CLASS;
  2557. #define OBJ_NAME_PATH_SEPARATOR ((WCHAR)L'\\')
  2558. //
  2559. // Object Manager Object Type Specific Access Rights.
  2560. //
  2561. #define OBJECT_TYPE_CREATE (0x0001)
  2562. #define OBJECT_TYPE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0x1)
  2563. //
  2564. // Object Manager Directory Specific Access Rights.
  2565. //
  2566. #define DIRECTORY_QUERY (0x0001)
  2567. #define DIRECTORY_TRAVERSE (0x0002)
  2568. #define DIRECTORY_CREATE_OBJECT (0x0004)
  2569. #define DIRECTORY_CREATE_SUBDIRECTORY (0x0008)
  2570. #define DIRECTORY_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0xF)
  2571. //
  2572. // Object Manager Symbolic Link Specific Access Rights.
  2573. //
  2574. #define SYMBOLIC_LINK_QUERY (0x0001)
  2575. #define SYMBOLIC_LINK_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0x1)
  2576. typedef struct _OBJECT_NAME_INFORMATION {
  2577. UNICODE_STRING Name;
  2578. } OBJECT_NAME_INFORMATION, *POBJECT_NAME_INFORMATION;
  2579. #define DUPLICATE_CLOSE_SOURCE 0x00000001 // winnt
  2580. #define DUPLICATE_SAME_ACCESS 0x00000002 // winnt
  2581. #define DUPLICATE_SAME_ATTRIBUTES 0x00000004
  2582. //
  2583. // Section Information Structures.
  2584. //
  2585. typedef enum _SECTION_INHERIT {
  2586. ViewShare = 1,
  2587. ViewUnmap = 2
  2588. } SECTION_INHERIT;
  2589. //
  2590. // Section Access Rights.
  2591. //
  2592. // begin_winnt
  2593. #define SECTION_QUERY 0x0001
  2594. #define SECTION_MAP_WRITE 0x0002
  2595. #define SECTION_MAP_READ 0x0004
  2596. #define SECTION_MAP_EXECUTE 0x0008
  2597. #define SECTION_EXTEND_SIZE 0x0010
  2598. #define SECTION_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SECTION_QUERY|\
  2599. SECTION_MAP_WRITE | \
  2600. SECTION_MAP_READ | \
  2601. SECTION_MAP_EXECUTE | \
  2602. SECTION_EXTEND_SIZE)
  2603. // end_winnt
  2604. #define SEGMENT_ALL_ACCESS SECTION_ALL_ACCESS
  2605. #define PAGE_NOACCESS 0x01 // winnt
  2606. #define PAGE_READONLY 0x02 // winnt
  2607. #define PAGE_READWRITE 0x04 // winnt
  2608. #define PAGE_WRITECOPY 0x08 // winnt
  2609. #define PAGE_EXECUTE 0x10 // winnt
  2610. #define PAGE_EXECUTE_READ 0x20 // winnt
  2611. #define PAGE_EXECUTE_READWRITE 0x40 // winnt
  2612. #define PAGE_EXECUTE_WRITECOPY 0x80 // winnt
  2613. #define PAGE_GUARD 0x100 // winnt
  2614. #define PAGE_NOCACHE 0x200 // winnt
  2615. #define MEM_COMMIT 0x1000
  2616. #define MEM_RESERVE 0x2000
  2617. #define MEM_DECOMMIT 0x4000
  2618. #define MEM_RELEASE 0x8000
  2619. #define MEM_FREE 0x10000
  2620. #define MEM_PRIVATE 0x20000
  2621. #define MEM_MAPPED 0x40000
  2622. #define MEM_RESET 0x80000
  2623. #define MEM_TOP_DOWN 0x100000
  2624. #define MEM_LARGE_PAGES 0x20000000
  2625. #define SEC_RESERVE 0x4000000
  2626. #define PROCESS_DUP_HANDLE (0x0040) // winnt
  2627. #define PROCESS_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
  2628. 0xFFF)
  2629. #define MAXIMUM_PROCESSORS 32
  2630. // end_winnt
  2631. //
  2632. // Thread Specific Access Rights
  2633. //
  2634. #define THREAD_TERMINATE (0x0001) // winnt
  2635. #define THREAD_SET_INFORMATION (0x0020) // winnt
  2636. #define THREAD_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
  2637. 0x3FF)
  2638. //
  2639. // ClientId
  2640. //
  2641. typedef struct _CLIENT_ID {
  2642. HANDLE UniqueProcess;
  2643. HANDLE UniqueThread;
  2644. } CLIENT_ID;
  2645. typedef CLIENT_ID *PCLIENT_ID;
  2646. //
  2647. // Thread Environment Block (and portable part of Thread Information Block)
  2648. //
  2649. //
  2650. // NT_TIB - Thread Information Block - Portable part.
  2651. //
  2652. // This is the subsystem portable part of the Thread Information Block.
  2653. // It appears as the first part of the TEB for all threads which have
  2654. // a user mode component.
  2655. //
  2656. // This structure MUST MATCH OS/2 V2.0!
  2657. //
  2658. // There is another, non-portable part of the TIB which is used
  2659. // for by subsystems, i.e. Os2Tib for OS/2 threads. SubSystemTib
  2660. // points there.
  2661. //
  2662. // begin_winnt
  2663. typedef struct _NT_TIB {
  2664. struct _EXCEPTION_REGISTRATION_RECORD *ExceptionList;
  2665. PVOID StackBase;
  2666. PVOID StackLimit;
  2667. PVOID SubSystemTib;
  2668. union {
  2669. PVOID FiberData;
  2670. ULONG Version;
  2671. };
  2672. PVOID ArbitraryUserPointer;
  2673. struct _NT_TIB *Self;
  2674. } NT_TIB;
  2675. typedef NT_TIB *PNT_TIB;
  2676. #define NtCurrentProcess() ( (HANDLE) -1 )
  2677. #define NtCurrentThread() ( (HANDLE) -2 )
  2678. typedef enum _SYSTEM_DOCK_STATE {
  2679. SystemDockStateUnknown,
  2680. SystemUndocked,
  2681. SystemDocked
  2682. } SYSTEM_DOCK_STATE, *PSYSTEM_DOCK_STATE;
  2683. //
  2684. //
  2685. // Define system event type codes.
  2686. //
  2687. typedef enum {
  2688. SystemEventVirtualKey,
  2689. SystemEventLidState,
  2690. SystemEventTimeChanged
  2691. } SYSTEM_EVENT_ID, *PSYSTEM_EVENT_ID;
  2692. //
  2693. // Defined processor features
  2694. //
  2695. #define PF_FLOATING_POINT_PRECISION_ERRATA 0 // winnt
  2696. #define PF_FLOATING_POINT_EMULATED 1 // winnt
  2697. #define PF_COMPARE_EXCHANGE_DOUBLE 2 // winnt
  2698. #define PF_MMX_INSTRUCTIONS_AVAILABLE 3 // winnt
  2699. #ifndef GUID_DEFINED
  2700. #define GUID_DEFINED
  2701. typedef struct _GUID
  2702. {
  2703. unsigned long Data1;
  2704. unsigned short Data2;
  2705. unsigned short Data3;
  2706. unsigned char Data4[8];
  2707. } GUID;
  2708. #endif /* GUID_DEFINED */
  2709. #ifndef __LPGUID_DEFINED__
  2710. #define __LPGUID_DEFINED__
  2711. typedef GUID *LPGUID;
  2712. #endif
  2713. //
  2714. // Define a reserved ordinal value indicating no such service instance
  2715. // or device instance.
  2716. //
  2717. #define PLUGPLAY_NO_INSTANCE (MAXULONG)
  2718. #if defined(_X86_)
  2719. //
  2720. // Define maximum size of flush multple TB request.
  2721. //
  2722. #define FLUSH_MULTIPLE_MAXIMUM 16
  2723. //
  2724. // Indicate that the i386 compiler supports the pragma textout construct.
  2725. //
  2726. #define ALLOC_PRAGMA 1
  2727. //
  2728. // Indicate that the i386 compiler supports the DATA_SEG("INIT") and
  2729. // DATA_SEG("PAGE") pragmas
  2730. //
  2731. #define ALLOC_DATA_PRAGMA 1
  2732. //
  2733. // Define function decoration.
  2734. //
  2735. #define NTKERNELAPI DECLSPEC_IMPORT
  2736. //
  2737. // Define function decoration depending on whether the HAL or other kernel
  2738. // component is being build.
  2739. //
  2740. #if !defined(_NTHAL_) && !defined(_BLDR_)
  2741. #define NTHALAPI DECLSPEC_IMPORT
  2742. #else
  2743. #define NTHALAPI
  2744. #endif
  2745. #define NORMAL_DISPATCH_LENGTH 106
  2746. #define DISPATCH_LENGTH NORMAL_DISPATCH_LENGTH
  2747. //
  2748. // STATUS register for each MCA bank.
  2749. //
  2750. typedef union _MCI_STATS {
  2751. struct {
  2752. USHORT McaCod;
  2753. USHORT MsCod;
  2754. ULONG OtherInfo : 25;
  2755. ULONG Damage : 1;
  2756. ULONG AddressValid : 1;
  2757. ULONG MiscValid : 1;
  2758. ULONG Enabled : 1;
  2759. ULONG UnCorrected : 1;
  2760. ULONG OverFlow : 1;
  2761. ULONG Valid : 1;
  2762. } MciStats;
  2763. ULONGLONG QuadPart;
  2764. } MCI_STATS, *PMCI_STATS;
  2765. //
  2766. // Interrupt Request Level definitions
  2767. //
  2768. #define PASSIVE_LEVEL 0 // Passive release level
  2769. #define LOW_LEVEL 0 // Lowest interrupt level
  2770. #define APC_LEVEL 1 // APC interrupt level
  2771. #define DISPATCH_LEVEL 2 // Dispatcher level
  2772. #define PROFILE_LEVEL 27 // timer used for profiling.
  2773. #define CLOCK1_LEVEL 28 // Interval clock 1 level - Not used on x86
  2774. #define CLOCK2_LEVEL 28 // Interval clock 2 level
  2775. #define IPI_LEVEL 29 // Interprocessor interrupt level
  2776. #define POWER_LEVEL 30 // Power failure level
  2777. #define HIGH_LEVEL 31 // Highest interrupt level
  2778. #define SYNCH_LEVEL (IPI_LEVEL-1) // synchronization level
  2779. //
  2780. // I/O space read and write macros.
  2781. //
  2782. // These have to be actual functions on the 386, because we need
  2783. // to use assembler, but cannot return a value if we inline it.
  2784. //
  2785. // The READ/WRITE_REGISTER_* calls manipulate I/O registers in MEMORY space.
  2786. // (Use x86 move instructions, with LOCK prefix to force correct behavior
  2787. // w.r.t. caches and write buffers.)
  2788. //
  2789. // The READ/WRITE_PORT_* calls manipulate I/O registers in PORT space.
  2790. // (Use x86 in/out instructions.)
  2791. //
  2792. NTKERNELAPI
  2793. UCHAR
  2794. READ_REGISTER_UCHAR(
  2795. PUCHAR Register
  2796. );
  2797. NTKERNELAPI
  2798. USHORT
  2799. READ_REGISTER_USHORT(
  2800. PUSHORT Register
  2801. );
  2802. NTKERNELAPI
  2803. ULONG
  2804. READ_REGISTER_ULONG(
  2805. PULONG Register
  2806. );
  2807. NTKERNELAPI
  2808. VOID
  2809. READ_REGISTER_BUFFER_UCHAR(
  2810. PUCHAR Register,
  2811. PUCHAR Buffer,
  2812. ULONG Count
  2813. );
  2814. NTKERNELAPI
  2815. VOID
  2816. READ_REGISTER_BUFFER_USHORT(
  2817. PUSHORT Register,
  2818. PUSHORT Buffer,
  2819. ULONG Count
  2820. );
  2821. NTKERNELAPI
  2822. VOID
  2823. READ_REGISTER_BUFFER_ULONG(
  2824. PULONG Register,
  2825. PULONG Buffer,
  2826. ULONG Count
  2827. );
  2828. NTKERNELAPI
  2829. VOID
  2830. WRITE_REGISTER_UCHAR(
  2831. PUCHAR Register,
  2832. UCHAR Value
  2833. );
  2834. NTKERNELAPI
  2835. VOID
  2836. WRITE_REGISTER_USHORT(
  2837. PUSHORT Register,
  2838. USHORT Value
  2839. );
  2840. NTKERNELAPI
  2841. VOID
  2842. WRITE_REGISTER_ULONG(
  2843. PULONG Register,
  2844. ULONG Value
  2845. );
  2846. NTKERNELAPI
  2847. VOID
  2848. WRITE_REGISTER_BUFFER_UCHAR(
  2849. PUCHAR Register,
  2850. PUCHAR Buffer,
  2851. ULONG Count
  2852. );
  2853. NTKERNELAPI
  2854. VOID
  2855. WRITE_REGISTER_BUFFER_USHORT(
  2856. PUSHORT Register,
  2857. PUSHORT Buffer,
  2858. ULONG Count
  2859. );
  2860. NTKERNELAPI
  2861. VOID
  2862. WRITE_REGISTER_BUFFER_ULONG(
  2863. PULONG Register,
  2864. PULONG Buffer,
  2865. ULONG Count
  2866. );
  2867. NTKERNELAPI
  2868. UCHAR
  2869. READ_PORT_UCHAR(
  2870. PUCHAR Port
  2871. );
  2872. NTKERNELAPI
  2873. USHORT
  2874. READ_PORT_USHORT(
  2875. PUSHORT Port
  2876. );
  2877. NTKERNELAPI
  2878. ULONG
  2879. READ_PORT_ULONG(
  2880. PULONG Port
  2881. );
  2882. NTKERNELAPI
  2883. VOID
  2884. READ_PORT_BUFFER_UCHAR(
  2885. PUCHAR Port,
  2886. PUCHAR Buffer,
  2887. ULONG Count
  2888. );
  2889. NTKERNELAPI
  2890. VOID
  2891. READ_PORT_BUFFER_USHORT(
  2892. PUSHORT Port,
  2893. PUSHORT Buffer,
  2894. ULONG Count
  2895. );
  2896. NTKERNELAPI
  2897. VOID
  2898. READ_PORT_BUFFER_ULONG(
  2899. PULONG Port,
  2900. PULONG Buffer,
  2901. ULONG Count
  2902. );
  2903. NTKERNELAPI
  2904. VOID
  2905. WRITE_PORT_UCHAR(
  2906. PUCHAR Port,
  2907. UCHAR Value
  2908. );
  2909. NTKERNELAPI
  2910. VOID
  2911. WRITE_PORT_USHORT(
  2912. PUSHORT Port,
  2913. USHORT Value
  2914. );
  2915. NTKERNELAPI
  2916. VOID
  2917. WRITE_PORT_ULONG(
  2918. PULONG Port,
  2919. ULONG Value
  2920. );
  2921. NTKERNELAPI
  2922. VOID
  2923. WRITE_PORT_BUFFER_UCHAR(
  2924. PUCHAR Port,
  2925. PUCHAR Buffer,
  2926. ULONG Count
  2927. );
  2928. NTKERNELAPI
  2929. VOID
  2930. WRITE_PORT_BUFFER_USHORT(
  2931. PUSHORT Port,
  2932. PUSHORT Buffer,
  2933. ULONG Count
  2934. );
  2935. NTKERNELAPI
  2936. VOID
  2937. WRITE_PORT_BUFFER_ULONG(
  2938. PULONG Port,
  2939. PULONG Buffer,
  2940. ULONG Count
  2941. );
  2942. // end_ntndis
  2943. //
  2944. // Get data cache fill size.
  2945. //
  2946. #define KeGetDcacheFillSize() 1L
  2947. #define KeFlushIoBuffers(Mdl, ReadOperation, DmaOperation)
  2948. #define ExAcquireSpinLock(Lock, OldIrql) KeAcquireSpinLock((Lock), (OldIrql))
  2949. #define ExReleaseSpinLock(Lock, OldIrql) KeReleaseSpinLock((Lock), (OldIrql))
  2950. #define ExAcquireSpinLockAtDpcLevel(Lock) KeAcquireSpinLockAtDpcLevel(Lock)
  2951. #define ExReleaseSpinLockFromDpcLevel(Lock) KeReleaseSpinLockFromDpcLevel(Lock)
  2952. #define KeQueryTickCount(CurrentCount ) { \
  2953. PKSYSTEM_TIME _TickCount = *((PKSYSTEM_TIME *)(&KeTickCount)); \
  2954. do { \
  2955. (CurrentCount)->HighPart = _TickCount->High1Time; \
  2956. (CurrentCount)->LowPart = _TickCount->LowPart; \
  2957. } while ((CurrentCount)->HighPart != _TickCount->High2Time); \
  2958. }
  2959. //
  2960. // Processor Control Region Structure Definition
  2961. //
  2962. #define PCR_MINOR_VERSION 1
  2963. #define PCR_MAJOR_VERSION 1
  2964. typedef struct _KPCR {
  2965. //
  2966. // Start of the architecturally defined section of the PCR. This section
  2967. // may be directly addressed by vendor/platform specific HAL code and will
  2968. // not change from version to version of NT.
  2969. //
  2970. NT_TIB NtTib;
  2971. struct _KPCR *SelfPcr; // flat address of this PCR
  2972. struct _KPRCB *Prcb; // pointer to Prcb
  2973. KIRQL Irql;
  2974. ULONG IRR;
  2975. ULONG IrrActive;
  2976. ULONG IDR;
  2977. ULONG Reserved2;
  2978. struct _KIDTENTRY *IDT;
  2979. struct _KGDTENTRY *GDT;
  2980. struct _KTSS *TSS;
  2981. USHORT MajorVersion;
  2982. USHORT MinorVersion;
  2983. KAFFINITY SetMember;
  2984. ULONG StallScaleFactor;
  2985. UCHAR DebugActive;
  2986. UCHAR Number;
  2987. } KPCR;
  2988. typedef KPCR *PKPCR;
  2989. //
  2990. // i386 Specific portions of mm component
  2991. //
  2992. //
  2993. // Define the page size for the Intel 386 as 4096 (0x1000).
  2994. //
  2995. #define PAGE_SIZE (ULONG)0x1000
  2996. //
  2997. // Define the number of trailing zeroes in a page aligned virtual address.
  2998. // This is used as the shift count when shifting virtual addresses to
  2999. // virtual page numbers.
  3000. //
  3001. #define PAGE_SHIFT 12L
  3002. // end_ntndis
  3003. //
  3004. // The highest user address reserves 64K bytes for a guard
  3005. // page. This allows the probing of address from kernel mode to
  3006. // only have to check the starting address for strucutures of 64k bytes
  3007. // or less.
  3008. //
  3009. #define MM_HIGHEST_USER_ADDRESS (PVOID)0x7FFEFFFF // temp should be 0xBFFEFFFF
  3010. #define MM_USER_PROBE_ADDRESS 0x7FFF0000 // starting address of guard page
  3011. //
  3012. // The lowest user address reserves the low 64k.
  3013. //
  3014. #define MM_LOWEST_USER_ADDRESS (PVOID)0x00010000
  3015. //
  3016. // The lowest address for system space.
  3017. //
  3018. #define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xC0800000
  3019. #define MmGetProcedureAddress(Address) (Address)
  3020. #define MmLockPagableCodeSection(Address) MmLockPagableDataSection(Address)
  3021. //
  3022. // Convert various portable ExInterlock apis into their architecural
  3023. // equivalents.
  3024. //
  3025. #define ExInterlockedAddUlong ExfInterlockedAddUlong
  3026. #define ExInterlockedInsertHeadList ExfInterlockedInsertHeadList
  3027. #define ExInterlockedInsertTailList ExfInterlockedInsertTailList
  3028. #define ExInterlockedRemoveHeadList ExfInterlockedRemoveHeadList
  3029. #define ExInterlockedPopEntryList ExfInterlockedPopEntryList
  3030. #define ExInterlockedPushEntryList ExfInterlockedPushEntryList
  3031. //
  3032. // Intrinsic interlocked functions
  3033. //
  3034. LONG
  3035. FASTCALL
  3036. InterlockedIncrement(
  3037. IN PLONG Addend
  3038. );
  3039. LONG
  3040. FASTCALL
  3041. InterlockedDecrement(
  3042. IN PLONG Addend
  3043. );
  3044. LONG
  3045. FASTCALL
  3046. InterlockedExchange(
  3047. IN OUT PLONG Target,
  3048. IN LONG Value
  3049. );
  3050. PVOID
  3051. FASTCALL
  3052. InterlockedCompareExchange(
  3053. IN OUT PVOID *Destination,
  3054. IN PVOID ExChange,
  3055. IN PVOID Comperand
  3056. );
  3057. #if !defined(MIDL_PASS) && defined(_M_IX86)
  3058. //
  3059. // i386 function definitions
  3060. //
  3061. #pragma warning(disable:4035) // re-enable below
  3062. #define _PCR fs:[0]
  3063. //
  3064. // Get current IRQL.
  3065. //
  3066. // On x86 this function resides in the HAL
  3067. //
  3068. KIRQL
  3069. KeGetCurrentIrql();
  3070. //
  3071. // Get the current processor number
  3072. //
  3073. __inline ULONG KeGetCurrentProcessorNumber(VOID)
  3074. {
  3075. __asm { movzx eax, _PCR KPCR.Number }
  3076. }
  3077. #endif // !defined(MIDL_PASS) && defined(_M_IX86)
  3078. #endif // defined(_X86_)
  3079. #if defined(_MIPS_)
  3080. //
  3081. // Define maximum size of flush multple TB request.
  3082. //
  3083. #define FLUSH_MULTIPLE_MAXIMUM 16
  3084. //
  3085. // Indicate that the MIPS compiler supports the pragma textout construct.
  3086. //
  3087. #define ALLOC_PRAGMA 1
  3088. //
  3089. // Define function decoration depending on whether a driver, a file system,
  3090. // or a kernel component is being built.
  3091. //
  3092. #define NTKERNELAPI DECLSPEC_IMPORT
  3093. //
  3094. // Define function decoration depending on whether the HAL or other kernel
  3095. // component is being build.
  3096. //
  3097. #if !defined(_NTHAL_) && !defined(_BLDR_)
  3098. #define NTHALAPI DECLSPEC_IMPORT
  3099. #else
  3100. #define NTHALAPI
  3101. #endif
  3102. // end_ntndis
  3103. //
  3104. // Define macro to generate import names.
  3105. //
  3106. #define IMPORT_NAME(name) __imp_##name
  3107. //
  3108. // Intrinsic interlocked functions.
  3109. //
  3110. #if defined(_M_MRX000) && !defined(RC_INVOKED)
  3111. #define InterlockedIncrement _InterlockedIncrement
  3112. #define InterlockedDecrement _InterlockedDecrement
  3113. #define InterlockedExchange _InterlockedExchange
  3114. #define InterlockedCompareExchange _InterlockedCompareExchange
  3115. LONG
  3116. InterlockedIncrement(
  3117. IN OUT PLONG Addend
  3118. );
  3119. LONG
  3120. InterlockedDecrement(
  3121. IN OUT PLONG Addend
  3122. );
  3123. LONG
  3124. InterlockedExchange(
  3125. IN OUT PLONG Target,
  3126. IN LONG Increment
  3127. );
  3128. NTKERNELAPI
  3129. LONG
  3130. InterlockedExchangeAdd(
  3131. IN OUT PLONG Addend,
  3132. IN LONG Value
  3133. );
  3134. NTKERNELAPI
  3135. PVOID
  3136. InterlockedCompareExchange (
  3137. IN OUT PVOID *Destination,
  3138. IN PVOID Exchange,
  3139. IN PVOID Comperand
  3140. );
  3141. #pragma intrinsic(_InterlockedIncrement)
  3142. #pragma intrinsic(_InterlockedDecrement)
  3143. #pragma intrinsic(_InterlockedExchange)
  3144. #pragma intrinsic(_InterlockedCompareExchange)
  3145. #endif
  3146. //
  3147. // MIPS Interrupt Definitions.
  3148. //
  3149. // Define length on interupt object dispatch code in longwords.
  3150. //
  3151. #define DISPATCH_LENGTH 4 // Length of dispatch code in instructions
  3152. //
  3153. // Define Interrupt Request Levels.
  3154. //
  3155. #define PASSIVE_LEVEL 0 // Passive release level
  3156. #define LOW_LEVEL 0 // Lowest interrupt level
  3157. #define APC_LEVEL 1 // APC interrupt level
  3158. #define DISPATCH_LEVEL 2 // Dispatcher level
  3159. #define IPI_LEVEL 7 // Interprocessor interrupt level
  3160. #define POWER_LEVEL 7 // Power failure level
  3161. #define PROFILE_LEVEL 8 // Profiling level
  3162. #define HIGH_LEVEL 8 // Highest interrupt level
  3163. #define SYNCH_LEVEL (IPI_LEVEL - 1) // synchronization level
  3164. //
  3165. // Define profile intervals.
  3166. //
  3167. #define DEFAULT_PROFILE_COUNT 0x40000000 // ~= 20 seconds @50mhz
  3168. #define DEFAULT_PROFILE_INTERVAL (10 * 500) // 500 microseconds
  3169. #define MAXIMUM_PROFILE_INTERVAL (10 * 1000 * 1000) // 1 second
  3170. #define MINIMUM_PROFILE_INTERVAL (10 * 40) // 40 microseconds
  3171. //
  3172. // Get current processor number.
  3173. //
  3174. #define KeGetCurrentProcessorNumber() PCR->Number
  3175. //
  3176. // Get data cache fill size.
  3177. //
  3178. #define KeGetDcacheFillSize() PCR->DcacheFillSize
  3179. //
  3180. // Cache and write buffer flush functions.
  3181. //
  3182. NTKERNELAPI
  3183. VOID
  3184. KeFlushIoBuffers (
  3185. IN PMDL Mdl,
  3186. IN BOOLEAN ReadOperation,
  3187. IN BOOLEAN DmaOperation
  3188. );
  3189. #define ExAcquireSpinLock(Lock, OldIrql) \
  3190. *(OldIrql) = KeAcquireSpinLockRaiseToDpc((Lock))
  3191. #define ExReleaseSpinLock(Lock, OldIrql) KeReleaseSpinLock((Lock), (OldIrql))
  3192. #define ExAcquireSpinLockAtDpcLevel(Lock) KeAcquireSpinLockAtDpcLevel(Lock)
  3193. #define ExReleaseSpinLockFromDpcLevel(Lock) KeReleaseSpinLockFromDpcLevel(Lock)
  3194. #define KeQueryTickCount(CurrentCount) { \
  3195. PKSYSTEM_TIME _TickCount = *((PKSYSTEM_TIME *)(&KeTickCount)); \
  3196. (CurrentCount)->QuadPart = _TickCount->Alignment; \
  3197. }
  3198. //
  3199. // I/O space read and write macros.
  3200. //
  3201. #define READ_REGISTER_UCHAR(x) \
  3202. *(volatile UCHAR * const)(x)
  3203. #define READ_REGISTER_USHORT(x) \
  3204. *(volatile USHORT * const)(x)
  3205. #define READ_REGISTER_ULONG(x) \
  3206. *(volatile ULONG * const)(x)
  3207. #define READ_REGISTER_BUFFER_UCHAR(x, y, z) { \
  3208. PUCHAR registerBuffer = x; \
  3209. PUCHAR readBuffer = y; \
  3210. ULONG readCount; \
  3211. for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
  3212. *readBuffer = *(volatile UCHAR * const)(registerBuffer); \
  3213. } \
  3214. }
  3215. #define READ_REGISTER_BUFFER_USHORT(x, y, z) { \
  3216. PUSHORT registerBuffer = x; \
  3217. PUSHORT readBuffer = y; \
  3218. ULONG readCount; \
  3219. for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
  3220. *readBuffer = *(volatile USHORT * const)(registerBuffer); \
  3221. } \
  3222. }
  3223. #define READ_REGISTER_BUFFER_ULONG(x, y, z) { \
  3224. PULONG registerBuffer = x; \
  3225. PULONG readBuffer = y; \
  3226. ULONG readCount; \
  3227. for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
  3228. *readBuffer = *(volatile ULONG * const)(registerBuffer); \
  3229. } \
  3230. }
  3231. #define WRITE_REGISTER_UCHAR(x, y) { \
  3232. *(volatile UCHAR * const)(x) = y; \
  3233. KeFlushWriteBuffer(); \
  3234. }
  3235. #define WRITE_REGISTER_USHORT(x, y) { \
  3236. *(volatile USHORT * const)(x) = y; \
  3237. KeFlushWriteBuffer(); \
  3238. }
  3239. #define WRITE_REGISTER_ULONG(x, y) { \
  3240. *(volatile ULONG * const)(x) = y; \
  3241. KeFlushWriteBuffer(); \
  3242. }
  3243. #define WRITE_REGISTER_BUFFER_UCHAR(x, y, z) { \
  3244. PUCHAR registerBuffer = x; \
  3245. PUCHAR writeBuffer = y; \
  3246. ULONG writeCount; \
  3247. for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
  3248. *(volatile UCHAR * const)(registerBuffer) = *writeBuffer; \
  3249. } \
  3250. KeFlushWriteBuffer(); \
  3251. }
  3252. #define WRITE_REGISTER_BUFFER_USHORT(x, y, z) { \
  3253. PUSHORT registerBuffer = x; \
  3254. PUSHORT writeBuffer = y; \
  3255. ULONG writeCount; \
  3256. for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
  3257. *(volatile USHORT * const)(registerBuffer) = *writeBuffer; \
  3258. } \
  3259. KeFlushWriteBuffer(); \
  3260. }
  3261. #define WRITE_REGISTER_BUFFER_ULONG(x, y, z) { \
  3262. PULONG registerBuffer = x; \
  3263. PULONG writeBuffer = y; \
  3264. ULONG writeCount; \
  3265. for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
  3266. *(volatile ULONG * const)(registerBuffer) = *writeBuffer; \
  3267. } \
  3268. KeFlushWriteBuffer(); \
  3269. }
  3270. #define READ_PORT_UCHAR(x) \
  3271. *(volatile UCHAR * const)(x)
  3272. #define READ_PORT_USHORT(x) \
  3273. *(volatile USHORT * const)(x)
  3274. #define READ_PORT_ULONG(x) \
  3275. *(volatile ULONG * const)(x)
  3276. #define READ_PORT_BUFFER_UCHAR(x, y, z) { \
  3277. PUCHAR readBuffer = y; \
  3278. ULONG readCount; \
  3279. for (readCount = 0; readCount < z; readCount++, readBuffer++) { \
  3280. *readBuffer = *(volatile UCHAR * const)(x); \
  3281. } \
  3282. }
  3283. #define READ_PORT_BUFFER_USHORT(x, y, z) { \
  3284. PUSHORT readBuffer = y; \
  3285. ULONG readCount; \
  3286. for (readCount = 0; readCount < z; readCount++, readBuffer++) { \
  3287. *readBuffer = *(volatile USHORT * const)(x); \
  3288. } \
  3289. }
  3290. #define READ_PORT_BUFFER_ULONG(x, y, z) { \
  3291. PULONG readBuffer = y; \
  3292. ULONG readCount; \
  3293. for (readCount = 0; readCount < z; readCount++, readBuffer++) { \
  3294. *readBuffer = *(volatile ULONG * const)(x); \
  3295. } \
  3296. }
  3297. #define WRITE_PORT_UCHAR(x, y) { \
  3298. *(volatile UCHAR * const)(x) = y; \
  3299. KeFlushWriteBuffer(); \
  3300. }
  3301. #define WRITE_PORT_USHORT(x, y) { \
  3302. *(volatile USHORT * const)(x) = y; \
  3303. KeFlushWriteBuffer(); \
  3304. }
  3305. #define WRITE_PORT_ULONG(x, y) { \
  3306. *(volatile ULONG * const)(x) = y; \
  3307. KeFlushWriteBuffer(); \
  3308. }
  3309. #define WRITE_PORT_BUFFER_UCHAR(x, y, z) { \
  3310. PUCHAR writeBuffer = y; \
  3311. ULONG writeCount; \
  3312. for (writeCount = 0; writeCount < z; writeCount++, writeBuffer++) { \
  3313. *(volatile UCHAR * const)(x) = *writeBuffer; \
  3314. KeFlushWriteBuffer(); \
  3315. } \
  3316. }
  3317. #define WRITE_PORT_BUFFER_USHORT(x, y, z) { \
  3318. PUSHORT writeBuffer = y; \
  3319. ULONG writeCount; \
  3320. for (writeCount = 0; writeCount < z; writeCount++, writeBuffer++) { \
  3321. *(volatile USHORT * const)(x) = *writeBuffer; \
  3322. KeFlushWriteBuffer(); \
  3323. } \
  3324. }
  3325. #define WRITE_PORT_BUFFER_ULONG(x, y, z) { \
  3326. PULONG writeBuffer = y; \
  3327. ULONG writeCount; \
  3328. for (writeCount = 0; writeCount < z; writeCount++, writeBuffer++) { \
  3329. *(volatile ULONG * const)(x) = *writeBuffer; \
  3330. KeFlushWriteBuffer(); \
  3331. } \
  3332. }
  3333. //
  3334. // Define the page size for the MIPS R4000 as 4096 (0x1000).
  3335. //
  3336. #define PAGE_SIZE (ULONG)0x1000
  3337. //
  3338. // Define the number of trailing zeroes in a page aligned virtual address.
  3339. // This is used as the shift count when shifting virtual addresses to
  3340. // virtual page numbers.
  3341. //
  3342. #define PAGE_SHIFT 12L
  3343. //
  3344. // The highest user address reserves 64K bytes for a guard page. This
  3345. // the probing of address from kernel mode to only have to check the
  3346. // starting address for structures of 64k bytes or less.
  3347. //
  3348. #define MM_HIGHEST_USER_ADDRESS (PVOID)0x7FFEFFFF // highest user address
  3349. #define MM_USER_PROBE_ADDRESS 0x7FFF0000 // starting address of guard page
  3350. //
  3351. // The lowest user address reserves the low 64k.
  3352. //
  3353. #define MM_LOWEST_USER_ADDRESS (PVOID)0x00010000
  3354. #define MmGetProcedureAddress(Address) (Address)
  3355. #define MmLockPagableCodeSection(Address) MmLockPagableDataSection(Address)
  3356. //
  3357. // The lowest address for system space.
  3358. //
  3359. #define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xC0800000
  3360. #define SYSTEM_BASE 0xc0800000 // start of system space (no typecast)
  3361. // begin_ntndis
  3362. #endif // defined(_MIPS_)
  3363. #if defined(_ALPHA_)
  3364. //
  3365. // Define maximum size of flush multple TB request.
  3366. //
  3367. #define FLUSH_MULTIPLE_MAXIMUM 16
  3368. //
  3369. // Indicate that the MIPS compiler supports the pragma textout construct.
  3370. //
  3371. #define ALLOC_PRAGMA 1
  3372. // end_ntndis
  3373. //
  3374. // Include the alpha instruction definitions
  3375. //
  3376. #include "alphaops.h"
  3377. //
  3378. // Include reference machine definitions.
  3379. //
  3380. #include "alpharef.h"
  3381. //
  3382. // Define function decoration depending on whether a driver, a file system,
  3383. // or a kernel component is being built.
  3384. //
  3385. #define NTKERNELAPI DECLSPEC_IMPORT
  3386. //
  3387. // Define function decoration depending on whether the HAL or other kernel
  3388. // component is being build.
  3389. //
  3390. #if !defined(_NTHAL_) && !defined(_BLDR_)
  3391. #define NTHALAPI DECLSPEC_IMPORT
  3392. #else
  3393. #define NTHALAPI
  3394. #endif
  3395. // end_ntndis
  3396. //
  3397. // Define macro to generate import names.
  3398. //
  3399. #define IMPORT_NAME(name) __imp_##name
  3400. //
  3401. // Define length of interrupt vector table.
  3402. //
  3403. #define MAXIMUM_VECTOR 256
  3404. //
  3405. // Define bus error routine type.
  3406. //
  3407. struct _EXCEPTION_RECORD;
  3408. struct _KEXCEPTION_FRAME;
  3409. struct _KTRAP_FRAME;
  3410. typedef
  3411. BOOLEAN
  3412. (*PKBUS_ERROR_ROUTINE) (
  3413. IN struct _EXCEPTION_RECORD *ExceptionRecord,
  3414. IN struct _KEXCEPTION_FRAME *ExceptionFrame,
  3415. IN struct _KTRAP_FRAME *TrapFrame
  3416. );
  3417. #define PCR_MINOR_VERSION 1
  3418. #define PCR_MAJOR_VERSION 1
  3419. typedef struct _KPCR {
  3420. //
  3421. // Major and minor version numbers of the PCR.
  3422. //
  3423. ULONG MinorVersion;
  3424. ULONG MajorVersion;
  3425. //
  3426. // Start of the architecturally defined section of the PCR. This section
  3427. // may be directly addressed by vendor/platform specific PAL/HAL code and will
  3428. // not change from version to version of NT.
  3429. //
  3430. // PALcode information.
  3431. //
  3432. ULONGLONG PalBaseAddress;
  3433. ULONG PalMajorVersion;
  3434. ULONG PalMinorVersion;
  3435. ULONG PalSequenceVersion;
  3436. ULONG PalMajorSpecification;
  3437. ULONG PalMinorSpecification;
  3438. //
  3439. // Firmware restart information.
  3440. //
  3441. ULONGLONG FirmwareRestartAddress;
  3442. PVOID RestartBlock;
  3443. //
  3444. // Reserved per-processor region for the PAL (3K bytes).
  3445. //
  3446. ULONGLONG PalReserved[384];
  3447. //
  3448. // Panic Stack Address.
  3449. //
  3450. ULONG PanicStack;
  3451. //
  3452. // Processor parameters.
  3453. //
  3454. ULONG ProcessorType;
  3455. ULONG ProcessorRevision;
  3456. ULONG PhysicalAddressBits;
  3457. ULONG MaximumAddressSpaceNumber;
  3458. ULONG PageSize;
  3459. ULONG FirstLevelDcacheSize;
  3460. ULONG FirstLevelDcacheFillSize;
  3461. ULONG FirstLevelIcacheSize;
  3462. ULONG FirstLevelIcacheFillSize;
  3463. //
  3464. // System Parameters.
  3465. //
  3466. ULONG FirmwareRevisionId;
  3467. UCHAR SystemType[8];
  3468. ULONG SystemVariant;
  3469. ULONG SystemRevision;
  3470. UCHAR SystemSerialNumber[16];
  3471. ULONG CycleClockPeriod;
  3472. ULONG SecondLevelCacheSize;
  3473. ULONG SecondLevelCacheFillSize;
  3474. ULONG ThirdLevelCacheSize;
  3475. ULONG ThirdLevelCacheFillSize;
  3476. ULONG FourthLevelCacheSize;
  3477. ULONG FourthLevelCacheFillSize;
  3478. //
  3479. // Pointer to processor control block.
  3480. //
  3481. struct _KPRCB *Prcb;
  3482. //
  3483. // Processor identification.
  3484. //
  3485. CCHAR Number;
  3486. KAFFINITY SetMember;
  3487. //
  3488. // Reserved per-processor region for the HAL (.5K bytes).
  3489. //
  3490. ULONGLONG HalReserved[64];
  3491. //
  3492. // IRQL mapping tables.
  3493. //
  3494. ULONG IrqlTable[8];
  3495. #define SFW_IMT_ENTRIES 4
  3496. #define HDW_IMT_ENTRIES 128
  3497. struct _IRQLMASK {
  3498. USHORT IrqlTableIndex; // synchronization irql level
  3499. USHORT IDTIndex; // vector in IDT
  3500. } IrqlMask[SFW_IMT_ENTRIES + HDW_IMT_ENTRIES];
  3501. //
  3502. // Interrupt Dispatch Table (IDT).
  3503. //
  3504. PKINTERRUPT_ROUTINE InterruptRoutine[MAXIMUM_VECTOR];
  3505. //
  3506. // Reserved vectors mask, these vectors cannot be attached to via
  3507. // standard interrupt objects.
  3508. //
  3509. ULONG ReservedVectors;
  3510. //
  3511. // Complement of processor affinity mask.
  3512. //
  3513. KAFFINITY NotMember;
  3514. ULONG InterruptInProgress;
  3515. ULONG DpcRequested;
  3516. //
  3517. // Pointer to machine check handler
  3518. //
  3519. PKBUS_ERROR_ROUTINE MachineCheckError;
  3520. //
  3521. // DPC Stack.
  3522. //
  3523. ULONG DpcStack;
  3524. //
  3525. // End of the architecturally defined section of the PCR. This section
  3526. // may be directly addressed by vendor/platform specific HAL code and will
  3527. // not change from version to version of NT. Some of these values are
  3528. // reserved for chip-specific palcode.
  3529. } KPCR, *PKPCR;
  3530. //
  3531. // length of dispatch code in interrupt template
  3532. //
  3533. #define DISPATCH_LENGTH 4
  3534. //
  3535. // Define IRQL levels across the architecture.
  3536. //
  3537. #define PASSIVE_LEVEL 0
  3538. #define LOW_LEVEL 0
  3539. #define APC_LEVEL 1
  3540. #define DISPATCH_LEVEL 2
  3541. #define HIGH_LEVEL 7
  3542. #define SYNCH_LEVEL (IPI_LEVEL-1)
  3543. //
  3544. // Processor Control Block (PRCB)
  3545. //
  3546. #define PRCB_MINOR_VERSION 1
  3547. #define PRCB_MAJOR_VERSION 2
  3548. #define PRCB_BUILD_DEBUG 0x0001
  3549. #define PRCB_BUILD_UNIPROCESSOR 0x0002
  3550. typedef struct _KPRCB {
  3551. //
  3552. // Major and minor version numbers of the PCR.
  3553. //
  3554. USHORT MinorVersion;
  3555. USHORT MajorVersion;
  3556. //
  3557. // Start of the architecturally defined section of the PRCB. This section
  3558. // may be directly addressed by vendor/platform specific HAL code and will
  3559. // not change from version to version of NT.
  3560. //
  3561. struct _KTHREAD *CurrentThread;
  3562. struct _KTHREAD *NextThread;
  3563. struct _KTHREAD *IdleThread;
  3564. CCHAR Number;
  3565. CCHAR Reserved;
  3566. USHORT BuildType;
  3567. KAFFINITY SetMember;
  3568. struct _RESTART_BLOCK *RestartBlock;
  3569. //
  3570. // End of the architecturally defined section of the PRCB. This section
  3571. // may be directly addressed by vendor/platform specific HAL code and will
  3572. // not change from version to version of NT.
  3573. //
  3574. } KPRCB, *PKPRCB, *RESTRICTED_POINTER PRKPRCB;
  3575. //
  3576. // I/O space read and write macros.
  3577. //
  3578. // These have to be actual functions on Alpha, because we need
  3579. // to shift the VA and OR in the BYTE ENABLES.
  3580. //
  3581. // These can become INLINEs if we require that ALL Alpha systems shift
  3582. // the same number of bits and have the SAME byte enables.
  3583. //
  3584. // The READ/WRITE_REGISTER_* calls manipulate I/O registers in MEMORY space?
  3585. //
  3586. // The READ/WRITE_PORT_* calls manipulate I/O registers in PORT space?
  3587. //
  3588. NTHALAPI
  3589. UCHAR
  3590. READ_REGISTER_UCHAR(
  3591. PUCHAR Register
  3592. );
  3593. NTHALAPI
  3594. USHORT
  3595. READ_REGISTER_USHORT(
  3596. PUSHORT Register
  3597. );
  3598. NTHALAPI
  3599. ULONG
  3600. READ_REGISTER_ULONG(
  3601. PULONG Register
  3602. );
  3603. NTHALAPI
  3604. VOID
  3605. READ_REGISTER_BUFFER_UCHAR(
  3606. PUCHAR Register,
  3607. PUCHAR Buffer,
  3608. ULONG Count
  3609. );
  3610. NTHALAPI
  3611. VOID
  3612. READ_REGISTER_BUFFER_USHORT(
  3613. PUSHORT Register,
  3614. PUSHORT Buffer,
  3615. ULONG Count
  3616. );
  3617. NTHALAPI
  3618. VOID
  3619. READ_REGISTER_BUFFER_ULONG(
  3620. PULONG Register,
  3621. PULONG Buffer,
  3622. ULONG Count
  3623. );
  3624. NTHALAPI
  3625. VOID
  3626. WRITE_REGISTER_UCHAR(
  3627. PUCHAR Register,
  3628. UCHAR Value
  3629. );
  3630. NTHALAPI
  3631. VOID
  3632. WRITE_REGISTER_USHORT(
  3633. PUSHORT Register,
  3634. USHORT Value
  3635. );
  3636. NTHALAPI
  3637. VOID
  3638. WRITE_REGISTER_ULONG(
  3639. PULONG Register,
  3640. ULONG Value
  3641. );
  3642. NTHALAPI
  3643. VOID
  3644. WRITE_REGISTER_BUFFER_UCHAR(
  3645. PUCHAR Register,
  3646. PUCHAR Buffer,
  3647. ULONG Count
  3648. );
  3649. NTHALAPI
  3650. VOID
  3651. WRITE_REGISTER_BUFFER_USHORT(
  3652. PUSHORT Register,
  3653. PUSHORT Buffer,
  3654. ULONG Count
  3655. );
  3656. NTHALAPI
  3657. VOID
  3658. WRITE_REGISTER_BUFFER_ULONG(
  3659. PULONG Register,
  3660. PULONG Buffer,
  3661. ULONG Count
  3662. );
  3663. NTHALAPI
  3664. UCHAR
  3665. READ_PORT_UCHAR(
  3666. PUCHAR Port
  3667. );
  3668. NTHALAPI
  3669. USHORT
  3670. READ_PORT_USHORT(
  3671. PUSHORT Port
  3672. );
  3673. NTHALAPI
  3674. ULONG
  3675. READ_PORT_ULONG(
  3676. PULONG Port
  3677. );
  3678. NTHALAPI
  3679. VOID
  3680. READ_PORT_BUFFER_UCHAR(
  3681. PUCHAR Port,
  3682. PUCHAR Buffer,
  3683. ULONG Count
  3684. );
  3685. NTHALAPI
  3686. VOID
  3687. READ_PORT_BUFFER_USHORT(
  3688. PUSHORT Port,
  3689. PUSHORT Buffer,
  3690. ULONG Count
  3691. );
  3692. NTHALAPI
  3693. VOID
  3694. READ_PORT_BUFFER_ULONG(
  3695. PULONG Port,
  3696. PULONG Buffer,
  3697. ULONG Count
  3698. );
  3699. NTHALAPI
  3700. VOID
  3701. WRITE_PORT_UCHAR(
  3702. PUCHAR Port,
  3703. UCHAR Value
  3704. );
  3705. NTHALAPI
  3706. VOID
  3707. WRITE_PORT_USHORT(
  3708. PUSHORT Port,
  3709. USHORT Value
  3710. );
  3711. NTHALAPI
  3712. VOID
  3713. WRITE_PORT_ULONG(
  3714. PULONG Port,
  3715. ULONG Value
  3716. );
  3717. NTHALAPI
  3718. VOID
  3719. WRITE_PORT_BUFFER_UCHAR(
  3720. PUCHAR Port,
  3721. PUCHAR Buffer,
  3722. ULONG Count
  3723. );
  3724. NTHALAPI
  3725. VOID
  3726. WRITE_PORT_BUFFER_USHORT(
  3727. PUSHORT Port,
  3728. PUSHORT Buffer,
  3729. ULONG Count
  3730. );
  3731. NTHALAPI
  3732. VOID
  3733. WRITE_PORT_BUFFER_ULONG(
  3734. PULONG Port,
  3735. PULONG Buffer,
  3736. ULONG Count
  3737. );
  3738. // end_ntndis
  3739. #if defined(_M_ALPHA) && !defined(RC_INVOKED)
  3740. #define InterlockedIncrement _InterlockedIncrement
  3741. #define InterlockedDecrement _InterlockedDecrement
  3742. #define InterlockedExchange _InterlockedExchange
  3743. #define InterlockedCompareExchange _InterlockedCompareExchange
  3744. LONG
  3745. InterlockedIncrement(
  3746. PLONG Addend
  3747. );
  3748. LONG
  3749. InterlockedDecrement(
  3750. PLONG Addend
  3751. );
  3752. LONG
  3753. InterlockedExchange(
  3754. PLONG Target,
  3755. LONG Value
  3756. );
  3757. PVOID
  3758. InterlockedCompareExchange (
  3759. IN OUT PVOID *Destination,
  3760. IN PVOID ExChange,
  3761. IN PVOID Comperand
  3762. );
  3763. #pragma intrinsic(_InterlockedIncrement)
  3764. #pragma intrinsic(_InterlockedDecrement)
  3765. #pragma intrinsic(_InterlockedExchange)
  3766. #pragma intrinsic(_InterlockedCompareExchange)
  3767. #endif
  3768. // there is a lot of other stuff that could go in here
  3769. // probe macros
  3770. // others
  3771. //
  3772. // Define the page size for the Alpha ev4 and lca as 8k.
  3773. //
  3774. #define PAGE_SIZE (ULONG)0x2000
  3775. //
  3776. // Define the number of trailing zeroes in a page aligned virtual address.
  3777. // This is used as the shift count when shifting virtual addresses to
  3778. // virtual page numbers.
  3779. //
  3780. #define PAGE_SHIFT 13L
  3781. //
  3782. // The highest user address reserves 64K bytes for a guard page. This
  3783. // the probing of address from kernel mode to only have to check the
  3784. // starting address for structures of 64k bytes or less.
  3785. //
  3786. #define MM_HIGHEST_USER_ADDRESS (PVOID)0x7FFEFFFF // highest user address
  3787. #define MM_USER_PROBE_ADDRESS 0x7FFF0000 // starting address of guard page
  3788. //
  3789. // The lowest user address reserves the low 64k.
  3790. //
  3791. #define MM_LOWEST_USER_ADDRESS (PVOID)0x00010000
  3792. #define MmGetProcedureAddress(Address) (Address)
  3793. #define MmLockPagableCodeSection(Address) MmLockPagableDataSection(Address)
  3794. //
  3795. // The lowest address for system space.
  3796. //
  3797. #define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xC0800000
  3798. //
  3799. // Get address of current PRCB.
  3800. //
  3801. #define KeGetCurrentPrcb() (PCR->Prcb)
  3802. //
  3803. // Get current processor number.
  3804. //
  3805. #define KeGetCurrentProcessorNumber() KeGetCurrentPrcb()->Number
  3806. //
  3807. // Cache and write buffer flush functions.
  3808. //
  3809. VOID
  3810. KeFlushIoBuffers (
  3811. IN PMDL Mdl,
  3812. IN BOOLEAN ReadOperation,
  3813. IN BOOLEAN DmaOperation
  3814. );
  3815. #define KeQueryTickCount(CurrentCount ) \
  3816. *(PULONGLONG)(CurrentCount) = **((volatile ULONGLONG **)(&KeTickCount));
  3817. #define ExAcquireSpinLock(Lock, OldIrql) KeAcquireSpinLock((Lock), (OldIrql))
  3818. #define ExReleaseSpinLock(Lock, OldIrql) KeReleaseSpinLock((Lock), (OldIrql))
  3819. #define ExAcquireSpinLockAtDpcLevel(Lock) KeAcquireSpinLockAtDpcLevel(Lock)
  3820. #define ExReleaseSpinLockFromDpcLevel(Lock) KeReleaseSpinLockFromDpcLevel(Lock)
  3821. #endif // _ALPHA_
  3822. #if defined(_PPC_)
  3823. //
  3824. // Define maximum size of flush multple TB request.
  3825. //
  3826. #define FLUSH_MULTIPLE_MAXIMUM 48
  3827. //
  3828. // Indicate that the compiler (with MIPS front-end) supports
  3829. // the pragma textout construct.
  3830. //
  3831. #define ALLOC_PRAGMA 1
  3832. //
  3833. // Define function decoration.
  3834. //
  3835. #define NTKERNELAPI DECLSPEC_IMPORT
  3836. //
  3837. // Define function decoration depending on whether the HAL or other kernel
  3838. // component is being build.
  3839. //
  3840. #if !defined(_NTHAL_)
  3841. #define NTHALAPI DECLSPEC_IMPORT
  3842. #else
  3843. #define NTHALAPI
  3844. #endif
  3845. // end_ntndis
  3846. //
  3847. // Define macro to generate import names.
  3848. //
  3849. #define IMPORT_NAME(name) __imp_##name
  3850. //
  3851. // Intrinsic interlocked functions
  3852. //
  3853. #if defined(_M_PPC) && defined(_MSC_VER) && (_MSC_VER>=1000) && !defined(RC_INVOKED)
  3854. #define InterlockedIncrement _InterlockedIncrement
  3855. #define InterlockedDecrement _InterlockedDecrement
  3856. #define InterlockedExchange _InterlockedExchange
  3857. #define InterlockedCompareExchange _InterlockedCompareExchange
  3858. LONG
  3859. InterlockedIncrement(
  3860. IN OUT PLONG Addend
  3861. );
  3862. LONG
  3863. InterlockedDecrement(
  3864. IN OUT PLONG Addend
  3865. );
  3866. LONG
  3867. InterlockedExchange(
  3868. IN OUT PLONG Target,
  3869. IN LONG Increment
  3870. );
  3871. PVOID
  3872. InterlockedCompareExchange (
  3873. IN OUT PVOID *Destination,
  3874. IN PVOID Exchange,
  3875. IN PVOID Comperand
  3876. );
  3877. #pragma intrinsic(_InterlockedIncrement)
  3878. #pragma intrinsic(_InterlockedDecrement)
  3879. #pragma intrinsic(_InterlockedExchange)
  3880. #pragma intrinsic(_InterlockedCompareExchange)
  3881. #else
  3882. NTKERNELAPI
  3883. LONG
  3884. InterlockedIncrement(
  3885. IN OUT PLONG Addend
  3886. );
  3887. NTKERNELAPI
  3888. LONG
  3889. InterlockedDecrement(
  3890. IN OUT PLONG Addend
  3891. );
  3892. NTKERNELAPI
  3893. LONG
  3894. InterlockedExchange(
  3895. IN OUT PLONG Target,
  3896. IN LONG Increment
  3897. );
  3898. NTKERNELAPI
  3899. PVOID
  3900. InterlockedCompareExchange (
  3901. IN OUT PVOID *Destination,
  3902. IN PVOID Exchange,
  3903. IN PVOID Comperand
  3904. );
  3905. #endif
  3906. //
  3907. // PowerPC Interrupt Definitions.
  3908. //
  3909. // Define length of interupt object dispatch code in 32-bit words.
  3910. //
  3911. #define DISPATCH_LENGTH 4 // Length of dispatch code in instructions
  3912. //
  3913. // Define Interrupt Request Levels.
  3914. //
  3915. #define PASSIVE_LEVEL 0 // Passive release level
  3916. #define LOW_LEVEL 0 // Lowest interrupt level
  3917. #define APC_LEVEL 1 // APC interrupt level
  3918. #define DISPATCH_LEVEL 2 // Dispatcher level
  3919. #define PROFILE_LEVEL 27 // Profiling level
  3920. #define IPI_LEVEL 29 // Interprocessor interrupt level
  3921. #define POWER_LEVEL 30 // Power failure level
  3922. #define FLOAT_LEVEL 31 // Floating interrupt level
  3923. #define HIGH_LEVEL 31 // Highest interrupt level
  3924. #define SYNCH_LEVEL DISPATCH_LEVEL // Synchronization level
  3925. //
  3926. // Define profile intervals.
  3927. //
  3928. // **FINISH** These are the MIPS R4000 values; investigate for PPC
  3929. #define DEFAULT_PROFILE_COUNT 0x40000000 // ~= 20 seconds @50mhz
  3930. #define DEFAULT_PROFILE_INTERVAL (10 * 500) // 500 microseconds
  3931. #define MAXIMUM_PROFILE_INTERVAL (10 * 1000 * 1000) // 1 second
  3932. #define MINIMUM_PROFILE_INTERVAL (10 * 40) // 40 microseconds
  3933. //
  3934. // Define length of interrupt vector table.
  3935. //
  3936. #define MAXIMUM_VECTOR 256
  3937. //
  3938. // Processor Control Region
  3939. //
  3940. // On PowerPC, this cannot be at a fixed virtual address;
  3941. // it must be at a different address on each processor of an MP.
  3942. //
  3943. #define PCR_MINOR_VERSION 1
  3944. #define PCR_MAJOR_VERSION 1
  3945. typedef struct _KPCR {
  3946. //
  3947. // Major and minor version numbers of the PCR.
  3948. //
  3949. USHORT MinorVersion;
  3950. USHORT MajorVersion;
  3951. //
  3952. // Start of the architecturally defined section of the PCR. This section
  3953. // may be directly addressed by vendor/platform specific HAL code and will
  3954. // not change from version to version of NT.
  3955. //
  3956. // Interrupt and error exception vectors.
  3957. //
  3958. PKINTERRUPT_ROUTINE InterruptRoutine[MAXIMUM_VECTOR];
  3959. ULONG PcrPage2;
  3960. ULONG Kseg0Top;
  3961. ULONG Spare7[30];
  3962. //
  3963. // First and second level cache parameters.
  3964. //
  3965. ULONG FirstLevelDcacheSize;
  3966. ULONG FirstLevelDcacheFillSize;
  3967. ULONG FirstLevelIcacheSize;
  3968. ULONG FirstLevelIcacheFillSize;
  3969. ULONG SecondLevelDcacheSize;
  3970. ULONG SecondLevelDcacheFillSize;
  3971. ULONG SecondLevelIcacheSize;
  3972. ULONG SecondLevelIcacheFillSize;
  3973. //
  3974. // Pointer to processor control block.
  3975. //
  3976. struct _KPRCB *Prcb;
  3977. //
  3978. // Pointer to the thread environment block. A fast-path system call
  3979. // is provided that will return this value to user-mode code.
  3980. //
  3981. PVOID Teb;
  3982. //
  3983. // Data cache alignment and fill size used for cache flushing and alignment.
  3984. // These fields are set to the larger of the first and second level data
  3985. // cache fill sizes.
  3986. //
  3987. ULONG DcacheAlignment;
  3988. ULONG DcacheFillSize;
  3989. //
  3990. // Instruction cache alignment and fill size used for cache flushing and
  3991. // alignment. These fields are set to the larger of the first and second
  3992. // level data cache fill sizes.
  3993. //
  3994. ULONG IcacheAlignment;
  3995. ULONG IcacheFillSize;
  3996. //
  3997. // Processor identification information from PVR.
  3998. //
  3999. ULONG ProcessorVersion;
  4000. ULONG ProcessorRevision;
  4001. //
  4002. // Profiling data.
  4003. //
  4004. ULONG ProfileInterval;
  4005. ULONG ProfileCount;
  4006. //
  4007. // Stall execution count and scale factor.
  4008. //
  4009. ULONG StallExecutionCount;
  4010. ULONG StallScaleFactor;
  4011. //
  4012. // Spare cell.
  4013. //
  4014. ULONG Spare;
  4015. //
  4016. // Cache policy, right justified, as read from the processor configuration
  4017. // register at startup.
  4018. //
  4019. union {
  4020. ULONG CachePolicy;
  4021. struct {
  4022. UCHAR IcacheMode; // Dynamic cache mode for PPC
  4023. UCHAR DcacheMode; // Dynamic cache mode for PPC
  4024. USHORT ModeSpare;
  4025. };
  4026. };
  4027. //
  4028. // IRQL mapping tables.
  4029. //
  4030. UCHAR IrqlMask[32];
  4031. UCHAR IrqlTable[9];
  4032. //
  4033. // Current IRQL.
  4034. //
  4035. UCHAR CurrentIrql;
  4036. //
  4037. // Processor identification
  4038. //
  4039. CCHAR Number;
  4040. KAFFINITY SetMember;
  4041. //
  4042. // Reserved interrupt vector mask.
  4043. //
  4044. ULONG ReservedVectors;
  4045. //
  4046. // Current state parameters.
  4047. //
  4048. struct _KTHREAD *CurrentThread;
  4049. //
  4050. // Cache policy, PTE field aligned, as read from the processor configuration
  4051. // register at startup.
  4052. //
  4053. ULONG AlignedCachePolicy;
  4054. //
  4055. // Flag for determining pending software interrupts
  4056. //
  4057. union {
  4058. ULONG SoftwareInterrupt; // any bit 1 => some s/w interrupt pending
  4059. struct {
  4060. UCHAR ApcInterrupt; // 0x01 if APC int pending
  4061. UCHAR DispatchInterrupt; // 0x01 if dispatch int pending
  4062. UCHAR Spare4;
  4063. UCHAR Spare5;
  4064. };
  4065. };
  4066. //
  4067. // Complement of the processor affinity mask.
  4068. //
  4069. KAFFINITY NotMember;
  4070. //
  4071. // Space reserved for the system.
  4072. //
  4073. ULONG SystemReserved[16];
  4074. //
  4075. // Space reserved for the HAL
  4076. //
  4077. ULONG HalReserved[16];
  4078. //
  4079. // End of the architecturally defined section of the PCR. This section
  4080. // may be directly addressed by vendor/platform specific HAL code and will
  4081. // not change from version to version of NT.
  4082. //
  4083. } KPCR, *PKPCR;
  4084. #define KIPCR 0xffffd000 // kernel address of first PCR
  4085. #define PCR ((volatile KPCR * const)KIPCR)
  4086. #if defined(_M_PPC) && defined(_MSC_VER) && (_MSC_VER>=1000)
  4087. unsigned __sregister_get( unsigned const regnum );
  4088. #define _PPC_SPRG1_ 273
  4089. #define PCRsprg1 ((volatile KPCR * volatile)__sregister_get(_PPC_SPRG1_))
  4090. #else
  4091. KPCR * __builtin_get_sprg1(VOID);
  4092. #define PCRsprg1 ((volatile KPCR * volatile)__builtin_get_sprg1())
  4093. #endif
  4094. //
  4095. // Macros for enabling and disabling system interrupts.
  4096. //
  4097. //BUGBUG - work around 603e/ev errata #15
  4098. // The instructions __emit'ed in these macros are "cror 0,0,0" instructions
  4099. // that force the mtmsr to complete before allowing any subsequent loads to
  4100. // issue. The condition register no-op is executed in the system unit on
  4101. // the 603. This will not dispatch until the mtmsr completes and will halt
  4102. // further dispatch. On a 601 or 604 this instruction executes in the
  4103. // branch unit and will run in parallel (i.e., no performance penalty except
  4104. // for code bloat).
  4105. //
  4106. #if defined(_M_PPC) && defined(_MSC_VER) && (_MSC_VER>=1000)
  4107. unsigned __sregister_get( unsigned const regnum );
  4108. void __sregister_set( unsigned const regnum, unsigned value );
  4109. #define _PPC_MSR_ (unsigned)(~0x0)
  4110. #define _enable() (__sregister_set(_PPC_MSR_, __sregister_get(_PPC_MSR_) | 0x00008000), __emit(0x4C000382))
  4111. #define _disable() (__sregister_set(_PPC_MSR_, __sregister_get(_PPC_MSR_) & 0xffff7fff), __emit(0x4C000382))
  4112. #define __builtin_get_msr() __sregister_get(_PPC_MSR_)
  4113. #else
  4114. ULONG __builtin_get_msr(VOID);
  4115. VOID __builtin_set_msr(ULONG);
  4116. #define _enable() (__builtin_set_msr(__builtin_get_msr() | 0x00008000), __builtin_isync())
  4117. #define _disable() (__builtin_set_msr(__builtin_get_msr() & 0xffff7fff), __builtin_isync())
  4118. #endif
  4119. //
  4120. // Get current IRQL.
  4121. //
  4122. #define KeGetCurrentIrql() PCR->CurrentIrql
  4123. //
  4124. // Get address of current processor block.
  4125. //
  4126. #define KeGetCurrentPrcb() PCR->Prcb
  4127. //
  4128. // Get address of processor control region.
  4129. //
  4130. #define KeGetPcr() PCR
  4131. //
  4132. // Get address of current kernel thread object.
  4133. //
  4134. #define KeGetCurrentThread() PCR->CurrentThread
  4135. //
  4136. // Get Processor Version Register
  4137. //
  4138. #if defined(_M_PPC) && defined(_MSC_VER) && (_MSC_VER>=1000)
  4139. unsigned __sregister_get( unsigned const regnum );
  4140. #define _PPC_PVR_ 287
  4141. #define KeGetPvr() __sregister_get(_PPC_PVR_)
  4142. #else
  4143. ULONG __builtin_get_pvr(VOID);
  4144. #define KeGetPvr() __builtin_get_pvr()
  4145. #endif
  4146. // begin_ntddk
  4147. //
  4148. // Get current processor number.
  4149. //
  4150. #define KeGetCurrentProcessorNumber() PCR->Number
  4151. //
  4152. // Get data cache fill size.
  4153. //
  4154. // **FINISH** See that proper PowerPC parameter is accessed here
  4155. #define KeGetDcacheFillSize() PCR->DcacheFillSize
  4156. //
  4157. // Cache and write buffer flush functions.
  4158. //
  4159. NTKERNELAPI
  4160. VOID
  4161. KeFlushIoBuffers (
  4162. IN PMDL Mdl,
  4163. IN BOOLEAN ReadOperation,
  4164. IN BOOLEAN DmaOperation
  4165. );
  4166. // end_nthal
  4167. #define ExAcquireSpinLock(Lock, OldIrql) KeAcquireSpinLock((Lock), (OldIrql))
  4168. #define ExReleaseSpinLock(Lock, OldIrql) KeReleaseSpinLock((Lock), (OldIrql))
  4169. #define ExAcquireSpinLockAtDpcLevel(Lock) KeAcquireSpinLockAtDpcLevel(Lock)
  4170. #define ExReleaseSpinLockFromDpcLevel(Lock) KeReleaseSpinLockFromDpcLevel(Lock)
  4171. #define KeQueryTickCount(CurrentCount) { \
  4172. PKSYSTEM_TIME _TickCount = *((PKSYSTEM_TIME *)(&KeTickCount)); \
  4173. do { \
  4174. (CurrentCount)->HighPart = _TickCount->High1Time; \
  4175. (CurrentCount)->LowPart = _TickCount->LowPart; \
  4176. } while ((CurrentCount)->HighPart != _TickCount->High2Time); \
  4177. }
  4178. //
  4179. // I/O space read and write macros.
  4180. //
  4181. // **FINISH** Ensure that these are appropriate for PowerPC
  4182. #define READ_REGISTER_UCHAR(x) \
  4183. *(volatile UCHAR * const)(x)
  4184. #define READ_REGISTER_USHORT(x) \
  4185. *(volatile USHORT * const)(x)
  4186. #define READ_REGISTER_ULONG(x) \
  4187. *(volatile ULONG * const)(x)
  4188. #define READ_REGISTER_BUFFER_UCHAR(x, y, z) { \
  4189. PUCHAR registerBuffer = x; \
  4190. PUCHAR readBuffer = y; \
  4191. ULONG readCount; \
  4192. for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
  4193. *readBuffer = *(volatile UCHAR * const)(registerBuffer); \
  4194. } \
  4195. }
  4196. #define READ_REGISTER_BUFFER_USHORT(x, y, z) { \
  4197. PUSHORT registerBuffer = x; \
  4198. PUSHORT readBuffer = y; \
  4199. ULONG readCount; \
  4200. for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
  4201. *readBuffer = *(volatile USHORT * const)(registerBuffer); \
  4202. } \
  4203. }
  4204. #define READ_REGISTER_BUFFER_ULONG(x, y, z) { \
  4205. PULONG registerBuffer = x; \
  4206. PULONG readBuffer = y; \
  4207. ULONG readCount; \
  4208. for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
  4209. *readBuffer = *(volatile ULONG * const)(registerBuffer); \
  4210. } \
  4211. }
  4212. #define WRITE_REGISTER_UCHAR(x, y) { \
  4213. *(volatile UCHAR * const)(x) = y; \
  4214. KeFlushWriteBuffer(); \
  4215. }
  4216. #define WRITE_REGISTER_USHORT(x, y) { \
  4217. *(volatile USHORT * const)(x) = y; \
  4218. KeFlushWriteBuffer(); \
  4219. }
  4220. #define WRITE_REGISTER_ULONG(x, y) { \
  4221. *(volatile ULONG * const)(x) = y; \
  4222. KeFlushWriteBuffer(); \
  4223. }
  4224. #define WRITE_REGISTER_BUFFER_UCHAR(x, y, z) { \
  4225. PUCHAR registerBuffer = x; \
  4226. PUCHAR writeBuffer = y; \
  4227. ULONG writeCount; \
  4228. for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
  4229. *(volatile UCHAR * const)(registerBuffer) = *writeBuffer; \
  4230. } \
  4231. KeFlushWriteBuffer(); \
  4232. }
  4233. #define WRITE_REGISTER_BUFFER_USHORT(x, y, z) { \
  4234. PUSHORT registerBuffer = x; \
  4235. PUSHORT writeBuffer = y; \
  4236. ULONG writeCount; \
  4237. for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
  4238. *(volatile USHORT * const)(registerBuffer) = *writeBuffer; \
  4239. } \
  4240. KeFlushWriteBuffer(); \
  4241. }
  4242. #define WRITE_REGISTER_BUFFER_ULONG(x, y, z) { \
  4243. PULONG registerBuffer = x; \
  4244. PULONG writeBuffer = y; \
  4245. ULONG writeCount; \
  4246. for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
  4247. *(volatile ULONG * const)(registerBuffer) = *writeBuffer; \
  4248. } \
  4249. KeFlushWriteBuffer(); \
  4250. }
  4251. #define READ_PORT_UCHAR(x) \
  4252. *(volatile UCHAR * const)(x)
  4253. #define READ_PORT_USHORT(x) \
  4254. *(volatile USHORT * const)(x)
  4255. #define READ_PORT_ULONG(x) \
  4256. *(volatile ULONG * const)(x)
  4257. #define READ_PORT_BUFFER_UCHAR(x, y, z) { \
  4258. PUCHAR readBuffer = y; \
  4259. ULONG readCount; \
  4260. for (readCount = 0; readCount < z; readCount++, readBuffer++) { \
  4261. *readBuffer = *(volatile UCHAR * const)(x); \
  4262. } \
  4263. }
  4264. #define READ_PORT_BUFFER_USHORT(x, y, z) { \
  4265. PUSHORT readBuffer = y; \
  4266. ULONG readCount; \
  4267. for (readCount = 0; readCount < z; readCount++, readBuffer++) { \
  4268. *readBuffer = *(volatile USHORT * const)(x); \
  4269. } \
  4270. }
  4271. #define READ_PORT_BUFFER_ULONG(x, y, z) { \
  4272. PULONG readBuffer = y; \
  4273. ULONG readCount; \
  4274. for (readCount = 0; readCount < z; readCount++, readBuffer++) { \
  4275. *readBuffer = *(volatile ULONG * const)(x); \
  4276. } \
  4277. }
  4278. #define WRITE_PORT_UCHAR(x, y) { \
  4279. *(volatile UCHAR * const)(x) = y; \
  4280. KeFlushWriteBuffer(); \
  4281. }
  4282. #define WRITE_PORT_USHORT(x, y) { \
  4283. *(volatile USHORT * const)(x) = y; \
  4284. KeFlushWriteBuffer(); \
  4285. }
  4286. #define WRITE_PORT_ULONG(x, y) { \
  4287. *(volatile ULONG * const)(x) = y; \
  4288. KeFlushWriteBuffer(); \
  4289. }
  4290. #define WRITE_PORT_BUFFER_UCHAR(x, y, z) { \
  4291. PUCHAR writeBuffer = y; \
  4292. ULONG writeCount; \
  4293. for (writeCount = 0; writeCount < z; writeCount++, writeBuffer++) { \
  4294. *(volatile UCHAR * const)(x) = *writeBuffer; \
  4295. KeFlushWriteBuffer(); \
  4296. } \
  4297. }
  4298. #define WRITE_PORT_BUFFER_USHORT(x, y, z) { \
  4299. PUSHORT writeBuffer = y; \
  4300. ULONG writeCount; \
  4301. for (writeCount = 0; writeCount < z; writeCount++, writeBuffer++) { \
  4302. *(volatile USHORT * const)(x) = *writeBuffer; \
  4303. KeFlushWriteBuffer(); \
  4304. } \
  4305. }
  4306. #define WRITE_PORT_BUFFER_ULONG(x, y, z) { \
  4307. PULONG writeBuffer = y; \
  4308. ULONG writeCount; \
  4309. for (writeCount = 0; writeCount < z; writeCount++, writeBuffer++) { \
  4310. *(volatile ULONG * const)(x) = *writeBuffer; \
  4311. KeFlushWriteBuffer(); \
  4312. } \
  4313. }
  4314. //
  4315. // PowerPC page size = 4 KB
  4316. //
  4317. #define PAGE_SIZE (ULONG)0x1000
  4318. //
  4319. // Define the number of trailing zeroes in a page aligned virtual address.
  4320. // This is used as the shift count when shifting virtual addresses to
  4321. // virtual page numbers.
  4322. //
  4323. #define PAGE_SHIFT 12L
  4324. //
  4325. // The highest user address reserves 64K bytes for a guard page. This
  4326. // the probing of address from kernel mode to only have to check the
  4327. // starting address for structures of 64k bytes or less.
  4328. //
  4329. #define MM_HIGHEST_USER_ADDRESS (PVOID)0x7FFEFFFF // highest user address
  4330. #define MM_USER_PROBE_ADDRESS 0x7FFF0000 // starting address of guard page
  4331. //
  4332. // The lowest user address reserves the low 64k.
  4333. //
  4334. #define MM_LOWEST_USER_ADDRESS (PVOID)0x00010000
  4335. #define MmGetProcedureAddress(Address) *((PVOID *)(Address))
  4336. #define MmLockPagableCodeSection(Address) MmLockPagableDataSection(*((PVOID *)(Address)))
  4337. //
  4338. // The lowest address for system space.
  4339. //
  4340. #define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0x80000000
  4341. #define SYSTEM_BASE 0x80000000 // start of system space (no typecast)
  4342. // begin_ntndis
  4343. #endif // defined(_PPC_)
  4344. #if defined(_X86_)
  4345. //
  4346. // Define system time structure.
  4347. //
  4348. typedef struct _KSYSTEM_TIME {
  4349. ULONG LowPart;
  4350. LONG High1Time;
  4351. LONG High2Time;
  4352. } KSYSTEM_TIME, *PKSYSTEM_TIME;
  4353. #endif
  4354. #ifdef _X86_
  4355. //
  4356. // Disable these two pramas that evaluate to "sti" "cli" on x86 so that driver
  4357. // writers to not leave them inadvertantly in their code.
  4358. //
  4359. #if !defined(MIDL_PASS)
  4360. #if !defined(RC_INVOKED)
  4361. #pragma warning(disable:4164) // disable C4164 warning so that apps that
  4362. // build with /Od don't get weird errors !
  4363. #ifdef _M_IX86
  4364. #pragma function(_enable)
  4365. #pragma function(_disable)
  4366. #endif
  4367. #pragma warning(default:4164) // reenable C4164 warning
  4368. #endif
  4369. #endif
  4370. //
  4371. // Size of kernel mode stack.
  4372. //
  4373. #define KERNEL_STACK_SIZE 12288
  4374. //
  4375. // Define size of large kernel mode stack for callbacks.
  4376. //
  4377. #define KERNEL_LARGE_STACK_SIZE 61440
  4378. //
  4379. // Define number of pages to initialize in a large kernel stack.
  4380. //
  4381. #define KERNEL_LARGE_STACK_COMMIT 12288
  4382. #ifdef _X86_
  4383. // begin_winnt
  4384. #if !defined(MIDL_PASS) && defined(_M_IX86)
  4385. #pragma warning (disable:4035) // disable 4035 (function must return something)
  4386. _inline PVOID GetFiberData( void ) { __asm {
  4387. mov eax, fs:[0x10]
  4388. mov eax,[eax]
  4389. }
  4390. }
  4391. _inline PVOID GetCurrentFiber( void ) { __asm mov eax, fs:[0x10] }
  4392. #pragma warning (default:4035) // Reenable it
  4393. #endif
  4394. // begin_wx86
  4395. //
  4396. // Define the size of the 80387 save area, which is in the context frame.
  4397. //
  4398. #define SIZE_OF_80387_REGISTERS 80
  4399. //
  4400. // The following flags control the contents of the CONTEXT structure.
  4401. //
  4402. #if !defined(RC_INVOKED)
  4403. #define CONTEXT_i386 0x00010000 // this assumes that i386 and
  4404. #define CONTEXT_i486 0x00010000 // i486 have identical context records
  4405. // end_wx86
  4406. #define CONTEXT_CONTROL (CONTEXT_i386 | 0x00000001L) // SS:SP, CS:IP, FLAGS, BP
  4407. #define CONTEXT_INTEGER (CONTEXT_i386 | 0x00000002L) // AX, BX, CX, DX, SI, DI
  4408. #define CONTEXT_SEGMENTS (CONTEXT_i386 | 0x00000004L) // DS, ES, FS, GS
  4409. #define CONTEXT_FLOATING_POINT (CONTEXT_i386 | 0x00000008L) // 387 state
  4410. #define CONTEXT_DEBUG_REGISTERS (CONTEXT_i386 | 0x00000010L) // DB 0-3,6,7
  4411. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER |\
  4412. CONTEXT_SEGMENTS)
  4413. // begin_wx86
  4414. #endif
  4415. typedef struct _FLOATING_SAVE_AREA {
  4416. ULONG ControlWord;
  4417. ULONG StatusWord;
  4418. ULONG TagWord;
  4419. ULONG ErrorOffset;
  4420. ULONG ErrorSelector;
  4421. ULONG DataOffset;
  4422. ULONG DataSelector;
  4423. UCHAR RegisterArea[SIZE_OF_80387_REGISTERS];
  4424. ULONG Cr0NpxState;
  4425. } FLOATING_SAVE_AREA;
  4426. typedef FLOATING_SAVE_AREA *PFLOATING_SAVE_AREA;
  4427. //
  4428. // Context Frame
  4429. //
  4430. // This frame has a several purposes: 1) it is used as an argument to
  4431. // NtContinue, 2) is is used to constuct a call frame for APC delivery,
  4432. // and 3) it is used in the user level thread creation routines.
  4433. //
  4434. // The layout of the record conforms to a standard call frame.
  4435. //
  4436. typedef struct _CONTEXT {
  4437. //
  4438. // The flags values within this flag control the contents of
  4439. // a CONTEXT record.
  4440. //
  4441. // If the context record is used as an input parameter, then
  4442. // for each portion of the context record controlled by a flag
  4443. // whose value is set, it is assumed that that portion of the
  4444. // context record contains valid context. If the context record
  4445. // is being used to modify a threads context, then only that
  4446. // portion of the threads context will be modified.
  4447. //
  4448. // If the context record is used as an IN OUT parameter to capture
  4449. // the context of a thread, then only those portions of the thread's
  4450. // context corresponding to set flags will be returned.
  4451. //
  4452. // The context record is never used as an OUT only parameter.
  4453. //
  4454. ULONG ContextFlags;
  4455. //
  4456. // This section is specified/returned if CONTEXT_DEBUG_REGISTERS is
  4457. // set in ContextFlags. Note that CONTEXT_DEBUG_REGISTERS is NOT
  4458. // included in CONTEXT_FULL.
  4459. //
  4460. ULONG Dr0;
  4461. ULONG Dr1;
  4462. ULONG Dr2;
  4463. ULONG Dr3;
  4464. ULONG Dr6;
  4465. ULONG Dr7;
  4466. //
  4467. // This section is specified/returned if the
  4468. // ContextFlags word contians the flag CONTEXT_FLOATING_POINT.
  4469. //
  4470. FLOATING_SAVE_AREA FloatSave;
  4471. //
  4472. // This section is specified/returned if the
  4473. // ContextFlags word contians the flag CONTEXT_SEGMENTS.
  4474. //
  4475. ULONG SegGs;
  4476. ULONG SegFs;
  4477. ULONG SegEs;
  4478. ULONG SegDs;
  4479. //
  4480. // This section is specified/returned if the
  4481. // ContextFlags word contians the flag CONTEXT_INTEGER.
  4482. //
  4483. ULONG Edi;
  4484. ULONG Esi;
  4485. ULONG Ebx;
  4486. ULONG Edx;
  4487. ULONG Ecx;
  4488. ULONG Eax;
  4489. //
  4490. // This section is specified/returned if the
  4491. // ContextFlags word contians the flag CONTEXT_CONTROL.
  4492. //
  4493. ULONG Ebp;
  4494. ULONG Eip;
  4495. ULONG SegCs; // MUST BE SANITIZED
  4496. ULONG EFlags; // MUST BE SANITIZED
  4497. ULONG Esp;
  4498. ULONG SegSs;
  4499. } CONTEXT;
  4500. typedef CONTEXT *PCONTEXT;
  4501. // begin_ntminiport
  4502. #endif //_X86_
  4503. #endif // _X86_
  4504. #if defined(_MIPS_)
  4505. //
  4506. // Define system time structure.
  4507. //
  4508. typedef union _KSYSTEM_TIME {
  4509. struct {
  4510. ULONG LowPart;
  4511. LONG High1Time;
  4512. LONG High2Time;
  4513. };
  4514. ULONGLONG Alignment;
  4515. } KSYSTEM_TIME, *PKSYSTEM_TIME;
  4516. //
  4517. // Define unsupported "keywords".
  4518. //
  4519. #define _cdecl
  4520. // begin_windbgkd
  4521. #if defined(_MIPS_)
  4522. #endif
  4523. //
  4524. // Define size of kernel mode stack.
  4525. //
  4526. #define KERNEL_STACK_SIZE 12288
  4527. //
  4528. // Define size of large kernel mode stack for callbacks.
  4529. //
  4530. #define KERNEL_LARGE_STACK_SIZE 61440
  4531. //
  4532. // Define number of pages to initialize in a large kernel stack.
  4533. //
  4534. #define KERNEL_LARGE_STACK_COMMIT 12288
  4535. //
  4536. // Define length of exception code dispatch vector.
  4537. //
  4538. #define XCODE_VECTOR_LENGTH 32
  4539. //
  4540. // Define length of interrupt vector table.
  4541. //
  4542. #define MAXIMUM_VECTOR 256
  4543. //
  4544. // Define bus error routine type.
  4545. //
  4546. struct _EXCEPTION_RECORD;
  4547. struct _KEXCEPTION_FRAME;
  4548. struct _KTRAP_FRAME;
  4549. typedef
  4550. BOOLEAN
  4551. (*PKBUS_ERROR_ROUTINE) (
  4552. IN struct _EXCEPTION_RECORD *ExceptionRecord,
  4553. IN struct _KEXCEPTION_FRAME *ExceptionFrame,
  4554. IN struct _KTRAP_FRAME *TrapFrame,
  4555. IN PVOID VirtualAddress,
  4556. IN PHYSICAL_ADDRESS PhysicalAddress
  4557. );
  4558. //
  4559. // Define Processor Control Region Structure.
  4560. //
  4561. #define PCR_MINOR_VERSION 1
  4562. #define PCR_MAJOR_VERSION 1
  4563. typedef struct _KPCR {
  4564. //
  4565. // Major and minor version numbers of the PCR.
  4566. //
  4567. USHORT MinorVersion;
  4568. USHORT MajorVersion;
  4569. //
  4570. // Start of the architecturally defined section of the PCR. This section
  4571. // may be directly addressed by vendor/platform specific HAL code and will
  4572. // not change from version to version of NT.
  4573. //
  4574. // Interrupt and error exception vectors.
  4575. //
  4576. PKINTERRUPT_ROUTINE InterruptRoutine[MAXIMUM_VECTOR];
  4577. PVOID XcodeDispatch[XCODE_VECTOR_LENGTH];
  4578. //
  4579. // First and second level cache parameters.
  4580. //
  4581. ULONG FirstLevelDcacheSize;
  4582. ULONG FirstLevelDcacheFillSize;
  4583. ULONG FirstLevelIcacheSize;
  4584. ULONG FirstLevelIcacheFillSize;
  4585. ULONG SecondLevelDcacheSize;
  4586. ULONG SecondLevelDcacheFillSize;
  4587. ULONG SecondLevelIcacheSize;
  4588. ULONG SecondLevelIcacheFillSize;
  4589. //
  4590. // Pointer to processor control block.
  4591. //
  4592. struct _KPRCB *Prcb;
  4593. //
  4594. // Pointer to the thread environment block and the address of the TLS array.
  4595. //
  4596. PVOID Teb;
  4597. PVOID TlsArray;
  4598. //
  4599. // Data fill size used for cache flushing and alignment. This field is set
  4600. // to the larger of the first and second level data cache fill sizes.
  4601. //
  4602. ULONG DcacheFillSize;
  4603. //
  4604. // Instruction cache alignment and fill size used for cache flushing and
  4605. // alignment. These fields are set to the larger of the first and second
  4606. // level data cache fill sizes.
  4607. //
  4608. ULONG IcacheAlignment;
  4609. ULONG IcacheFillSize;
  4610. //
  4611. // Processor identification from PrId register.
  4612. //
  4613. ULONG ProcessorId;
  4614. //
  4615. // Profiling data.
  4616. //
  4617. ULONG ProfileInterval;
  4618. ULONG ProfileCount;
  4619. //
  4620. // Stall execution count and scale factor.
  4621. //
  4622. ULONG StallExecutionCount;
  4623. ULONG StallScaleFactor;
  4624. //
  4625. // Processor number.
  4626. //
  4627. CCHAR Number;
  4628. //
  4629. // Spare cells.
  4630. //
  4631. CCHAR Spareb1;
  4632. CCHAR Spareb2;
  4633. CCHAR Spareb3;
  4634. //
  4635. // Pointers to bus error and parity error routines.
  4636. //
  4637. PKBUS_ERROR_ROUTINE DataBusError;
  4638. PKBUS_ERROR_ROUTINE InstructionBusError;
  4639. //
  4640. // Cache policy, right justified, as read from the processor configuration
  4641. // register at startup.
  4642. //
  4643. ULONG CachePolicy;
  4644. //
  4645. // IRQL mapping tables.
  4646. //
  4647. UCHAR IrqlMask[32];
  4648. UCHAR IrqlTable[9];
  4649. //
  4650. // Current IRQL.
  4651. //
  4652. UCHAR CurrentIrql;
  4653. //
  4654. // Processor affinity mask.
  4655. //
  4656. KAFFINITY SetMember;
  4657. //
  4658. // Reserved interrupt vector mask.
  4659. //
  4660. ULONG ReservedVectors;
  4661. //
  4662. // Current state parameters.
  4663. //
  4664. struct _KTHREAD *CurrentThread;
  4665. //
  4666. // Cache policy, PTE field aligned, as read from the processor configuration
  4667. // register at startup.
  4668. //
  4669. ULONG AlignedCachePolicy;
  4670. //
  4671. // Complement of processor affinity mask.
  4672. //
  4673. KAFFINITY NotMember;
  4674. //
  4675. // Space reserved for the system.
  4676. //
  4677. ULONG SystemReserved[15];
  4678. //
  4679. // Data cache alignment used for cache flushing and alignment. This field is
  4680. // set to the larger of the first and second level data cache fill sizes.
  4681. //
  4682. ULONG DcacheAlignment;
  4683. //
  4684. // Space reserved for the HAL
  4685. //
  4686. ULONG HalReserved[16];
  4687. //
  4688. // End of the architecturally defined section of the PCR. This section
  4689. // may be directly addressed by vendor/platform specific HAL code and will
  4690. // not change from version to version of NT.
  4691. //
  4692. } KPCR, *PKPCR;
  4693. //
  4694. // The following flags control the contents of the CONTEXT structure.
  4695. //
  4696. #if !defined(RC_INVOKED)
  4697. #define CONTEXT_R4000 0x00010000 // r4000 context
  4698. #define CONTEXT_CONTROL (CONTEXT_R4000 | 0x00000001)
  4699. #define CONTEXT_FLOATING_POINT (CONTEXT_R4000 | 0x00000002)
  4700. #define CONTEXT_INTEGER (CONTEXT_R4000 | 0x00000004)
  4701. #define CONTEXT_EXTENDED_FLOAT (CONTEXT_FLOATING_POINT | 0x00000008)
  4702. #define CONTEXT_EXTENDED_INTEGER (CONTEXT_INTEGER | 0x00000010)
  4703. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | \
  4704. CONTEXT_INTEGER | CONTEXT_EXTENDED_INTEGER)
  4705. #endif
  4706. //
  4707. // Context Frame
  4708. //
  4709. // N.B. This frame must be exactly a multiple of 16 bytes in length.
  4710. //
  4711. // This frame has a several purposes: 1) it is used as an argument to
  4712. // NtContinue, 2) it is used to constuct a call frame for APC delivery,
  4713. // 3) it is used to construct a call frame for exception dispatching
  4714. // in user mode, and 4) it is used in the user level thread creation
  4715. // routines.
  4716. //
  4717. // The layout of the record conforms to a standard call frame.
  4718. //
  4719. typedef struct _CONTEXT {
  4720. //
  4721. // This section is always present and is used as an argument build
  4722. // area.
  4723. //
  4724. // N.B. Context records are 0 mod 8 aligned starting with NT 4.0.
  4725. //
  4726. union {
  4727. ULONG Argument[4];
  4728. ULONGLONG Alignment;
  4729. };
  4730. //
  4731. // The following union defines the 32-bit and 64-bit register context.
  4732. //
  4733. union {
  4734. //
  4735. // 32-bit context.
  4736. //
  4737. struct {
  4738. //
  4739. // This section is specified/returned if the ContextFlags contains
  4740. // the flag CONTEXT_FLOATING_POINT.
  4741. //
  4742. // N.B. This section contains the 16 double floating registers f0,
  4743. // f2, ..., f30.
  4744. //
  4745. ULONG FltF0;
  4746. ULONG FltF1;
  4747. ULONG FltF2;
  4748. ULONG FltF3;
  4749. ULONG FltF4;
  4750. ULONG FltF5;
  4751. ULONG FltF6;
  4752. ULONG FltF7;
  4753. ULONG FltF8;
  4754. ULONG FltF9;
  4755. ULONG FltF10;
  4756. ULONG FltF11;
  4757. ULONG FltF12;
  4758. ULONG FltF13;
  4759. ULONG FltF14;
  4760. ULONG FltF15;
  4761. ULONG FltF16;
  4762. ULONG FltF17;
  4763. ULONG FltF18;
  4764. ULONG FltF19;
  4765. ULONG FltF20;
  4766. ULONG FltF21;
  4767. ULONG FltF22;
  4768. ULONG FltF23;
  4769. ULONG FltF24;
  4770. ULONG FltF25;
  4771. ULONG FltF26;
  4772. ULONG FltF27;
  4773. ULONG FltF28;
  4774. ULONG FltF29;
  4775. ULONG FltF30;
  4776. ULONG FltF31;
  4777. //
  4778. // This section is specified/returned if the ContextFlags contains
  4779. // the flag CONTEXT_INTEGER.
  4780. //
  4781. // N.B. The registers gp, sp, and ra are defined in this section,
  4782. // but are considered part of the control context rather than
  4783. // part of the integer context.
  4784. //
  4785. // N.B. Register zero is not stored in the frame.
  4786. //
  4787. ULONG IntZero;
  4788. ULONG IntAt;
  4789. ULONG IntV0;
  4790. ULONG IntV1;
  4791. ULONG IntA0;
  4792. ULONG IntA1;
  4793. ULONG IntA2;
  4794. ULONG IntA3;
  4795. ULONG IntT0;
  4796. ULONG IntT1;
  4797. ULONG IntT2;
  4798. ULONG IntT3;
  4799. ULONG IntT4;
  4800. ULONG IntT5;
  4801. ULONG IntT6;
  4802. ULONG IntT7;
  4803. ULONG IntS0;
  4804. ULONG IntS1;
  4805. ULONG IntS2;
  4806. ULONG IntS3;
  4807. ULONG IntS4;
  4808. ULONG IntS5;
  4809. ULONG IntS6;
  4810. ULONG IntS7;
  4811. ULONG IntT8;
  4812. ULONG IntT9;
  4813. ULONG IntK0;
  4814. ULONG IntK1;
  4815. ULONG IntGp;
  4816. ULONG IntSp;
  4817. ULONG IntS8;
  4818. ULONG IntRa;
  4819. ULONG IntLo;
  4820. ULONG IntHi;
  4821. //
  4822. // This section is specified/returned if the ContextFlags word contains
  4823. // the flag CONTEXT_FLOATING_POINT.
  4824. //
  4825. ULONG Fsr;
  4826. //
  4827. // This section is specified/returned if the ContextFlags word contains
  4828. // the flag CONTEXT_CONTROL.
  4829. //
  4830. // N.B. The registers gp, sp, and ra are defined in the integer section,
  4831. // but are considered part of the control context rather than part of
  4832. // the integer context.
  4833. //
  4834. ULONG Fir;
  4835. ULONG Psr;
  4836. //
  4837. // The flags values within this flag control the contents of
  4838. // a CONTEXT record.
  4839. //
  4840. // If the context record is used as an input parameter, then
  4841. // for each portion of the context record controlled by a flag
  4842. // whose value is set, it is assumed that that portion of the
  4843. // context record contains valid context. If the context record
  4844. // is being used to modify a thread's context, then only that
  4845. // portion of the threads context will be modified.
  4846. //
  4847. // If the context record is used as an IN OUT parameter to capture
  4848. // the context of a thread, then only those portions of the thread's
  4849. // context corresponding to set flags will be returned.
  4850. //
  4851. // The context record is never used as an OUT only parameter.
  4852. //
  4853. ULONG ContextFlags;
  4854. };
  4855. //
  4856. // 64-bit context.
  4857. //
  4858. struct {
  4859. //
  4860. // This section is specified/returned if the ContextFlags contains
  4861. // the flag CONTEXT_EXTENDED_FLOAT.
  4862. //
  4863. // N.B. This section contains the 32 double floating registers f0,
  4864. // f1, ..., f31.
  4865. //
  4866. ULONGLONG XFltF0;
  4867. ULONGLONG XFltF1;
  4868. ULONGLONG XFltF2;
  4869. ULONGLONG XFltF3;
  4870. ULONGLONG XFltF4;
  4871. ULONGLONG XFltF5;
  4872. ULONGLONG XFltF6;
  4873. ULONGLONG XFltF7;
  4874. ULONGLONG XFltF8;
  4875. ULONGLONG XFltF9;
  4876. ULONGLONG XFltF10;
  4877. ULONGLONG XFltF11;
  4878. ULONGLONG XFltF12;
  4879. ULONGLONG XFltF13;
  4880. ULONGLONG XFltF14;
  4881. ULONGLONG XFltF15;
  4882. ULONGLONG XFltF16;
  4883. ULONGLONG XFltF17;
  4884. ULONGLONG XFltF18;
  4885. ULONGLONG XFltF19;
  4886. ULONGLONG XFltF20;
  4887. ULONGLONG XFltF21;
  4888. ULONGLONG XFltF22;
  4889. ULONGLONG XFltF23;
  4890. ULONGLONG XFltF24;
  4891. ULONGLONG XFltF25;
  4892. ULONGLONG XFltF26;
  4893. ULONGLONG XFltF27;
  4894. ULONGLONG XFltF28;
  4895. ULONGLONG XFltF29;
  4896. ULONGLONG XFltF30;
  4897. ULONGLONG XFltF31;
  4898. //
  4899. // The following sections must exactly overlay the 32-bit context.
  4900. //
  4901. ULONG Fill1;
  4902. ULONG Fill2;
  4903. //
  4904. // This section is specified/returned if the ContextFlags contains
  4905. // the flag CONTEXT_FLOATING_POINT.
  4906. //
  4907. ULONG XFsr;
  4908. //
  4909. // This section is specified/returned if the ContextFlags contains
  4910. // the flag CONTEXT_CONTROL.
  4911. //
  4912. // N.B. The registers gp, sp, and ra are defined in the integer
  4913. // section, but are considered part of the control context
  4914. // rather than part of the integer context.
  4915. //
  4916. ULONG XFir;
  4917. ULONG XPsr;
  4918. //
  4919. // The flags values within this flag control the contents of
  4920. // a CONTEXT record.
  4921. //
  4922. // If the context record is used as an input parameter, then
  4923. // for each portion of the context record controlled by a flag
  4924. // whose value is set, it is assumed that that portion of the
  4925. // context record contains valid context. If the context record
  4926. // is being used to modify a thread's context, then only that
  4927. // portion of the threads context will be modified.
  4928. //
  4929. // If the context record is used as an IN OUT parameter to capture
  4930. // the context of a thread, then only those portions of the thread's
  4931. // context corresponding to set flags will be returned.
  4932. //
  4933. // The context record is never used as an OUT only parameter.
  4934. //
  4935. ULONG XContextFlags;
  4936. //
  4937. // This section is specified/returned if the ContextFlags contains
  4938. // the flag CONTEXT_EXTENDED_INTEGER.
  4939. //
  4940. // N.B. The registers gp, sp, and ra are defined in this section,
  4941. // but are considered part of the control context rather than
  4942. // part of the integer context.
  4943. //
  4944. // N.B. Register zero is not stored in the frame.
  4945. //
  4946. ULONGLONG XIntZero;
  4947. ULONGLONG XIntAt;
  4948. ULONGLONG XIntV0;
  4949. ULONGLONG XIntV1;
  4950. ULONGLONG XIntA0;
  4951. ULONGLONG XIntA1;
  4952. ULONGLONG XIntA2;
  4953. ULONGLONG XIntA3;
  4954. ULONGLONG XIntT0;
  4955. ULONGLONG XIntT1;
  4956. ULONGLONG XIntT2;
  4957. ULONGLONG XIntT3;
  4958. ULONGLONG XIntT4;
  4959. ULONGLONG XIntT5;
  4960. ULONGLONG XIntT6;
  4961. ULONGLONG XIntT7;
  4962. ULONGLONG XIntS0;
  4963. ULONGLONG XIntS1;
  4964. ULONGLONG XIntS2;
  4965. ULONGLONG XIntS3;
  4966. ULONGLONG XIntS4;
  4967. ULONGLONG XIntS5;
  4968. ULONGLONG XIntS6;
  4969. ULONGLONG XIntS7;
  4970. ULONGLONG XIntT8;
  4971. ULONGLONG XIntT9;
  4972. ULONGLONG XIntK0;
  4973. ULONGLONG XIntK1;
  4974. ULONGLONG XIntGp;
  4975. ULONGLONG XIntSp;
  4976. ULONGLONG XIntS8;
  4977. ULONGLONG XIntRa;
  4978. ULONGLONG XIntLo;
  4979. ULONGLONG XIntHi;
  4980. };
  4981. };
  4982. } CONTEXT, *PCONTEXT;
  4983. #endif // defined(_MIPS_)
  4984. #if defined(_ALPHA_)
  4985. //
  4986. // Define system time structure.
  4987. //
  4988. typedef ULONGLONG KSYSTEM_TIME;
  4989. typedef KSYSTEM_TIME *PKSYSTEM_TIME;
  4990. #endif
  4991. #ifdef _ALPHA_
  4992. //
  4993. // Define size of kernel mode stack.
  4994. //
  4995. #define KERNEL_STACK_SIZE 0x4000
  4996. //
  4997. // Define size of large kernel mode stack for callbacks.
  4998. //
  4999. #define KERNEL_LARGE_STACK_SIZE 65536
  5000. //
  5001. // Define number of pages to initialize in a large kernel stack.
  5002. //
  5003. #define KERNEL_LARGE_STACK_COMMIT 16384
  5004. //
  5005. // The following flags control the contents of the CONTEXT structure.
  5006. //
  5007. #if !defined(RC_INVOKED)
  5008. #define CONTEXT_PORTABLE_32BIT 0x00100000
  5009. #define CONTEXT_ALPHA 0x00020000
  5010. #define CONTEXT_CONTROL (CONTEXT_ALPHA | 0x00000001L)
  5011. #define CONTEXT_FLOATING_POINT (CONTEXT_ALPHA | 0x00000002L)
  5012. #define CONTEXT_INTEGER (CONTEXT_ALPHA | 0x00000004L)
  5013. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
  5014. #endif
  5015. #ifndef _PORTABLE_32BIT_CONTEXT
  5016. //
  5017. // Context Frame
  5018. //
  5019. // This frame has a several purposes: 1) it is used as an argument to
  5020. // NtContinue, 2) it is used to construct a call frame for APC delivery,
  5021. // 3) it is used to construct a call frame for exception dispatching
  5022. // in user mode, 4) it is used in the user level thread creation
  5023. // routines, and 5) it is used to to pass thread state to debuggers.
  5024. //
  5025. // N.B. Because this record is used as a call frame, it must be EXACTLY
  5026. // a multiple of 16 bytes in length.
  5027. //
  5028. // There are two variations of the context structure. This is the real one.
  5029. //
  5030. typedef struct _CONTEXT {
  5031. //
  5032. // This section is specified/returned if the ContextFlags word contains
  5033. // the flag CONTEXT_FLOATING_POINT.
  5034. //
  5035. ULONGLONG FltF0;
  5036. ULONGLONG FltF1;
  5037. ULONGLONG FltF2;
  5038. ULONGLONG FltF3;
  5039. ULONGLONG FltF4;
  5040. ULONGLONG FltF5;
  5041. ULONGLONG FltF6;
  5042. ULONGLONG FltF7;
  5043. ULONGLONG FltF8;
  5044. ULONGLONG FltF9;
  5045. ULONGLONG FltF10;
  5046. ULONGLONG FltF11;
  5047. ULONGLONG FltF12;
  5048. ULONGLONG FltF13;
  5049. ULONGLONG FltF14;
  5050. ULONGLONG FltF15;
  5051. ULONGLONG FltF16;
  5052. ULONGLONG FltF17;
  5053. ULONGLONG FltF18;
  5054. ULONGLONG FltF19;
  5055. ULONGLONG FltF20;
  5056. ULONGLONG FltF21;
  5057. ULONGLONG FltF22;
  5058. ULONGLONG FltF23;
  5059. ULONGLONG FltF24;
  5060. ULONGLONG FltF25;
  5061. ULONGLONG FltF26;
  5062. ULONGLONG FltF27;
  5063. ULONGLONG FltF28;
  5064. ULONGLONG FltF29;
  5065. ULONGLONG FltF30;
  5066. ULONGLONG FltF31;
  5067. //
  5068. // This section is specified/returned if the ContextFlags word contains
  5069. // the flag CONTEXT_INTEGER.
  5070. //
  5071. // N.B. The registers gp, sp, and ra are defined in this section, but are
  5072. // considered part of the control context rather than part of the integer
  5073. // context.
  5074. //
  5075. ULONGLONG IntV0; // $0: return value register, v0
  5076. ULONGLONG IntT0; // $1: temporary registers, t0 - t7
  5077. ULONGLONG IntT1; // $2:
  5078. ULONGLONG IntT2; // $3:
  5079. ULONGLONG IntT3; // $4:
  5080. ULONGLONG IntT4; // $5:
  5081. ULONGLONG IntT5; // $6:
  5082. ULONGLONG IntT6; // $7:
  5083. ULONGLONG IntT7; // $8:
  5084. ULONGLONG IntS0; // $9: nonvolatile registers, s0 - s5
  5085. ULONGLONG IntS1; // $10:
  5086. ULONGLONG IntS2; // $11:
  5087. ULONGLONG IntS3; // $12:
  5088. ULONGLONG IntS4; // $13:
  5089. ULONGLONG IntS5; // $14:
  5090. ULONGLONG IntFp; // $15: frame pointer register, fp/s6
  5091. ULONGLONG IntA0; // $16: argument registers, a0 - a5
  5092. ULONGLONG IntA1; // $17:
  5093. ULONGLONG IntA2; // $18:
  5094. ULONGLONG IntA3; // $19:
  5095. ULONGLONG IntA4; // $20:
  5096. ULONGLONG IntA5; // $21:
  5097. ULONGLONG IntT8; // $22: temporary registers, t8 - t11
  5098. ULONGLONG IntT9; // $23:
  5099. ULONGLONG IntT10; // $24:
  5100. ULONGLONG IntT11; // $25:
  5101. ULONGLONG IntRa; // $26: return address register, ra
  5102. ULONGLONG IntT12; // $27: temporary register, t12
  5103. ULONGLONG IntAt; // $28: assembler temp register, at
  5104. ULONGLONG IntGp; // $29: global pointer register, gp
  5105. ULONGLONG IntSp; // $30: stack pointer register, sp
  5106. ULONGLONG IntZero; // $31: zero register, zero
  5107. //
  5108. // This section is specified/returned if the ContextFlags word contains
  5109. // the flag CONTEXT_FLOATING_POINT.
  5110. //
  5111. ULONGLONG Fpcr; // floating point control register
  5112. ULONGLONG SoftFpcr; // software extension to FPCR
  5113. //
  5114. // This section is specified/returned if the ContextFlags word contains
  5115. // the flag CONTEXT_CONTROL.
  5116. //
  5117. // N.B. The registers gp, sp, and ra are defined in the integer section,
  5118. // but are considered part of the control context rather than part of
  5119. // the integer context.
  5120. //
  5121. ULONGLONG Fir; // (fault instruction) continuation address
  5122. ULONG Psr; // processor status
  5123. //
  5124. // The flags values within this flag control the contents of
  5125. // a CONTEXT record.
  5126. //
  5127. // If the context record is used as an input parameter, then
  5128. // for each portion of the context record controlled by a flag
  5129. // whose value is set, it is assumed that that portion of the
  5130. // context record contains valid context. If the context record
  5131. // is being used to modify a thread's context, then only that
  5132. // portion of the threads context will be modified.
  5133. //
  5134. // If the context record is used as an IN OUT parameter to capture
  5135. // the context of a thread, then only those portions of the thread's
  5136. // context corresponding to set flags will be returned.
  5137. //
  5138. // The context record is never used as an OUT only parameter.
  5139. //
  5140. ULONG ContextFlags;
  5141. ULONG Fill[4]; // padding for 16-byte stack frame alignment
  5142. } CONTEXT, *PCONTEXT;
  5143. #else
  5144. //
  5145. // 32-bit Context Frame
  5146. //
  5147. // This alternate version of the Alpha context structure parallels that
  5148. // of MIPS and IX86 in style for the first 64 entries: 32-bit machines
  5149. // can operate on the fields, and a value declared as a pointer to an
  5150. // array of int's can be used to index into the fields. This makes life
  5151. // with windbg and ntsd vastly easier.
  5152. //
  5153. // There are two parts: the first contains the lower 32-bits of each
  5154. // element in the 64-bit definition above. The second part contains
  5155. // the upper 32-bits of each 64-bit element above.
  5156. //
  5157. // The names in the first part are identical to the 64-bit names.
  5158. // The second part names are prefixed with "High".
  5159. //
  5160. // 1st half: at 32 bits each, (containing the low parts of 64-bit values)
  5161. // 32 floats, 32 ints, fpcrs, fir, psr, contextflags
  5162. // 2nd half: at 32 bits each
  5163. // 32 floats, 32 ints, fpcrs, fir, fill
  5164. //
  5165. // There is no external support for the 32-bit version of the context
  5166. // structure. It is only used internally by windbg and ntsd.
  5167. //
  5168. // This structure must be the same size as the 64-bit version above.
  5169. //
  5170. typedef struct _CONTEXT {
  5171. ULONG FltF0;
  5172. ULONG FltF1;
  5173. ULONG FltF2;
  5174. ULONG FltF3;
  5175. ULONG FltF4;
  5176. ULONG FltF5;
  5177. ULONG FltF6;
  5178. ULONG FltF7;
  5179. ULONG FltF8;
  5180. ULONG FltF9;
  5181. ULONG FltF10;
  5182. ULONG FltF11;
  5183. ULONG FltF12;
  5184. ULONG FltF13;
  5185. ULONG FltF14;
  5186. ULONG FltF15;
  5187. ULONG FltF16;
  5188. ULONG FltF17;
  5189. ULONG FltF18;
  5190. ULONG FltF19;
  5191. ULONG FltF20;
  5192. ULONG FltF21;
  5193. ULONG FltF22;
  5194. ULONG FltF23;
  5195. ULONG FltF24;
  5196. ULONG FltF25;
  5197. ULONG FltF26;
  5198. ULONG FltF27;
  5199. ULONG FltF28;
  5200. ULONG FltF29;
  5201. ULONG FltF30;
  5202. ULONG FltF31;
  5203. ULONG IntV0; // $0: return value register, v0
  5204. ULONG IntT0; // $1: temporary registers, t0 - t7
  5205. ULONG IntT1; // $2:
  5206. ULONG IntT2; // $3:
  5207. ULONG IntT3; // $4:
  5208. ULONG IntT4; // $5:
  5209. ULONG IntT5; // $6:
  5210. ULONG IntT6; // $7:
  5211. ULONG IntT7; // $8:
  5212. ULONG IntS0; // $9: nonvolatile registers, s0 - s5
  5213. ULONG IntS1; // $10:
  5214. ULONG IntS2; // $11:
  5215. ULONG IntS3; // $12:
  5216. ULONG IntS4; // $13:
  5217. ULONG IntS5; // $14:
  5218. ULONG IntFp; // $15: frame pointer register, fp/s6
  5219. ULONG IntA0; // $16: argument registers, a0 - a5
  5220. ULONG IntA1; // $17:
  5221. ULONG IntA2; // $18:
  5222. ULONG IntA3; // $19:
  5223. ULONG IntA4; // $20:
  5224. ULONG IntA5; // $21:
  5225. ULONG IntT8; // $22: temporary registers, t8 - t11
  5226. ULONG IntT9; // $23:
  5227. ULONG IntT10; // $24:
  5228. ULONG IntT11; // $25:
  5229. ULONG IntRa; // $26: return address register, ra
  5230. ULONG IntT12; // $27: temporary register, t12
  5231. ULONG IntAt; // $28: assembler temp register, at
  5232. ULONG IntGp; // $29: global pointer register, gp
  5233. ULONG IntSp; // $30: stack pointer register, sp
  5234. ULONG IntZero; // $31: zero register, zero
  5235. ULONG Fpcr; // floating point control register
  5236. ULONG SoftFpcr; // software extension to FPCR
  5237. ULONG Fir; // (fault instruction) continuation address
  5238. ULONG Psr; // processor status
  5239. ULONG ContextFlags;
  5240. //
  5241. // Beginning of the "second half".
  5242. // The name "High" parallels the HighPart of a LargeInteger.
  5243. //
  5244. ULONG HighFltF0;
  5245. ULONG HighFltF1;
  5246. ULONG HighFltF2;
  5247. ULONG HighFltF3;
  5248. ULONG HighFltF4;
  5249. ULONG HighFltF5;
  5250. ULONG HighFltF6;
  5251. ULONG HighFltF7;
  5252. ULONG HighFltF8;
  5253. ULONG HighFltF9;
  5254. ULONG HighFltF10;
  5255. ULONG HighFltF11;
  5256. ULONG HighFltF12;
  5257. ULONG HighFltF13;
  5258. ULONG HighFltF14;
  5259. ULONG HighFltF15;
  5260. ULONG HighFltF16;
  5261. ULONG HighFltF17;
  5262. ULONG HighFltF18;
  5263. ULONG HighFltF19;
  5264. ULONG HighFltF20;
  5265. ULONG HighFltF21;
  5266. ULONG HighFltF22;
  5267. ULONG HighFltF23;
  5268. ULONG HighFltF24;
  5269. ULONG HighFltF25;
  5270. ULONG HighFltF26;
  5271. ULONG HighFltF27;
  5272. ULONG HighFltF28;
  5273. ULONG HighFltF29;
  5274. ULONG HighFltF30;
  5275. ULONG HighFltF31;
  5276. ULONG HighIntV0; // $0: return value register, v0
  5277. ULONG HighIntT0; // $1: temporary registers, t0 - t7
  5278. ULONG HighIntT1; // $2:
  5279. ULONG HighIntT2; // $3:
  5280. ULONG HighIntT3; // $4:
  5281. ULONG HighIntT4; // $5:
  5282. ULONG HighIntT5; // $6:
  5283. ULONG HighIntT6; // $7:
  5284. ULONG HighIntT7; // $8:
  5285. ULONG HighIntS0; // $9: nonvolatile registers, s0 - s5
  5286. ULONG HighIntS1; // $10:
  5287. ULONG HighIntS2; // $11:
  5288. ULONG HighIntS3; // $12:
  5289. ULONG HighIntS4; // $13:
  5290. ULONG HighIntS5; // $14:
  5291. ULONG HighIntFp; // $15: frame pointer register, fp/s6
  5292. ULONG HighIntA0; // $16: argument registers, a0 - a5
  5293. ULONG HighIntA1; // $17:
  5294. ULONG HighIntA2; // $18:
  5295. ULONG HighIntA3; // $19:
  5296. ULONG HighIntA4; // $20:
  5297. ULONG HighIntA5; // $21:
  5298. ULONG HighIntT8; // $22: temporary registers, t8 - t11
  5299. ULONG HighIntT9; // $23:
  5300. ULONG HighIntT10; // $24:
  5301. ULONG HighIntT11; // $25:
  5302. ULONG HighIntRa; // $26: return address register, ra
  5303. ULONG HighIntT12; // $27: temporary register, t12
  5304. ULONG HighIntAt; // $28: assembler temp register, at
  5305. ULONG HighIntGp; // $29: global pointer register, gp
  5306. ULONG HighIntSp; // $30: stack pointer register, sp
  5307. ULONG HighIntZero; // $31: zero register, zero
  5308. ULONG HighFpcr; // floating point control register
  5309. ULONG HighSoftFpcr; // software extension to FPCR
  5310. ULONG HighFir; // processor status
  5311. double DoNotUseThisField; // to force quadword structure alignment
  5312. ULONG HighFill[2]; // padding for 16-byte stack frame alignment
  5313. } CONTEXT, *PCONTEXT;
  5314. //
  5315. // These should name the fields in the _PORTABLE_32BIT structure
  5316. // that overlay the Psr and ContextFlags in the normal structure.
  5317. //
  5318. #define _QUAD_PSR_OFFSET HighSoftFpcr
  5319. #define _QUAD_FLAGS_OFFSET HighFir
  5320. #endif // _PORTABLE_32BIT_CONTEXT
  5321. #endif
  5322. #if defined(_PPC_)
  5323. // end_windbgkd end_winnt
  5324. //
  5325. // Define system time structure.
  5326. //
  5327. typedef struct _KSYSTEM_TIME {
  5328. ULONG LowPart;
  5329. LONG High1Time;
  5330. LONG High2Time;
  5331. } KSYSTEM_TIME, *PKSYSTEM_TIME;
  5332. //
  5333. // Define unsupported "keywords".
  5334. //
  5335. #define _cdecl
  5336. //
  5337. //
  5338. // Define size of kernel mode stack.
  5339. //
  5340. // **FINISH** This may not be the appropriate value for PowerPC
  5341. #define KERNEL_STACK_SIZE 16384
  5342. //
  5343. // Define size of large kernel mode stack for callbacks.
  5344. //
  5345. #define KERNEL_LARGE_STACK_SIZE 61440
  5346. //
  5347. // Define number of pages to initialize in a large kernel stack.
  5348. //
  5349. #define KERNEL_LARGE_STACK_COMMIT 16384
  5350. //
  5351. // Define bus error routine type.
  5352. //
  5353. struct _EXCEPTION_RECORD;
  5354. struct _KEXCEPTION_FRAME;
  5355. struct _KTRAP_FRAME;
  5356. typedef
  5357. VOID
  5358. (*PKBUS_ERROR_ROUTINE) (
  5359. IN struct _EXCEPTION_RECORD *ExceptionRecord,
  5360. IN struct _KEXCEPTION_FRAME *ExceptionFrame,
  5361. IN struct _KTRAP_FRAME *TrapFrame,
  5362. IN PVOID VirtualAddress,
  5363. IN PHYSICAL_ADDRESS PhysicalAddress
  5364. );
  5365. //
  5366. // Macros to emit eieio, sync, and isync instructions.
  5367. //
  5368. #if defined(_M_PPC) && defined(_MSC_VER) && (_MSC_VER>=1000)
  5369. void __emit( unsigned const __int32 );
  5370. #define __builtin_eieio() __emit( 0x7C0006AC )
  5371. #define __builtin_sync() __emit( 0x7C0004AC )
  5372. #define __builtin_isync() __emit( 0x4C00012C )
  5373. #else
  5374. void __builtin_eieio(void);
  5375. void __builtin_sync(void);
  5376. void __builtin_isync(void);
  5377. #endif
  5378. //
  5379. // The following flags control the contents of the CONTEXT structure.
  5380. //
  5381. #if !defined(RC_INVOKED)
  5382. #define CONTEXT_CONTROL 0x00000001L
  5383. #define CONTEXT_FLOATING_POINT 0x00000002L
  5384. #define CONTEXT_INTEGER 0x00000004L
  5385. #define CONTEXT_DEBUG_REGISTERS 0x00000008L
  5386. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
  5387. #endif
  5388. //
  5389. // Context Frame
  5390. //
  5391. // N.B. This frame must be exactly a multiple of 16 bytes in length.
  5392. //
  5393. // This frame has a several purposes: 1) it is used as an argument to
  5394. // NtContinue, 2) it is used to constuct a call frame for APC delivery,
  5395. // 3) it is used to construct a call frame for exception dispatching
  5396. // in user mode, and 4) it is used in the user level thread creation
  5397. // routines.
  5398. //
  5399. // Requires at least 8-byte alignment (double)
  5400. //
  5401. typedef struct _CONTEXT {
  5402. //
  5403. // This section is specified/returned if the ContextFlags word contains
  5404. // the flag CONTEXT_FLOATING_POINT.
  5405. //
  5406. double Fpr0; // Floating registers 0..31
  5407. double Fpr1;
  5408. double Fpr2;
  5409. double Fpr3;
  5410. double Fpr4;
  5411. double Fpr5;
  5412. double Fpr6;
  5413. double Fpr7;
  5414. double Fpr8;
  5415. double Fpr9;
  5416. double Fpr10;
  5417. double Fpr11;
  5418. double Fpr12;
  5419. double Fpr13;
  5420. double Fpr14;
  5421. double Fpr15;
  5422. double Fpr16;
  5423. double Fpr17;
  5424. double Fpr18;
  5425. double Fpr19;
  5426. double Fpr20;
  5427. double Fpr21;
  5428. double Fpr22;
  5429. double Fpr23;
  5430. double Fpr24;
  5431. double Fpr25;
  5432. double Fpr26;
  5433. double Fpr27;
  5434. double Fpr28;
  5435. double Fpr29;
  5436. double Fpr30;
  5437. double Fpr31;
  5438. double Fpscr; // Floating point status/control reg
  5439. //
  5440. // This section is specified/returned if the ContextFlags word contains
  5441. // the flag CONTEXT_INTEGER.
  5442. //
  5443. ULONG Gpr0; // General registers 0..31
  5444. ULONG Gpr1;
  5445. ULONG Gpr2;
  5446. ULONG Gpr3;
  5447. ULONG Gpr4;
  5448. ULONG Gpr5;
  5449. ULONG Gpr6;
  5450. ULONG Gpr7;
  5451. ULONG Gpr8;
  5452. ULONG Gpr9;
  5453. ULONG Gpr10;
  5454. ULONG Gpr11;
  5455. ULONG Gpr12;
  5456. ULONG Gpr13;
  5457. ULONG Gpr14;
  5458. ULONG Gpr15;
  5459. ULONG Gpr16;
  5460. ULONG Gpr17;
  5461. ULONG Gpr18;
  5462. ULONG Gpr19;
  5463. ULONG Gpr20;
  5464. ULONG Gpr21;
  5465. ULONG Gpr22;
  5466. ULONG Gpr23;
  5467. ULONG Gpr24;
  5468. ULONG Gpr25;
  5469. ULONG Gpr26;
  5470. ULONG Gpr27;
  5471. ULONG Gpr28;
  5472. ULONG Gpr29;
  5473. ULONG Gpr30;
  5474. ULONG Gpr31;
  5475. ULONG Cr; // Condition register
  5476. ULONG Xer; // Fixed point exception register
  5477. //
  5478. // This section is specified/returned if the ContextFlags word contains
  5479. // the flag CONTEXT_CONTROL.
  5480. //
  5481. ULONG Msr; // Machine status register
  5482. ULONG Iar; // Instruction address register
  5483. ULONG Lr; // Link register
  5484. ULONG Ctr; // Count register
  5485. //
  5486. // The flags values within this flag control the contents of
  5487. // a CONTEXT record.
  5488. //
  5489. // If the context record is used as an input parameter, then
  5490. // for each portion of the context record controlled by a flag
  5491. // whose value is set, it is assumed that that portion of the
  5492. // context record contains valid context. If the context record
  5493. // is being used to modify a thread's context, then only that
  5494. // portion of the threads context will be modified.
  5495. //
  5496. // If the context record is used as an IN OUT parameter to capture
  5497. // the context of a thread, then only those portions of the thread's
  5498. // context corresponding to set flags will be returned.
  5499. //
  5500. // The context record is never used as an OUT only parameter.
  5501. //
  5502. ULONG ContextFlags;
  5503. ULONG Fill[3]; // Pad out to multiple of 16 bytes
  5504. //
  5505. // This section is specified/returned if CONTEXT_DEBUG_REGISTERS is
  5506. // set in ContextFlags. Note that CONTEXT_DEBUG_REGISTERS is NOT
  5507. // included in CONTEXT_FULL.
  5508. //
  5509. ULONG Dr0; // Breakpoint Register 1
  5510. ULONG Dr1; // Breakpoint Register 2
  5511. ULONG Dr2; // Breakpoint Register 3
  5512. ULONG Dr3; // Breakpoint Register 4
  5513. ULONG Dr4; // Breakpoint Register 5
  5514. ULONG Dr5; // Breakpoint Register 6
  5515. ULONG Dr6; // Debug Status Register
  5516. ULONG Dr7; // Debug Control Register
  5517. } CONTEXT, *PCONTEXT;
  5518. #endif // defined(_PPC_)
  5519. // begin_winnt
  5520. //
  5521. // Predefined Value Types.
  5522. //
  5523. #define REG_NONE ( 0 ) // No value type
  5524. #define REG_SZ ( 1 ) // Unicode nul terminated string
  5525. #define REG_EXPAND_SZ ( 2 ) // Unicode nul terminated string
  5526. // (with environment variable references)
  5527. #define REG_BINARY ( 3 ) // Free form binary
  5528. #define REG_DWORD ( 4 ) // 32-bit number
  5529. #define REG_DWORD_LITTLE_ENDIAN ( 4 ) // 32-bit number (same as REG_DWORD)
  5530. #define REG_DWORD_BIG_ENDIAN ( 5 ) // 32-bit number
  5531. #define REG_LINK ( 6 ) // Symbolic Link (unicode)
  5532. #define REG_MULTI_SZ ( 7 ) // Multiple Unicode strings
  5533. #define REG_RESOURCE_LIST ( 8 ) // Resource list in the resource map
  5534. #define REG_FULL_RESOURCE_DESCRIPTOR ( 9 ) // Resource list in the hardware description
  5535. #define REG_RESOURCE_REQUIREMENTS_LIST ( 10 )
  5536. //
  5537. // Service Types (Bit Mask)
  5538. //
  5539. #define SERVICE_KERNEL_DRIVER 0x00000001
  5540. #define SERVICE_FILE_SYSTEM_DRIVER 0x00000002
  5541. #define SERVICE_ADAPTER 0x00000004
  5542. #define SERVICE_RECOGNIZER_DRIVER 0x00000008
  5543. #define SERVICE_DRIVER (SERVICE_KERNEL_DRIVER | \
  5544. SERVICE_FILE_SYSTEM_DRIVER | \
  5545. SERVICE_RECOGNIZER_DRIVER)
  5546. #define SERVICE_WIN32_OWN_PROCESS 0x00000010
  5547. #define SERVICE_WIN32_SHARE_PROCESS 0x00000020
  5548. #define SERVICE_WIN32 (SERVICE_WIN32_OWN_PROCESS | \
  5549. SERVICE_WIN32_SHARE_PROCESS)
  5550. #define SERVICE_INTERACTIVE_PROCESS 0x00000100
  5551. #define SERVICE_TYPE_ALL (SERVICE_WIN32 | \
  5552. SERVICE_ADAPTER | \
  5553. SERVICE_DRIVER | \
  5554. SERVICE_INTERACTIVE_PROCESS)
  5555. //
  5556. // Start Type
  5557. //
  5558. #define SERVICE_BOOT_START 0x00000000
  5559. #define SERVICE_SYSTEM_START 0x00000001
  5560. #define SERVICE_AUTO_START 0x00000002
  5561. #define SERVICE_DEMAND_START 0x00000003
  5562. #define SERVICE_DISABLED 0x00000004
  5563. //
  5564. // Error control type
  5565. //
  5566. #define SERVICE_ERROR_IGNORE 0x00000000
  5567. #define SERVICE_ERROR_NORMAL 0x00000001
  5568. #define SERVICE_ERROR_SEVERE 0x00000002
  5569. #define SERVICE_ERROR_CRITICAL 0x00000003
  5570. //
  5571. //
  5572. // Define the registry driver node enumerations
  5573. //
  5574. typedef enum _CM_SERVICE_NODE_TYPE {
  5575. DriverType = SERVICE_KERNEL_DRIVER,
  5576. FileSystemType = SERVICE_FILE_SYSTEM_DRIVER,
  5577. Win32ServiceOwnProcess = SERVICE_WIN32_OWN_PROCESS,
  5578. Win32ServiceShareProcess = SERVICE_WIN32_SHARE_PROCESS,
  5579. AdapterType = SERVICE_ADAPTER,
  5580. RecognizerType = SERVICE_RECOGNIZER_DRIVER
  5581. } SERVICE_NODE_TYPE;
  5582. typedef enum _CM_SERVICE_LOAD_TYPE {
  5583. BootLoad = SERVICE_BOOT_START,
  5584. SystemLoad = SERVICE_SYSTEM_START,
  5585. AutoLoad = SERVICE_AUTO_START,
  5586. DemandLoad = SERVICE_DEMAND_START,
  5587. DisableLoad = SERVICE_DISABLED
  5588. } SERVICE_LOAD_TYPE;
  5589. typedef enum _CM_ERROR_CONTROL_TYPE {
  5590. IgnoreError = SERVICE_ERROR_IGNORE,
  5591. NormalError = SERVICE_ERROR_NORMAL,
  5592. SevereError = SERVICE_ERROR_SEVERE,
  5593. CriticalError = SERVICE_ERROR_CRITICAL
  5594. } SERVICE_ERROR_TYPE;
  5595. // end_winnt
  5596. //
  5597. // Resource List definitions
  5598. //
  5599. // begin_ntminiport begin_ntndis
  5600. //
  5601. // Defines the Type in the RESOURCE_DESCRIPTOR
  5602. //
  5603. typedef enum _CM_RESOURCE_TYPE {
  5604. CmResourceTypeNull = 0, // Reserved
  5605. CmResourceTypePort,
  5606. CmResourceTypeInterrupt,
  5607. CmResourceTypeMemory,
  5608. CmResourceTypeDma,
  5609. CmResourceTypeDeviceSpecific,
  5610. CmResourceTypeMaximum
  5611. } CM_RESOURCE_TYPE;
  5612. //
  5613. // Defines the ShareDisposition in the RESOURCE_DESCRIPTOR
  5614. //
  5615. typedef enum _CM_SHARE_DISPOSITION {
  5616. CmResourceShareUndetermined = 0, // Reserved
  5617. CmResourceShareDeviceExclusive,
  5618. CmResourceShareDriverExclusive,
  5619. CmResourceShareShared
  5620. } CM_SHARE_DISPOSITION;
  5621. //
  5622. // Define the bit masks for Flags when type is CmResourceTypeInterrupt
  5623. //
  5624. #define CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE 0
  5625. #define CM_RESOURCE_INTERRUPT_LATCHED 1
  5626. //
  5627. // Define the bit masks for Flags when type is CmResourceTypeMemory
  5628. //
  5629. #define CM_RESOURCE_MEMORY_READ_WRITE 0x0000
  5630. #define CM_RESOURCE_MEMORY_READ_ONLY 0x0001
  5631. #define CM_RESOURCE_MEMORY_WRITE_ONLY 0x0002
  5632. #define CM_RESOURCE_MEMORY_PREFETCHABLE 0x0004
  5633. #define CM_RESOURCE_MEMORY_COMBINEDWRITE 0x0008
  5634. #define CM_RESOURCE_MEMORY_24 0x0010
  5635. //
  5636. // Define the bit masks for Flags when type is CmResourceTypePort
  5637. //
  5638. #define CM_RESOURCE_PORT_MEMORY 0
  5639. #define CM_RESOURCE_PORT_IO 1
  5640. //
  5641. // Define the bit masks for Flags when type is CmResourceTypeDma
  5642. //
  5643. #define CM_RESOURCE_DMA_8 0x0000
  5644. #define CM_RESOURCE_DMA_16 0x0001
  5645. #define CM_RESOURCE_DMA_32 0x0002
  5646. // end_ntminiport end_ntndis
  5647. //
  5648. // This structure defines one type of resource used by a driver.
  5649. //
  5650. // There can only be *1* DeviceSpecificData block. It must be located at
  5651. // the end of all resource descriptors in a full descriptor block.
  5652. //
  5653. //
  5654. // BUGBUG Make sure alignment is made properly by compiler; otherwise move
  5655. // flags back to the top of the structure (common to all members of the
  5656. // union).
  5657. //
  5658. // begin_ntndis
  5659. #include "pshpack4.h"
  5660. typedef struct _CM_PARTIAL_RESOURCE_DESCRIPTOR {
  5661. UCHAR Type;
  5662. UCHAR ShareDisposition;
  5663. USHORT Flags;
  5664. union {
  5665. //
  5666. // Range of port numbers, inclusive. These are physical, bus
  5667. // relative. The value should be the same as the one passed to
  5668. // HalTranslateBusAddress().
  5669. //
  5670. struct {
  5671. PHYSICAL_ADDRESS Start;
  5672. ULONG Length;
  5673. } Port;
  5674. //
  5675. // IRQL and vector. Should be same values as were passed to
  5676. // HalGetInterruptVector().
  5677. //
  5678. struct {
  5679. ULONG Level;
  5680. ULONG Vector;
  5681. ULONG Affinity;
  5682. } Interrupt;
  5683. //
  5684. // Range of memory addresses, inclusive. These are physical, bus
  5685. // relative. The value should be the same as the one passed to
  5686. // HalTranslateBusAddress().
  5687. //
  5688. struct {
  5689. PHYSICAL_ADDRESS Start; // 64 bit physical addresses.
  5690. ULONG Length;
  5691. } Memory;
  5692. //
  5693. // Physical DMA channel.
  5694. //
  5695. struct {
  5696. ULONG Channel;
  5697. ULONG Port;
  5698. ULONG Reserved1;
  5699. } Dma;
  5700. //
  5701. // Device Specific information defined by the driver.
  5702. // The DataSize field indicates the size of the data in bytes. The
  5703. // data is located immediately after the DeviceSpecificData field in
  5704. // the structure.
  5705. //
  5706. struct {
  5707. ULONG DataSize;
  5708. ULONG Reserved1;
  5709. ULONG Reserved2;
  5710. } DeviceSpecificData;
  5711. } u;
  5712. } CM_PARTIAL_RESOURCE_DESCRIPTOR, *PCM_PARTIAL_RESOURCE_DESCRIPTOR;
  5713. #include "poppack.h"
  5714. //
  5715. // A Partial Resource List is what can be found in the ARC firmware
  5716. // or will be generated by ntdetect.com.
  5717. // The configuration manager will transform this structure into a Full
  5718. // resource descriptor when it is about to store it in the regsitry.
  5719. //
  5720. // Note: There must a be a convention to the order of fields of same type,
  5721. // (defined on a device by device basis) so that the fields can make sense
  5722. // to a driver (i.e. when multiple memory ranges are necessary).
  5723. //
  5724. typedef struct _CM_PARTIAL_RESOURCE_LIST {
  5725. USHORT Version;
  5726. USHORT Revision;
  5727. ULONG Count;
  5728. CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1];
  5729. } CM_PARTIAL_RESOURCE_LIST, *PCM_PARTIAL_RESOURCE_LIST;
  5730. //
  5731. // A Full Resource Descriptor is what can be found in the registry.
  5732. // This is what will be returned to a driver when it queries the registry
  5733. // to get device information; it will be stored under a key in the hardware
  5734. // description tree.
  5735. //
  5736. // Note: The BusNumber and Type are redundant information, but we will keep
  5737. // it since it allows the driver _not_ to append it when it is creating
  5738. // a resource list which could possibly span multiple buses.
  5739. //
  5740. // Note2: There must a be a convention to the order of fields of same type,
  5741. // (defined on a device by device basis) so that the fields can make sense
  5742. // to a driver (i.e. when multiple memory ranges are necessary).
  5743. //
  5744. typedef struct _CM_FULL_RESOURCE_DESCRIPTOR {
  5745. INTERFACE_TYPE InterfaceType;
  5746. ULONG BusNumber;
  5747. CM_PARTIAL_RESOURCE_LIST PartialResourceList;
  5748. } CM_FULL_RESOURCE_DESCRIPTOR, *PCM_FULL_RESOURCE_DESCRIPTOR;
  5749. //
  5750. // The Resource list is what will be stored by the drivers into the
  5751. // resource map via the IO API.
  5752. //
  5753. typedef struct _CM_RESOURCE_LIST {
  5754. ULONG Count;
  5755. CM_FULL_RESOURCE_DESCRIPTOR List[1];
  5756. } CM_RESOURCE_LIST, *PCM_RESOURCE_LIST;
  5757. // end_ntndis
  5758. //
  5759. // Define the structures used to interpret configuration data of
  5760. // \\Registry\machine\hardware\description tree.
  5761. // Basically, these structures are used to interpret component
  5762. // sepcific data.
  5763. //
  5764. //
  5765. // Define DEVICE_FLAGS
  5766. //
  5767. typedef struct _DEVICE_FLAGS {
  5768. ULONG Failed : 1;
  5769. ULONG ReadOnly : 1;
  5770. ULONG Removable : 1;
  5771. ULONG ConsoleIn : 1;
  5772. ULONG ConsoleOut : 1;
  5773. ULONG Input : 1;
  5774. ULONG Output : 1;
  5775. } DEVICE_FLAGS, *PDEVICE_FLAGS;
  5776. //
  5777. // Define Component Information structure
  5778. //
  5779. typedef struct _CM_COMPONENT_INFORMATION {
  5780. DEVICE_FLAGS Flags;
  5781. ULONG Version;
  5782. ULONG Key;
  5783. ULONG AffinityMask;
  5784. } CM_COMPONENT_INFORMATION, *PCM_COMPONENT_INFORMATION;
  5785. //
  5786. // The following structures are used to interpret x86
  5787. // DeviceSpecificData of CM_PARTIAL_RESOURCE_DESCRIPTOR.
  5788. // (Most of the structures are defined by BIOS. They are
  5789. // not aligned on word (or dword) boundary.
  5790. //
  5791. //
  5792. // Define the Rom Block structure
  5793. //
  5794. typedef struct _CM_ROM_BLOCK {
  5795. ULONG Address;
  5796. ULONG Size;
  5797. } CM_ROM_BLOCK, *PCM_ROM_BLOCK;
  5798. // begin_ntminiport begin_ntndis
  5799. #include "pshpack1.h"
  5800. // end_ntminiport end_ntndis
  5801. //
  5802. // Define INT13 driver parameter block
  5803. //
  5804. typedef struct _CM_INT13_DRIVE_PARAMETER {
  5805. USHORT DriveSelect;
  5806. ULONG MaxCylinders;
  5807. USHORT SectorsPerTrack;
  5808. USHORT MaxHeads;
  5809. USHORT NumberDrives;
  5810. } CM_INT13_DRIVE_PARAMETER, *PCM_INT13_DRIVE_PARAMETER;
  5811. // begin_ntminiport begin_ntndis
  5812. //
  5813. // Define Mca POS data block for slot
  5814. //
  5815. typedef struct _CM_MCA_POS_DATA {
  5816. USHORT AdapterId;
  5817. UCHAR PosData1;
  5818. UCHAR PosData2;
  5819. UCHAR PosData3;
  5820. UCHAR PosData4;
  5821. } CM_MCA_POS_DATA, *PCM_MCA_POS_DATA;
  5822. //
  5823. // Memory configuration of eisa data block structure
  5824. //
  5825. typedef struct _EISA_MEMORY_TYPE {
  5826. UCHAR ReadWrite: 1;
  5827. UCHAR Cached : 1;
  5828. UCHAR Reserved0 :1;
  5829. UCHAR Type:2;
  5830. UCHAR Shared:1;
  5831. UCHAR Reserved1 :1;
  5832. UCHAR MoreEntries : 1;
  5833. } EISA_MEMORY_TYPE, *PEISA_MEMORY_TYPE;
  5834. typedef struct _EISA_MEMORY_CONFIGURATION {
  5835. EISA_MEMORY_TYPE ConfigurationByte;
  5836. UCHAR DataSize;
  5837. USHORT AddressLowWord;
  5838. UCHAR AddressHighByte;
  5839. USHORT MemorySize;
  5840. } EISA_MEMORY_CONFIGURATION, *PEISA_MEMORY_CONFIGURATION;
  5841. //
  5842. // Interrupt configurationn of eisa data block structure
  5843. //
  5844. typedef struct _EISA_IRQ_DESCRIPTOR {
  5845. UCHAR Interrupt : 4;
  5846. UCHAR Reserved :1;
  5847. UCHAR LevelTriggered :1;
  5848. UCHAR Shared : 1;
  5849. UCHAR MoreEntries : 1;
  5850. } EISA_IRQ_DESCRIPTOR, *PEISA_IRQ_DESCRIPTOR;
  5851. typedef struct _EISA_IRQ_CONFIGURATION {
  5852. EISA_IRQ_DESCRIPTOR ConfigurationByte;
  5853. UCHAR Reserved;
  5854. } EISA_IRQ_CONFIGURATION, *PEISA_IRQ_CONFIGURATION;
  5855. //
  5856. // DMA description of eisa data block structure
  5857. //
  5858. typedef struct _DMA_CONFIGURATION_BYTE0 {
  5859. UCHAR Channel : 3;
  5860. UCHAR Reserved : 3;
  5861. UCHAR Shared :1;
  5862. UCHAR MoreEntries :1;
  5863. } DMA_CONFIGURATION_BYTE0;
  5864. typedef struct _DMA_CONFIGURATION_BYTE1 {
  5865. UCHAR Reserved0 : 2;
  5866. UCHAR TransferSize : 2;
  5867. UCHAR Timing : 2;
  5868. UCHAR Reserved1 : 2;
  5869. } DMA_CONFIGURATION_BYTE1;
  5870. typedef struct _EISA_DMA_CONFIGURATION {
  5871. DMA_CONFIGURATION_BYTE0 ConfigurationByte0;
  5872. DMA_CONFIGURATION_BYTE1 ConfigurationByte1;
  5873. } EISA_DMA_CONFIGURATION, *PEISA_DMA_CONFIGURATION;
  5874. //
  5875. // Port description of eisa data block structure
  5876. //
  5877. typedef struct _EISA_PORT_DESCRIPTOR {
  5878. UCHAR NumberPorts : 5;
  5879. UCHAR Reserved :1;
  5880. UCHAR Shared :1;
  5881. UCHAR MoreEntries : 1;
  5882. } EISA_PORT_DESCRIPTOR, *PEISA_PORT_DESCRIPTOR;
  5883. typedef struct _EISA_PORT_CONFIGURATION {
  5884. EISA_PORT_DESCRIPTOR Configuration;
  5885. USHORT PortAddress;
  5886. } EISA_PORT_CONFIGURATION, *PEISA_PORT_CONFIGURATION;
  5887. //
  5888. // Eisa slot information definition
  5889. // N.B. This structure is different from the one defined
  5890. // in ARC eisa addendum.
  5891. //
  5892. typedef struct _CM_EISA_SLOT_INFORMATION {
  5893. UCHAR ReturnCode;
  5894. UCHAR ReturnFlags;
  5895. UCHAR MajorRevision;
  5896. UCHAR MinorRevision;
  5897. USHORT Checksum;
  5898. UCHAR NumberFunctions;
  5899. UCHAR FunctionInformation;
  5900. ULONG CompressedId;
  5901. } CM_EISA_SLOT_INFORMATION, *PCM_EISA_SLOT_INFORMATION;
  5902. //
  5903. // Eisa function information definition
  5904. //
  5905. typedef struct _CM_EISA_FUNCTION_INFORMATION {
  5906. ULONG CompressedId;
  5907. UCHAR IdSlotFlags1;
  5908. UCHAR IdSlotFlags2;
  5909. UCHAR MinorRevision;
  5910. UCHAR MajorRevision;
  5911. UCHAR Selections[26];
  5912. UCHAR FunctionFlags;
  5913. UCHAR TypeString[80];
  5914. EISA_MEMORY_CONFIGURATION EisaMemory[9];
  5915. EISA_IRQ_CONFIGURATION EisaIrq[7];
  5916. EISA_DMA_CONFIGURATION EisaDma[4];
  5917. EISA_PORT_CONFIGURATION EisaPort[20];
  5918. UCHAR InitializationData[60];
  5919. } CM_EISA_FUNCTION_INFORMATION, *PCM_EISA_FUNCTION_INFORMATION;
  5920. //
  5921. // The followings define the way pnp bios information is stored in
  5922. // the registry \\HKEY_LOCAL_MACHINE\HARDWARE\Description\System\
  5923. // MultifunctionAdapter\x key, where x is an integer number indicating
  5924. // adapter instance. The "Identifier" of the key must equal to "PNP BIOS"
  5925. // and the "ConfigurationData" is organized as follow:
  5926. //
  5927. // CM_PNP_BIOS_INSTALLATION_CHECK +
  5928. // CM_PNP_BIOS_DEVICE_NODE for device 1 +
  5929. // CM_PNP_BIOS_DEVICE_NODE for device 2 +
  5930. // ...
  5931. // CM_PNP_BIOS_DEVICE_NODE for device n
  5932. //
  5933. //
  5934. // Pnp BIOS device node structure
  5935. //
  5936. typedef struct _CM_PNP_BIOS_DEVICE_NODE {
  5937. USHORT Size;
  5938. UCHAR Node;
  5939. ULONG ProductId;
  5940. UCHAR DeviceType[3];
  5941. USHORT DeviceAttributes;
  5942. // followed by AllocatedResourceBlock, PossibleResourceBlock
  5943. // and CompatibleDeviceId
  5944. } CM_PNP_BIOS_DEVICE_NODE,*PCM_PNP_BIOS_DEVICE_NODE;
  5945. //
  5946. // Pnp BIOS Installation check
  5947. //
  5948. typedef struct _CM_PNP_BIOS_INSTALLATION_CHECK {
  5949. UCHAR Signature[4]; // $PnP (ascii)
  5950. UCHAR Revision;
  5951. UCHAR Length;
  5952. USHORT ControlField;
  5953. UCHAR Checksum;
  5954. ULONG EventFlagAddress; // Physical address
  5955. USHORT RealModeEntryOffset;
  5956. USHORT RealModeEntrySegment;
  5957. USHORT ProtectedModeEntryOffset;
  5958. ULONG ProtectedModeCodeBaseAddress;
  5959. ULONG OemDeviceId;
  5960. USHORT RealModeDataBaseAddress;
  5961. ULONG ProtectedModeDataBaseAddress;
  5962. } CM_PNP_BIOS_INSTALLATION_CHECK, *PCM_PNP_BIOS_INSTALLATION_CHECK;
  5963. #include "poppack.h"
  5964. //
  5965. // Masks for EISA function information
  5966. //
  5967. #define EISA_FUNCTION_ENABLED 0x80
  5968. #define EISA_FREE_FORM_DATA 0x40
  5969. #define EISA_HAS_PORT_INIT_ENTRY 0x20
  5970. #define EISA_HAS_PORT_RANGE 0x10
  5971. #define EISA_HAS_DMA_ENTRY 0x08
  5972. #define EISA_HAS_IRQ_ENTRY 0x04
  5973. #define EISA_HAS_MEMORY_ENTRY 0x02
  5974. #define EISA_HAS_TYPE_ENTRY 0x01
  5975. #define EISA_HAS_INFORMATION EISA_HAS_PORT_RANGE + \
  5976. EISA_HAS_DMA_ENTRY + \
  5977. EISA_HAS_IRQ_ENTRY + \
  5978. EISA_HAS_MEMORY_ENTRY + \
  5979. EISA_HAS_TYPE_ENTRY
  5980. //
  5981. // Masks for EISA memory configuration
  5982. //
  5983. #define EISA_MORE_ENTRIES 0x80
  5984. #define EISA_SYSTEM_MEMORY 0x00
  5985. #define EISA_MEMORY_TYPE_RAM 0x01
  5986. //
  5987. // Returned error code for EISA bios call
  5988. //
  5989. #define EISA_INVALID_SLOT 0x80
  5990. #define EISA_INVALID_FUNCTION 0x81
  5991. #define EISA_INVALID_CONFIGURATION 0x82
  5992. #define EISA_EMPTY_SLOT 0x83
  5993. #define EISA_INVALID_BIOS_CALL 0x86
  5994. // end_ntminiport end_ntndis
  5995. //
  5996. // The following structures are used to interpret mips
  5997. // DeviceSpecificData of CM_PARTIAL_RESOURCE_DESCRIPTOR.
  5998. //
  5999. //
  6000. // Device data records for adapters.
  6001. //
  6002. //
  6003. // The device data record for the Emulex SCSI controller.
  6004. //
  6005. typedef struct _CM_SCSI_DEVICE_DATA {
  6006. USHORT Version;
  6007. USHORT Revision;
  6008. UCHAR HostIdentifier;
  6009. } CM_SCSI_DEVICE_DATA, *PCM_SCSI_DEVICE_DATA;
  6010. //
  6011. // Device data records for controllers.
  6012. //
  6013. //
  6014. // The device data record for the Video controller.
  6015. //
  6016. typedef struct _CM_VIDEO_DEVICE_DATA {
  6017. USHORT Version;
  6018. USHORT Revision;
  6019. ULONG VideoClock;
  6020. } CM_VIDEO_DEVICE_DATA, *PCM_VIDEO_DEVICE_DATA;
  6021. //
  6022. // The device data record for the SONIC network controller.
  6023. //
  6024. typedef struct _CM_SONIC_DEVICE_DATA {
  6025. USHORT Version;
  6026. USHORT Revision;
  6027. USHORT DataConfigurationRegister;
  6028. UCHAR EthernetAddress[8];
  6029. } CM_SONIC_DEVICE_DATA, *PCM_SONIC_DEVICE_DATA;
  6030. //
  6031. // The device data record for the serial controller.
  6032. //
  6033. typedef struct _CM_SERIAL_DEVICE_DATA {
  6034. USHORT Version;
  6035. USHORT Revision;
  6036. ULONG BaudClock;
  6037. } CM_SERIAL_DEVICE_DATA, *PCM_SERIAL_DEVICE_DATA;
  6038. //
  6039. // Device data records for peripherals.
  6040. //
  6041. //
  6042. // The device data record for the Monitor peripheral.
  6043. //
  6044. typedef struct _CM_MONITOR_DEVICE_DATA {
  6045. USHORT Version;
  6046. USHORT Revision;
  6047. USHORT HorizontalScreenSize;
  6048. USHORT VerticalScreenSize;
  6049. USHORT HorizontalResolution;
  6050. USHORT VerticalResolution;
  6051. USHORT HorizontalDisplayTimeLow;
  6052. USHORT HorizontalDisplayTime;
  6053. USHORT HorizontalDisplayTimeHigh;
  6054. USHORT HorizontalBackPorchLow;
  6055. USHORT HorizontalBackPorch;
  6056. USHORT HorizontalBackPorchHigh;
  6057. USHORT HorizontalFrontPorchLow;
  6058. USHORT HorizontalFrontPorch;
  6059. USHORT HorizontalFrontPorchHigh;
  6060. USHORT HorizontalSyncLow;
  6061. USHORT HorizontalSync;
  6062. USHORT HorizontalSyncHigh;
  6063. USHORT VerticalBackPorchLow;
  6064. USHORT VerticalBackPorch;
  6065. USHORT VerticalBackPorchHigh;
  6066. USHORT VerticalFrontPorchLow;
  6067. USHORT VerticalFrontPorch;
  6068. USHORT VerticalFrontPorchHigh;
  6069. USHORT VerticalSyncLow;
  6070. USHORT VerticalSync;
  6071. USHORT VerticalSyncHigh;
  6072. } CM_MONITOR_DEVICE_DATA, *PCM_MONITOR_DEVICE_DATA;
  6073. //
  6074. // The device data record for the Floppy peripheral.
  6075. //
  6076. typedef struct _CM_FLOPPY_DEVICE_DATA {
  6077. USHORT Version;
  6078. USHORT Revision;
  6079. CHAR Size[8];
  6080. ULONG MaxDensity;
  6081. ULONG MountDensity;
  6082. //
  6083. // New data fields for version >= 2.0
  6084. //
  6085. UCHAR StepRateHeadUnloadTime;
  6086. UCHAR HeadLoadTime;
  6087. UCHAR MotorOffTime;
  6088. UCHAR SectorLengthCode;
  6089. UCHAR SectorPerTrack;
  6090. UCHAR ReadWriteGapLength;
  6091. UCHAR DataTransferLength;
  6092. UCHAR FormatGapLength;
  6093. UCHAR FormatFillCharacter;
  6094. UCHAR HeadSettleTime;
  6095. UCHAR MotorSettleTime;
  6096. UCHAR MaximumTrackValue;
  6097. UCHAR DataTransferRate;
  6098. } CM_FLOPPY_DEVICE_DATA, *PCM_FLOPPY_DEVICE_DATA;
  6099. //
  6100. // The device data record for the Keyboard peripheral.
  6101. // The KeyboardFlags is defined (by x86 BIOS INT 16h, function 02) as:
  6102. // bit 7 : Insert on
  6103. // bit 6 : Caps Lock on
  6104. // bit 5 : Num Lock on
  6105. // bit 4 : Scroll Lock on
  6106. // bit 3 : Alt Key is down
  6107. // bit 2 : Ctrl Key is down
  6108. // bit 1 : Left shift key is down
  6109. // bit 0 : Right shift key is down
  6110. //
  6111. typedef struct _CM_KEYBOARD_DEVICE_DATA {
  6112. USHORT Version;
  6113. USHORT Revision;
  6114. UCHAR Type;
  6115. UCHAR Subtype;
  6116. USHORT KeyboardFlags;
  6117. } CM_KEYBOARD_DEVICE_DATA, *PCM_KEYBOARD_DEVICE_DATA;
  6118. //
  6119. // Declaration of the structure for disk geometries
  6120. //
  6121. typedef struct _CM_DISK_GEOMETRY_DEVICE_DATA {
  6122. ULONG BytesPerSector;
  6123. ULONG NumberOfCylinders;
  6124. ULONG SectorsPerTrack;
  6125. ULONG NumberOfHeads;
  6126. } CM_DISK_GEOMETRY_DEVICE_DATA, *PCM_DISK_GEOMETRY_DEVICE_DATA;
  6127. // begin_ntminiport
  6128. //
  6129. // Defines Resource Options
  6130. //
  6131. #define IO_RESOURCE_PREFERRED 0x01
  6132. #define IO_RESOURCE_DEFAULT 0x02
  6133. #define IO_RESOURCE_ALTERNATIVE 0x08
  6134. //
  6135. // This structure defines one type of resource requested by the driver
  6136. //
  6137. typedef struct _IO_RESOURCE_DESCRIPTOR {
  6138. UCHAR Option;
  6139. UCHAR Type; // use CM_RESOURCE_TYPE
  6140. UCHAR ShareDisposition; // use CM_SHARE_DISPOSITION
  6141. UCHAR Spare1;
  6142. USHORT Flags; // use CM resource flag defines
  6143. USHORT Spare2; // align
  6144. union {
  6145. struct {
  6146. ULONG Length;
  6147. ULONG Alignment;
  6148. PHYSICAL_ADDRESS MinimumAddress;
  6149. PHYSICAL_ADDRESS MaximumAddress;
  6150. } Port;
  6151. struct {
  6152. ULONG Length;
  6153. ULONG Alignment;
  6154. PHYSICAL_ADDRESS MinimumAddress;
  6155. PHYSICAL_ADDRESS MaximumAddress;
  6156. } Memory;
  6157. struct {
  6158. ULONG MinimumVector;
  6159. ULONG MaximumVector;
  6160. } Interrupt;
  6161. struct {
  6162. ULONG MinimumChannel;
  6163. ULONG MaximumChannel;
  6164. } Dma;
  6165. } u;
  6166. } IO_RESOURCE_DESCRIPTOR, *PIO_RESOURCE_DESCRIPTOR;
  6167. // end_ntminiport
  6168. typedef struct _IO_RESOURCE_LIST {
  6169. USHORT Version;
  6170. USHORT Revision;
  6171. ULONG Count;
  6172. IO_RESOURCE_DESCRIPTOR Descriptors[1];
  6173. } IO_RESOURCE_LIST, *PIO_RESOURCE_LIST;
  6174. typedef struct _IO_RESOURCE_REQUIREMENTS_LIST {
  6175. ULONG ListSize;
  6176. INTERFACE_TYPE InterfaceType;
  6177. ULONG BusNumber;
  6178. ULONG SlotNumber;
  6179. ULONG Reserved[3];
  6180. ULONG AlternativeLists;
  6181. IO_RESOURCE_LIST List[1];
  6182. } IO_RESOURCE_REQUIREMENTS_LIST, *PIO_RESOURCE_REQUIREMENTS_LIST;
  6183. //
  6184. // Exception flag definitions.
  6185. //
  6186. // begin_winnt
  6187. #define EXCEPTION_NONCONTINUABLE 0x1 // Noncontinuable exception
  6188. // end_winnt
  6189. //
  6190. // Define maximum number of exception parameters.
  6191. //
  6192. // begin_winnt
  6193. #define EXCEPTION_MAXIMUM_PARAMETERS 15 // maximum number of exception parameters
  6194. //
  6195. // Exception record definition.
  6196. //
  6197. typedef struct _EXCEPTION_RECORD {
  6198. /*lint -e18 */ // Don't complain about different definitions
  6199. NTSTATUS ExceptionCode;
  6200. /*lint +e18 */ // Resume checking for different definitions
  6201. ULONG ExceptionFlags;
  6202. struct _EXCEPTION_RECORD *ExceptionRecord;
  6203. PVOID ExceptionAddress;
  6204. ULONG NumberParameters;
  6205. ULONG ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
  6206. } EXCEPTION_RECORD;
  6207. typedef EXCEPTION_RECORD *PEXCEPTION_RECORD;
  6208. //
  6209. // Typedef for pointer returned by exception_info()
  6210. //
  6211. typedef struct _EXCEPTION_POINTERS {
  6212. PEXCEPTION_RECORD ExceptionRecord;
  6213. PCONTEXT ContextRecord;
  6214. } EXCEPTION_POINTERS, *PEXCEPTION_POINTERS;
  6215. // end_winnt
  6216. //
  6217. // Define configuration routine types.
  6218. //
  6219. // Configuration information.
  6220. //
  6221. typedef enum _CONFIGURATION_TYPE {
  6222. ArcSystem,
  6223. CentralProcessor,
  6224. FloatingPointProcessor,
  6225. PrimaryIcache,
  6226. PrimaryDcache,
  6227. SecondaryIcache,
  6228. SecondaryDcache,
  6229. SecondaryCache,
  6230. EisaAdapter,
  6231. TcAdapter,
  6232. ScsiAdapter,
  6233. DtiAdapter,
  6234. MultiFunctionAdapter,
  6235. DiskController,
  6236. TapeController,
  6237. CdromController,
  6238. WormController,
  6239. SerialController,
  6240. NetworkController,
  6241. DisplayController,
  6242. ParallelController,
  6243. PointerController,
  6244. KeyboardController,
  6245. AudioController,
  6246. OtherController,
  6247. DiskPeripheral,
  6248. FloppyDiskPeripheral,
  6249. TapePeripheral,
  6250. ModemPeripheral,
  6251. MonitorPeripheral,
  6252. PrinterPeripheral,
  6253. PointerPeripheral,
  6254. KeyboardPeripheral,
  6255. TerminalPeripheral,
  6256. OtherPeripheral,
  6257. LinePeripheral,
  6258. NetworkPeripheral,
  6259. SystemMemory,
  6260. MaximumType
  6261. } CONFIGURATION_TYPE, *PCONFIGURATION_TYPE;
  6262. #define THREAD_WAIT_OBJECTS 3 // Builtin usable wait blocks
  6263. //
  6264. // Interrupt modes.
  6265. //
  6266. typedef enum _KINTERRUPT_MODE {
  6267. LevelSensitive,
  6268. Latched
  6269. } KINTERRUPT_MODE;
  6270. //
  6271. // Wait reasons
  6272. //
  6273. typedef enum _KWAIT_REASON {
  6274. Executive,
  6275. FreePage,
  6276. PageIn,
  6277. PoolAllocation,
  6278. DelayExecution,
  6279. Suspended,
  6280. UserRequest,
  6281. WrExecutive,
  6282. WrFreePage,
  6283. WrPageIn,
  6284. WrPoolAllocation,
  6285. WrDelayExecution,
  6286. WrSuspended,
  6287. WrUserRequest,
  6288. WrEventPair,
  6289. WrQueue,
  6290. WrLpcReceive,
  6291. WrLpcReply,
  6292. WrVirtualMemory,
  6293. WrPageOut,
  6294. WrRendezvous,
  6295. Spare2,
  6296. Spare3,
  6297. Spare4,
  6298. Spare5,
  6299. Spare6,
  6300. WrKernel,
  6301. MaximumWaitReason
  6302. } KWAIT_REASON;
  6303. //
  6304. // Common dispatcher object header
  6305. //
  6306. // N.B. The size field contains the number of dwords in the structure.
  6307. //
  6308. typedef struct _DISPATCHER_HEADER {
  6309. UCHAR Type;
  6310. UCHAR Absolute;
  6311. UCHAR Size;
  6312. UCHAR Inserted;
  6313. LONG SignalState;
  6314. LIST_ENTRY WaitListHead;
  6315. } DISPATCHER_HEADER;
  6316. typedef struct _KWAIT_BLOCK {
  6317. LIST_ENTRY WaitListEntry;
  6318. struct _KTHREAD *RESTRICTED_POINTER Thread;
  6319. PVOID Object;
  6320. struct _KWAIT_BLOCK *RESTRICTED_POINTER NextWaitBlock;
  6321. USHORT WaitKey;
  6322. USHORT WaitType;
  6323. } KWAIT_BLOCK, *PKWAIT_BLOCK, *RESTRICTED_POINTER PRKWAIT_BLOCK;
  6324. //
  6325. // Thread start function
  6326. //
  6327. typedef
  6328. VOID
  6329. (*PKSTART_ROUTINE) (
  6330. IN PVOID StartContext
  6331. );
  6332. //
  6333. // Kernel object structure definitions
  6334. //
  6335. //
  6336. // Device Queue object and entry
  6337. //
  6338. typedef struct _KDEVICE_QUEUE {
  6339. CSHORT Type;
  6340. CSHORT Size;
  6341. LIST_ENTRY DeviceListHead;
  6342. KSPIN_LOCK Lock;
  6343. BOOLEAN Busy;
  6344. } KDEVICE_QUEUE, *PKDEVICE_QUEUE, *RESTRICTED_POINTER PRKDEVICE_QUEUE;
  6345. typedef struct _KDEVICE_QUEUE_ENTRY {
  6346. LIST_ENTRY DeviceListEntry;
  6347. ULONG SortKey;
  6348. BOOLEAN Inserted;
  6349. } KDEVICE_QUEUE_ENTRY, *PKDEVICE_QUEUE_ENTRY, *RESTRICTED_POINTER PRKDEVICE_QUEUE_ENTRY;
  6350. // begin_ntndis
  6351. //
  6352. // Event object
  6353. //
  6354. typedef struct _KEVENT {
  6355. DISPATCHER_HEADER Header;
  6356. } KEVENT, *PKEVENT, *RESTRICTED_POINTER PRKEVENT;
  6357. //
  6358. // Define the interrupt service function type and the empty struct
  6359. // type.
  6360. //
  6361. typedef
  6362. BOOLEAN
  6363. (*PKSERVICE_ROUTINE) (
  6364. IN struct _KINTERRUPT *Interrupt,
  6365. IN PVOID ServiceContext
  6366. );
  6367. //
  6368. // Mutant object
  6369. //
  6370. typedef struct _KMUTANT {
  6371. DISPATCHER_HEADER Header;
  6372. LIST_ENTRY MutantListEntry;
  6373. struct _KTHREAD *RESTRICTED_POINTER OwnerThread;
  6374. BOOLEAN Abandoned;
  6375. UCHAR ApcDisable;
  6376. } KMUTANT, *PKMUTANT, *RESTRICTED_POINTER PRKMUTANT, KMUTEX, *PKMUTEX, *RESTRICTED_POINTER PRKMUTEX;
  6377. //
  6378. //
  6379. // Semaphore object
  6380. //
  6381. typedef struct _KSEMAPHORE {
  6382. DISPATCHER_HEADER Header;
  6383. LONG Limit;
  6384. } KSEMAPHORE, *PKSEMAPHORE, *RESTRICTED_POINTER PRKSEMAPHORE;
  6385. // begin_ntndis
  6386. //
  6387. // Timer object
  6388. //
  6389. typedef struct _KTIMER {
  6390. DISPATCHER_HEADER Header;
  6391. ULARGE_INTEGER DueTime;
  6392. LIST_ENTRY TimerListEntry;
  6393. struct _KDPC *Dpc;
  6394. LONG Period;
  6395. } KTIMER, *PKTIMER, *RESTRICTED_POINTER PRKTIMER;
  6396. //
  6397. // DPC object
  6398. //
  6399. NTKERNELAPI
  6400. VOID
  6401. KeInitializeDpc (
  6402. IN PRKDPC Dpc,
  6403. IN PKDEFERRED_ROUTINE DeferredRoutine,
  6404. IN PVOID DeferredContext
  6405. );
  6406. NTKERNELAPI
  6407. BOOLEAN
  6408. KeInsertQueueDpc (
  6409. IN PRKDPC Dpc,
  6410. IN PVOID SystemArgument1,
  6411. IN PVOID SystemArgument2
  6412. );
  6413. NTKERNELAPI
  6414. BOOLEAN
  6415. KeRemoveQueueDpc (
  6416. IN PRKDPC Dpc
  6417. );
  6418. NTKERNELAPI
  6419. VOID
  6420. KeSetImportanceDpc (
  6421. IN PRKDPC Dpc,
  6422. IN KDPC_IMPORTANCE Importance
  6423. );
  6424. //
  6425. // Device queue object
  6426. //
  6427. NTKERNELAPI
  6428. VOID
  6429. KeInitializeDeviceQueue (
  6430. IN PKDEVICE_QUEUE DeviceQueue
  6431. );
  6432. NTKERNELAPI
  6433. BOOLEAN
  6434. KeInsertDeviceQueue (
  6435. IN PKDEVICE_QUEUE DeviceQueue,
  6436. IN PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
  6437. );
  6438. NTKERNELAPI
  6439. BOOLEAN
  6440. KeInsertByKeyDeviceQueue (
  6441. IN PKDEVICE_QUEUE DeviceQueue,
  6442. IN PKDEVICE_QUEUE_ENTRY DeviceQueueEntry,
  6443. IN ULONG SortKey
  6444. );
  6445. NTKERNELAPI
  6446. PKDEVICE_QUEUE_ENTRY
  6447. KeRemoveDeviceQueue (
  6448. IN PKDEVICE_QUEUE DeviceQueue
  6449. );
  6450. NTKERNELAPI
  6451. PKDEVICE_QUEUE_ENTRY
  6452. KeRemoveByKeyDeviceQueue (
  6453. IN PKDEVICE_QUEUE DeviceQueue,
  6454. IN ULONG SortKey
  6455. );
  6456. NTKERNELAPI
  6457. BOOLEAN
  6458. KeRemoveEntryDeviceQueue (
  6459. IN PKDEVICE_QUEUE DeviceQueue,
  6460. IN PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
  6461. );
  6462. NTKERNELAPI
  6463. BOOLEAN
  6464. KeSynchronizeExecution (
  6465. IN PKINTERRUPT Interrupt,
  6466. IN PKSYNCHRONIZE_ROUTINE SynchronizeRoutine,
  6467. IN PVOID SynchronizeContext
  6468. );
  6469. //
  6470. // Kernel dispatcher object functions
  6471. //
  6472. // Event Object
  6473. //
  6474. NTKERNELAPI
  6475. VOID
  6476. KeInitializeEvent (
  6477. IN PRKEVENT Event,
  6478. IN EVENT_TYPE Type,
  6479. IN BOOLEAN State
  6480. );
  6481. NTKERNELAPI
  6482. VOID
  6483. KeClearEvent (
  6484. IN PRKEVENT Event
  6485. );
  6486. NTKERNELAPI
  6487. LONG
  6488. KeResetEvent (
  6489. IN PRKEVENT Event
  6490. );
  6491. NTKERNELAPI
  6492. LONG
  6493. KeSetEvent (
  6494. IN PRKEVENT Event,
  6495. IN KPRIORITY Increment,
  6496. IN BOOLEAN Wait
  6497. );
  6498. //
  6499. // Mutex object
  6500. //
  6501. NTKERNELAPI
  6502. VOID
  6503. KeInitializeMutex (
  6504. IN PRKMUTEX Mutex,
  6505. IN ULONG Level
  6506. );
  6507. #define KeReadStateMutex(Mutex) KeReadStateMutant(Mutex)
  6508. NTKERNELAPI
  6509. LONG
  6510. KeReleaseMutex (
  6511. IN PRKMUTEX Mutex,
  6512. IN BOOLEAN Wait
  6513. );
  6514. //
  6515. // Semaphore object
  6516. //
  6517. NTKERNELAPI
  6518. VOID
  6519. KeInitializeSemaphore (
  6520. IN PRKSEMAPHORE Semaphore,
  6521. IN LONG Count,
  6522. IN LONG Limit
  6523. );
  6524. NTKERNELAPI
  6525. LONG
  6526. KeReadStateSemaphore (
  6527. IN PRKSEMAPHORE Semaphore
  6528. );
  6529. NTKERNELAPI
  6530. LONG
  6531. KeReleaseSemaphore (
  6532. IN PRKSEMAPHORE Semaphore,
  6533. IN KPRIORITY Increment,
  6534. IN LONG Adjustment,
  6535. IN BOOLEAN Wait
  6536. );
  6537. NTKERNELAPI
  6538. NTSTATUS
  6539. KeDelayExecutionThread (
  6540. IN KPROCESSOR_MODE WaitMode,
  6541. IN BOOLEAN Alertable,
  6542. IN PLARGE_INTEGER Interval
  6543. );
  6544. //
  6545. // Timer object
  6546. //
  6547. NTKERNELAPI
  6548. VOID
  6549. KeInitializeTimer (
  6550. IN PKTIMER Timer
  6551. );
  6552. NTKERNELAPI
  6553. BOOLEAN
  6554. KeCancelTimer (
  6555. IN PKTIMER
  6556. );
  6557. NTKERNELAPI
  6558. BOOLEAN
  6559. KeReadStateTimer (
  6560. PKTIMER Timer
  6561. );
  6562. NTKERNELAPI
  6563. BOOLEAN
  6564. KeSetTimer (
  6565. IN PKTIMER Timer,
  6566. IN LARGE_INTEGER DueTime,
  6567. IN PKDPC Dpc OPTIONAL
  6568. );
  6569. #define KeWaitForMutexObject KeWaitForSingleObject
  6570. NTKERNELAPI
  6571. NTSTATUS
  6572. KeWaitForSingleObject (
  6573. IN PVOID Object,
  6574. IN KWAIT_REASON WaitReason,
  6575. IN KPROCESSOR_MODE WaitMode,
  6576. IN BOOLEAN Alertable,
  6577. IN PLARGE_INTEGER Timeout OPTIONAL
  6578. );
  6579. //
  6580. // spin lock functions
  6581. //
  6582. NTKERNELAPI
  6583. VOID
  6584. NTAPI
  6585. KeInitializeSpinLock (
  6586. IN PKSPIN_LOCK SpinLock
  6587. );
  6588. #if defined(_X86_)
  6589. NTKERNELAPI
  6590. VOID
  6591. FASTCALL
  6592. KefAcquireSpinLockAtDpcLevel (
  6593. IN PKSPIN_LOCK SpinLock
  6594. );
  6595. NTKERNELAPI
  6596. VOID
  6597. FASTCALL
  6598. KefReleaseSpinLockFromDpcLevel (
  6599. IN PKSPIN_LOCK SpinLock
  6600. );
  6601. #define KeAcquireSpinLockAtDpcLevel(a) KefAcquireSpinLockAtDpcLevel(a)
  6602. #define KeReleaseSpinLockFromDpcLevel(a) KefReleaseSpinLockFromDpcLevel(a)
  6603. #else
  6604. NTKERNELAPI
  6605. VOID
  6606. KeAcquireSpinLockAtDpcLevel (
  6607. IN PKSPIN_LOCK SpinLock
  6608. );
  6609. NTKERNELAPI
  6610. VOID
  6611. KeReleaseSpinLockFromDpcLevel (
  6612. IN PKSPIN_LOCK SpinLock
  6613. );
  6614. #endif
  6615. #if defined(_X86_)
  6616. __declspec(dllimport)
  6617. KIRQL
  6618. FASTCALL
  6619. KfAcquireSpinLock (
  6620. IN PKSPIN_LOCK SpinLock
  6621. );
  6622. __declspec(dllimport)
  6623. VOID
  6624. FASTCALL
  6625. KfReleaseSpinLock (
  6626. IN PKSPIN_LOCK SpinLock,
  6627. IN KIRQL NewIrql
  6628. );
  6629. #define KeAcquireSpinLock(a,b) *(b) = KfAcquireSpinLock(a)
  6630. #define KeReleaseSpinLock(a,b) KfReleaseSpinLock(a,b)
  6631. #else
  6632. __declspec(dllimport)
  6633. KIRQL
  6634. KeAcquireSpinLockRaiseToDpc (
  6635. IN PKSPIN_LOCK SpinLock
  6636. );
  6637. #define KeAcquireSpinLock(SpinLock, OldIrql) \
  6638. *(OldIrql) = KeAcquireSpinLockRaiseToDpc(SpinLock)
  6639. __declspec(dllimport)
  6640. VOID
  6641. KeReleaseSpinLock (
  6642. IN PKSPIN_LOCK SpinLock,
  6643. IN KIRQL NewIrql
  6644. );
  6645. #endif
  6646. #if defined(_X86_)
  6647. __declspec(dllimport)
  6648. VOID
  6649. FASTCALL
  6650. KfLowerIrql (
  6651. IN KIRQL NewIrql
  6652. );
  6653. __declspec(dllimport)
  6654. KIRQL
  6655. FASTCALL
  6656. KfRaiseIrql (
  6657. IN KIRQL NewIrql
  6658. );
  6659. #define KeLowerIrql(a) KfLowerIrql(a)
  6660. #define KeRaiseIrql(a,b) *(b) = KfRaiseIrql(a)
  6661. #elif defined(_MIPS_)
  6662. __declspec(dllimport)
  6663. KIRQL
  6664. KeSwapIrql (
  6665. IN KIRQL NewIrql
  6666. );
  6667. #define KeLowerIrql(NewIrql) KeSwapIrql(NewIrql)
  6668. #define KeRaiseIrql(NewIrql, OldIrql) *(OldIrql) = KeSwapIrql(NewIrql)
  6669. #elif defined(_PPC_)
  6670. __declspec(dllimport)
  6671. VOID
  6672. KeLowerIrql (
  6673. IN KIRQL NewIrql
  6674. );
  6675. __declspec(dllimport)
  6676. VOID
  6677. KeRaiseIrql (
  6678. IN KIRQL NewIrql,
  6679. OUT PKIRQL OldIrql
  6680. );
  6681. #elif defined(_ALPHA_)
  6682. #define KeLowerIrql(a) __swpirql(a)
  6683. #define KeRaiseIrql(a,b) *(b) = __swpirql(a)
  6684. #endif
  6685. //
  6686. // Miscellaneous kernel functions
  6687. //
  6688. typedef enum _KBUGCHECK_BUFFER_DUMP_STATE {
  6689. BufferEmpty,
  6690. BufferInserted,
  6691. BufferStarted,
  6692. BufferFinished,
  6693. BufferIncomplete
  6694. } KBUGCHECK_BUFFER_DUMP_STATE;
  6695. typedef
  6696. VOID
  6697. (*PKBUGCHECK_CALLBACK_ROUTINE) (
  6698. IN PVOID Buffer,
  6699. IN ULONG Length
  6700. );
  6701. typedef struct _KBUGCHECK_CALLBACK_RECORD {
  6702. LIST_ENTRY Entry;
  6703. PKBUGCHECK_CALLBACK_ROUTINE CallbackRoutine;
  6704. PVOID Buffer;
  6705. ULONG Length;
  6706. PUCHAR Component;
  6707. ULONG Checksum;
  6708. UCHAR State;
  6709. } KBUGCHECK_CALLBACK_RECORD, *PKBUGCHECK_CALLBACK_RECORD;
  6710. NTKERNELAPI
  6711. VOID
  6712. KeBugCheckEx(
  6713. IN ULONG BugCheckCode,
  6714. IN ULONG BugCheckParameter1,
  6715. IN ULONG BugCheckParameter2,
  6716. IN ULONG BugCheckParameter3,
  6717. IN ULONG BugCheckParameter4
  6718. );
  6719. #define KeInitializeCallbackRecord(CallbackRecord) \
  6720. (CallbackRecord)->State = BufferEmpty
  6721. NTKERNELAPI
  6722. VOID
  6723. KeQuerySystemTime (
  6724. OUT PLARGE_INTEGER CurrentTime
  6725. );
  6726. NTKERNELAPI
  6727. ULONG
  6728. KeQueryTimeIncrement (
  6729. VOID
  6730. );
  6731. //
  6732. // Context swap notify routine.
  6733. //
  6734. typedef
  6735. VOID
  6736. (FASTCALL *PSWAP_CONTEXT_NOTIFY_ROUTINE)(
  6737. IN HANDLE OldThreadId,
  6738. IN HANDLE NewThreadId
  6739. );
  6740. //
  6741. // Time update notify routine.
  6742. //
  6743. typedef
  6744. VOID
  6745. (FASTCALL *PTIME_UPDATE_NOTIFY_ROUTINE)(
  6746. IN HANDLE ThreadId,
  6747. IN KPROCESSOR_MODE Mode
  6748. );
  6749. extern volatile KSYSTEM_TIME KeTickCount;
  6750. typedef enum _MEMORY_CACHING_TYPE {
  6751. MmNonCached = FALSE,
  6752. MmCached = TRUE,
  6753. MmFrameBufferCached,
  6754. MmHardwareCoherentCached,
  6755. MmMaximumCacheType
  6756. } MEMORY_CACHING_TYPE;
  6757. //
  6758. // Define external data.
  6759. //
  6760. extern BOOLEAN KdDebuggerNotPresent;
  6761. extern BOOLEAN KdDebuggerEnabled;
  6762. //
  6763. // Pool Allocation routines (in pool.c)
  6764. //
  6765. typedef enum _POOL_TYPE {
  6766. NonPagedPool,
  6767. PagedPool,
  6768. NonPagedPoolMustSucceed,
  6769. DontUseThisType,
  6770. NonPagedPoolCacheAligned,
  6771. PagedPoolCacheAligned,
  6772. NonPagedPoolCacheAlignedMustS,
  6773. MaxPoolType
  6774. } POOL_TYPE;
  6775. NTKERNELAPI
  6776. PVOID
  6777. ExAllocatePool(
  6778. IN POOL_TYPE PoolType,
  6779. IN ULONG NumberOfBytes
  6780. );
  6781. NTKERNELAPI
  6782. PVOID
  6783. ExAllocatePoolWithTag(
  6784. IN POOL_TYPE PoolType,
  6785. IN ULONG NumberOfBytes,
  6786. IN ULONG Tag
  6787. );
  6788. #ifndef POOL_TAGGING
  6789. #define ExAllocatePoolWithTag(a,b,c) ExAllocatePool(a,b)
  6790. #endif //POOL_TAGGING
  6791. NTKERNELAPI
  6792. VOID
  6793. NTAPI
  6794. ExFreePool(
  6795. IN PVOID P
  6796. );
  6797. //
  6798. // Routines to support fast mutexes.
  6799. //
  6800. typedef struct _FAST_MUTEX {
  6801. LONG Count;
  6802. PKTHREAD Owner;
  6803. ULONG Contention;
  6804. KEVENT Event;
  6805. ULONG OldIrql;
  6806. } FAST_MUTEX, *PFAST_MUTEX;
  6807. #if DBG
  6808. #define ExInitializeFastMutex(_FastMutex) \
  6809. (_FastMutex)->Count = 1; \
  6810. (_FastMutex)->Owner = NULL; \
  6811. (_FastMutex)->Contention = 0; \
  6812. KeInitializeEvent(&(_FastMutex)->Event, \
  6813. SynchronizationEvent, \
  6814. FALSE);
  6815. #else
  6816. #define ExInitializeFastMutex(_FastMutex) \
  6817. (_FastMutex)->Count = 1; \
  6818. (_FastMutex)->Contention = 0; \
  6819. KeInitializeEvent(&(_FastMutex)->Event, \
  6820. SynchronizationEvent, \
  6821. FALSE);
  6822. #endif // DBG
  6823. NTKERNELAPI
  6824. VOID
  6825. FASTCALL
  6826. ExAcquireFastMutexUnsafe (
  6827. IN PFAST_MUTEX FastMutex
  6828. );
  6829. NTKERNELAPI
  6830. VOID
  6831. FASTCALL
  6832. ExReleaseFastMutexUnsafe (
  6833. IN PFAST_MUTEX FastMutex
  6834. );
  6835. #if defined(_MIPS_) || defined(_ALPHA_) || defined(_PPC_) || (defined(_X86_) && defined(_NTHAL_))
  6836. NTKERNELAPI
  6837. VOID
  6838. FASTCALL
  6839. ExAcquireFastMutex (
  6840. IN PFAST_MUTEX FastMutex
  6841. );
  6842. NTKERNELAPI
  6843. VOID
  6844. FASTCALL
  6845. ExReleaseFastMutex (
  6846. IN PFAST_MUTEX FastMutex
  6847. );
  6848. #elif defined(_X86_) && !defined(_NTHAL_)
  6849. __declspec(dllimport)
  6850. VOID
  6851. FASTCALL
  6852. ExAcquireFastMutex (
  6853. IN PFAST_MUTEX FastMutex
  6854. );
  6855. __declspec(dllimport)
  6856. VOID
  6857. FASTCALL
  6858. ExReleaseFastMutex (
  6859. IN PFAST_MUTEX FastMutex
  6860. );
  6861. #elif
  6862. #error "Target architecture not defined"
  6863. #endif
  6864. //
  6865. NTKERNELAPI
  6866. VOID
  6867. FASTCALL
  6868. ExInterlockedAddLargeStatistic (
  6869. IN PLARGE_INTEGER Addend,
  6870. IN ULONG Increment
  6871. );
  6872. NTKERNELAPI
  6873. ULONG
  6874. FASTCALL
  6875. ExInterlockedAddUlong (
  6876. IN PULONG Addend,
  6877. IN ULONG Increment,
  6878. IN PKSPIN_LOCK Lock
  6879. );
  6880. NTKERNELAPI
  6881. PLIST_ENTRY
  6882. FASTCALL
  6883. ExInterlockedInsertHeadList (
  6884. IN PLIST_ENTRY ListHead,
  6885. IN PLIST_ENTRY ListEntry,
  6886. IN PKSPIN_LOCK Lock
  6887. );
  6888. NTKERNELAPI
  6889. PLIST_ENTRY
  6890. FASTCALL
  6891. ExInterlockedInsertTailList (
  6892. IN PLIST_ENTRY ListHead,
  6893. IN PLIST_ENTRY ListEntry,
  6894. IN PKSPIN_LOCK Lock
  6895. );
  6896. NTKERNELAPI
  6897. PLIST_ENTRY
  6898. FASTCALL
  6899. ExInterlockedRemoveHeadList (
  6900. IN PLIST_ENTRY ListHead,
  6901. IN PKSPIN_LOCK Lock
  6902. );
  6903. NTKERNELAPI
  6904. PSINGLE_LIST_ENTRY
  6905. FASTCALL
  6906. ExInterlockedPopEntryList (
  6907. IN PSINGLE_LIST_ENTRY ListHead,
  6908. IN PKSPIN_LOCK Lock
  6909. );
  6910. NTKERNELAPI
  6911. PSINGLE_LIST_ENTRY
  6912. FASTCALL
  6913. ExInterlockedPushEntryList (
  6914. IN PSINGLE_LIST_ENTRY ListHead,
  6915. IN PSINGLE_LIST_ENTRY ListEntry,
  6916. IN PKSPIN_LOCK Lock
  6917. );
  6918. //
  6919. // Define interlocked sequenced listhead functions.
  6920. //
  6921. // A sequenced interlocked list is a singly linked list with a header that
  6922. // contains the current depth and a sequence number. Each time an entry is
  6923. // inserted or removed from the list the depth is updated and the sequence
  6924. // number is incremented. This enables MIPS, Alpha, and Pentium and later
  6925. // machines to insert and remove from the list without the use of spinlocks.
  6926. // The PowerPc, however, must use a spinlock to synchronize access to the
  6927. // list.
  6928. //
  6929. // N.B. A spinlock must be specified with SLIST operations. However, it may
  6930. // not actually be used.
  6931. //
  6932. /*++
  6933. VOID
  6934. ExInitializeSListHead (
  6935. IN PSLIST_HEADER SListHead
  6936. )
  6937. Routine Description:
  6938. This function initializes a sequenced singly linked listhead.
  6939. Arguments:
  6940. SListHead - Supplies a pointer to a sequenced singly linked listhead.
  6941. Return Value:
  6942. None.
  6943. --*/
  6944. #define ExInitializeSListHead(_listhead_) \
  6945. (_listhead_)->Next.Next = NULL; \
  6946. (_listhead_)->Depth = 0; \
  6947. (_listhead_)->Sequence = 0
  6948. /*++
  6949. USHORT
  6950. ExQueryDepthSListHead (
  6951. IN PSLIST_HEADERT SListHead
  6952. )
  6953. Routine Description:
  6954. This function queries the current number of entries contained in a
  6955. sequenced single linked list.
  6956. Arguments:
  6957. SListHead - Supplies a pointer to the sequenced listhead which is
  6958. be queried.
  6959. Return Value:
  6960. The current number of entries in the sequenced singly linked list is
  6961. returned as the function value.
  6962. --*/
  6963. #define ExQueryDepthSList(_listhead_) (_listhead_)->Depth
  6964. #if defined(_MIPS_) || defined(_ALPHA_)
  6965. #define ExQueryDepthSList(_listhead_) (_listhead_)->Depth
  6966. NTKERNELAPI
  6967. PSINGLE_LIST_ENTRY
  6968. ExpInterlockedPopEntrySList (
  6969. IN PSLIST_HEADER ListHead
  6970. );
  6971. NTKERNELAPI
  6972. PSINGLE_LIST_ENTRY
  6973. ExpInterlockedPushEntrySList (
  6974. IN PSLIST_HEADER ListHead,
  6975. IN PSINGLE_LIST_ENTRY ListEntry
  6976. );
  6977. #endif
  6978. //
  6979. // Worker Thread
  6980. //
  6981. typedef enum _WORK_QUEUE_TYPE {
  6982. CriticalWorkQueue,
  6983. DelayedWorkQueue,
  6984. HyperCriticalWorkQueue,
  6985. MaximumWorkQueue
  6986. } WORK_QUEUE_TYPE;
  6987. typedef
  6988. VOID
  6989. (*PWORKER_THREAD_ROUTINE)(
  6990. IN PVOID Parameter
  6991. );
  6992. typedef struct _WORK_QUEUE_ITEM {
  6993. LIST_ENTRY List;
  6994. PWORKER_THREAD_ROUTINE WorkerRoutine;
  6995. PVOID Parameter;
  6996. } WORK_QUEUE_ITEM, *PWORK_QUEUE_ITEM;
  6997. #define ExInitializeWorkItem(Item, Routine, Context) \
  6998. (Item)->WorkerRoutine = (Routine); \
  6999. (Item)->Parameter = (Context); \
  7000. (Item)->List.Flink = NULL;
  7001. NTKERNELAPI
  7002. VOID
  7003. ExQueueWorkItem(
  7004. IN PWORK_QUEUE_ITEM WorkItem,
  7005. IN WORK_QUEUE_TYPE QueueType
  7006. );
  7007. //
  7008. // Raise status from kernel mode.
  7009. //
  7010. NTKERNELAPI
  7011. VOID
  7012. NTAPI
  7013. ExRaiseStatus (
  7014. IN NTSTATUS Status
  7015. );
  7016. //
  7017. // Define the type for Callback function.
  7018. //
  7019. typedef struct _CALLBACK_OBJECT *PCALLBACK_OBJECT;
  7020. typedef VOID (*PCALLBACK_FUNCTION ) (
  7021. IN PVOID CallbackContext,
  7022. IN PVOID Argument1,
  7023. IN PVOID Argument2
  7024. );
  7025. NTKERNELAPI
  7026. NTSTATUS
  7027. ExCreateCallback (
  7028. OUT PCALLBACK_OBJECT *CallbackObject,
  7029. IN POBJECT_ATTRIBUTES ObjectAttributes,
  7030. IN BOOLEAN Create,
  7031. IN BOOLEAN AllowMultipleCallbacks
  7032. );
  7033. NTKERNELAPI
  7034. PVOID
  7035. ExRegisterCallback (
  7036. IN PCALLBACK_OBJECT CallbackObject,
  7037. IN PCALLBACK_FUNCTION CallbackFunction,
  7038. IN PVOID CallbackContext
  7039. );
  7040. NTKERNELAPI
  7041. VOID
  7042. ExUnregisterCallback (
  7043. IN PVOID CallbackRegistration
  7044. );
  7045. NTKERNELAPI
  7046. VOID
  7047. ExNotifyCallback (
  7048. IN PVOID CallbackObject,
  7049. IN PVOID Argument1,
  7050. IN PVOID Argument2
  7051. );
  7052. //
  7053. // Priority increment definitions. The comment for each definition gives
  7054. // the names of the system services that use the definition when satisfying
  7055. // a wait.
  7056. //
  7057. //
  7058. // Priority increment used when satisfying a wait on an executive event
  7059. // (NtPulseEvent and NtSetEvent)
  7060. //
  7061. #define EVENT_INCREMENT 1
  7062. //
  7063. // Priority increment when no I/O has been done. This is used by device
  7064. // and file system drivers when completing an IRP (IoCompleteRequest).
  7065. //
  7066. #define IO_NO_INCREMENT 0
  7067. //
  7068. // Priority increment for completing CD-ROM I/O. This is used by CD-ROM device
  7069. // and file system drivers when completing an IRP (IoCompleteRequest)
  7070. //
  7071. #define IO_CD_ROM_INCREMENT 1
  7072. //
  7073. // Priority increment for completing disk I/O. This is used by disk device
  7074. // and file system drivers when completing an IRP (IoCompleteRequest)
  7075. //
  7076. #define IO_DISK_INCREMENT 1
  7077. //
  7078. // Priority increment for completing keyboard I/O. This is used by keyboard
  7079. // device drivers when completing an IRP (IoCompleteRequest)
  7080. //
  7081. #define IO_KEYBOARD_INCREMENT 6
  7082. //
  7083. // Priority increment for completing mailslot I/O. This is used by the mail-
  7084. // slot file system driver when completing an IRP (IoCompleteRequest).
  7085. //
  7086. #define IO_MAILSLOT_INCREMENT 2
  7087. //
  7088. // Priority increment for completing mouse I/O. This is used by mouse device
  7089. // drivers when completing an IRP (IoCompleteRequest)
  7090. //
  7091. #define IO_MOUSE_INCREMENT 6
  7092. //
  7093. // Priority increment for completing named pipe I/O. This is used by the
  7094. // named pipe file system driver when completing an IRP (IoCompleteRequest).
  7095. //
  7096. #define IO_NAMED_PIPE_INCREMENT 2
  7097. //
  7098. // Priority increment for completing network I/O. This is used by network
  7099. // device and network file system drivers when completing an IRP
  7100. // (IoCompleteRequest).
  7101. //
  7102. #define IO_NETWORK_INCREMENT 2
  7103. //
  7104. // Priority increment for completing parallel I/O. This is used by parallel
  7105. // device drivers when completing an IRP (IoCompleteRequest)
  7106. //
  7107. #define IO_PARALLEL_INCREMENT 1
  7108. //
  7109. // Priority increment for completing serial I/O. This is used by serial device
  7110. // drivers when completing an IRP (IoCompleteRequest)
  7111. //
  7112. #define IO_SERIAL_INCREMENT 2
  7113. //
  7114. // Priority increment for completing sound I/O. This is used by sound device
  7115. // drivers when completing an IRP (IoCompleteRequest)
  7116. //
  7117. #define IO_SOUND_INCREMENT 8
  7118. //
  7119. // Priority increment for completing video I/O. This is used by video device
  7120. // drivers when completing an IRP (IoCompleteRequest)
  7121. //
  7122. #define IO_VIDEO_INCREMENT 1
  7123. //
  7124. // Priority increment used when satisfying a wait on an executive semaphore
  7125. // (NtReleaseSemaphore)
  7126. //
  7127. #define SEMAPHORE_INCREMENT 1
  7128. //
  7129. // Define maximum disk transfer size to be used by MM and Cache Manager,
  7130. // so that packet-oriented disk drivers can optimize their packet allocation
  7131. // to this size.
  7132. //
  7133. #define MM_MAXIMUM_DISK_IO_SIZE (0x10000)
  7134. //++
  7135. //
  7136. // ULONG
  7137. // ROUND_TO_PAGES (
  7138. // IN ULONG Size
  7139. // )
  7140. //
  7141. // Routine Description:
  7142. //
  7143. // The ROUND_TO_PAGES macro takes a size in bytes and rounds it up to a
  7144. // multiple of the page size.
  7145. //
  7146. // NOTE: This macro fails for values 0xFFFFFFFF - (PAGE_SIZE - 1).
  7147. //
  7148. // Arguments:
  7149. //
  7150. // Size - Size in bytes to round up to a page multiple.
  7151. //
  7152. // Return Value:
  7153. //
  7154. // Returns the size rounded up to a multiple of the page size.
  7155. //
  7156. //--
  7157. #define ROUND_TO_PAGES(Size) (((ULONG)(Size) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
  7158. //++
  7159. //
  7160. // ULONG
  7161. // BYTES_TO_PAGES (
  7162. // IN ULONG Size
  7163. // )
  7164. //
  7165. // Routine Description:
  7166. //
  7167. // The BYTES_TO_PAGES macro takes the size in bytes and calculates the
  7168. // number of pages required to contain the bytes.
  7169. //
  7170. // Arguments:
  7171. //
  7172. // Size - Size in bytes.
  7173. //
  7174. // Return Value:
  7175. //
  7176. // Returns the number of pages required to contain the specified size.
  7177. //
  7178. //--
  7179. #define BYTES_TO_PAGES(Size) (((ULONG)(Size) >> PAGE_SHIFT) + \
  7180. (((ULONG)(Size) & (PAGE_SIZE - 1)) != 0))
  7181. //++
  7182. //
  7183. // ULONG
  7184. // BYTE_OFFSET (
  7185. // IN PVOID Va
  7186. // )
  7187. //
  7188. // Routine Description:
  7189. //
  7190. // The BYTE_OFFSET macro takes a virtual address and returns the byte offset
  7191. // of that address within the page.
  7192. //
  7193. // Arguments:
  7194. //
  7195. // Va - Virtual address.
  7196. //
  7197. // Return Value:
  7198. //
  7199. // Returns the byte offset portion of the virtual address.
  7200. //
  7201. //--
  7202. #define BYTE_OFFSET(Va) ((ULONG)(Va) & (PAGE_SIZE - 1))
  7203. //++
  7204. //
  7205. // PVOID
  7206. // PAGE_ALIGN (
  7207. // IN PVOID Va
  7208. // )
  7209. //
  7210. // Routine Description:
  7211. //
  7212. // The PAGE_ALIGN macro takes a virtual address and returns a page-aligned
  7213. // virtual address for that page.
  7214. //
  7215. // Arguments:
  7216. //
  7217. // Va - Virtual address.
  7218. //
  7219. // Return Value:
  7220. //
  7221. // Returns the page aligned virtual address.
  7222. //
  7223. //--
  7224. #define PAGE_ALIGN(Va) ((PVOID)((ULONG)(Va) & ~(PAGE_SIZE - 1)))
  7225. //++
  7226. //
  7227. // ULONG
  7228. // ADDRESS_AND_SIZE_TO_SPAN_PAGES (
  7229. // IN PVOID Va,
  7230. // IN ULONG Size
  7231. // )
  7232. //
  7233. // Routine Description:
  7234. //
  7235. // The ADDRESS_AND_SIZE_TO_SPAN_PAGES macro takes a virtual address and
  7236. // size and returns the number of pages spanned by the size.
  7237. //
  7238. // Arguments:
  7239. //
  7240. // Va - Virtual address.
  7241. //
  7242. // Size - Size in bytes.
  7243. //
  7244. // Return Value:
  7245. //
  7246. // Returns the number of pages spanned by the size.
  7247. //
  7248. //--
  7249. #define ADDRESS_AND_SIZE_TO_SPAN_PAGES(Va,Size) \
  7250. ((((ULONG)((ULONG)(Size) - 1L) >> PAGE_SHIFT) + \
  7251. (((((ULONG)(Size-1)&(PAGE_SIZE-1)) + ((ULONG)Va & (PAGE_SIZE -1)))) >> PAGE_SHIFT)) + 1L)
  7252. #define COMPUTE_PAGES_SPANNED(Va, Size) \
  7253. ((((ULONG)Va & (PAGE_SIZE -1)) + (Size) + (PAGE_SIZE - 1)) >> PAGE_SHIFT)
  7254. //++
  7255. //
  7256. // PVOID
  7257. // MmGetMdlVirtualAddress (
  7258. // IN PMDL Mdl
  7259. // )
  7260. //
  7261. // Routine Description:
  7262. //
  7263. // The MmGetMdlVirtualAddress returns the virual address of the buffer
  7264. // described by the Mdl.
  7265. //
  7266. // Arguments:
  7267. //
  7268. // Mdl - Pointer to an MDL.
  7269. //
  7270. // Return Value:
  7271. //
  7272. // Returns the virtual address of the buffer described by the Mdl
  7273. //
  7274. //--
  7275. #define MmGetMdlVirtualAddress(Mdl) ((PVOID) ((PCHAR) (Mdl)->StartVa + (Mdl)->ByteOffset))
  7276. //++
  7277. //
  7278. // ULONG
  7279. // MmGetMdlByteCount (
  7280. // IN PMDL Mdl
  7281. // )
  7282. //
  7283. // Routine Description:
  7284. //
  7285. // The MmGetMdlByteCount returns the length in bytes of the buffer
  7286. // described by the Mdl.
  7287. //
  7288. // Arguments:
  7289. //
  7290. // Mdl - Pointer to an MDL.
  7291. //
  7292. // Return Value:
  7293. //
  7294. // Returns the byte count of the buffer described by the Mdl
  7295. //
  7296. //--
  7297. #define MmGetMdlByteCount(Mdl) ((Mdl)->ByteCount)
  7298. //++
  7299. //
  7300. // ULONG
  7301. // MmGetMdlByteOffset (
  7302. // IN PMDL Mdl
  7303. // )
  7304. //
  7305. // Routine Description:
  7306. //
  7307. // The MmGetMdlByteOffset returns the byte offset within the page
  7308. // of the buffer described by the Mdl.
  7309. //
  7310. // Arguments:
  7311. //
  7312. // Mdl - Pointer to an MDL.
  7313. //
  7314. // Return Value:
  7315. //
  7316. // Returns the byte offset within the page of the buffer described by the Mdl
  7317. //
  7318. //--
  7319. #define MmGetMdlByteOffset(Mdl) ((Mdl)->ByteOffset)
  7320. typedef enum _MM_SYSTEM_SIZE {
  7321. MmSmallSystem,
  7322. MmMediumSystem,
  7323. MmLargeSystem
  7324. } MM_SYSTEMSIZE;
  7325. NTKERNELAPI
  7326. MM_SYSTEMSIZE
  7327. MmQuerySystemSize(
  7328. VOID
  7329. );
  7330. typedef enum _LOCK_OPERATION {
  7331. IoReadAccess,
  7332. IoWriteAccess,
  7333. IoModifyAccess
  7334. } LOCK_OPERATION;
  7335. //
  7336. // I/O support routines.
  7337. //
  7338. NTKERNELAPI
  7339. VOID
  7340. MmProbeAndLockPages (
  7341. IN OUT PMDL MemoryDescriptorList,
  7342. IN KPROCESSOR_MODE AccessMode,
  7343. IN LOCK_OPERATION Operation
  7344. );
  7345. NTKERNELAPI
  7346. VOID
  7347. MmUnlockPages (
  7348. IN PMDL MemoryDescriptorList
  7349. );
  7350. NTKERNELAPI
  7351. VOID
  7352. MmBuildMdlForNonPagedPool (
  7353. IN OUT PMDL MemoryDescriptorList
  7354. );
  7355. NTKERNELAPI
  7356. PVOID
  7357. MmMapLockedPages (
  7358. IN PMDL MemoryDescriptorList,
  7359. IN KPROCESSOR_MODE AccessMode
  7360. );
  7361. NTKERNELAPI
  7362. VOID
  7363. MmUnmapLockedPages (
  7364. IN PVOID BaseAddress,
  7365. IN PMDL MemoryDescriptorList
  7366. );
  7367. NTKERNELAPI
  7368. PVOID
  7369. MmMapIoSpace (
  7370. IN PHYSICAL_ADDRESS PhysicalAddress,
  7371. IN ULONG NumberOfBytes,
  7372. IN MEMORY_CACHING_TYPE CacheType
  7373. );
  7374. NTKERNELAPI
  7375. VOID
  7376. MmUnmapIoSpace (
  7377. IN PVOID BaseAddress,
  7378. IN ULONG NumberOfBytes
  7379. );
  7380. NTKERNELAPI
  7381. PHYSICAL_ADDRESS
  7382. MmGetPhysicalAddress (
  7383. IN PVOID BaseAddress
  7384. );
  7385. NTKERNELAPI
  7386. PVOID
  7387. MmAllocateContiguousMemory (
  7388. IN ULONG NumberOfBytes,
  7389. IN PHYSICAL_ADDRESS HighestAcceptableAddress
  7390. );
  7391. NTKERNELAPI
  7392. VOID
  7393. MmFreeContiguousMemory (
  7394. IN PVOID BaseAddress
  7395. );
  7396. NTKERNELAPI
  7397. ULONG
  7398. MmSizeOfMdl(
  7399. IN PVOID Base,
  7400. IN ULONG Length
  7401. );
  7402. NTKERNELAPI
  7403. PMDL
  7404. MmCreateMdl(
  7405. IN PMDL MemoryDescriptorList OPTIONAL,
  7406. IN PVOID Base,
  7407. IN ULONG Length
  7408. );
  7409. NTKERNELAPI
  7410. PVOID
  7411. MmLockPagableDataSection(
  7412. IN PVOID AddressWithinSection
  7413. );
  7414. NTKERNELAPI
  7415. VOID
  7416. MmUnlockPagableImageSection(
  7417. IN PVOID ImageSectionHandle
  7418. );
  7419. //++
  7420. //
  7421. // VOID
  7422. // MmInitializeMdl (
  7423. // IN PMDL MemoryDescriptorList,
  7424. // IN PVOID BaseVa,
  7425. // IN ULONG Length
  7426. // )
  7427. //
  7428. // Routine Description:
  7429. //
  7430. // This routine initializes the header of a Memory Descriptor List (MDL).
  7431. //
  7432. // Arguments:
  7433. //
  7434. // MemoryDescriptorList - Pointer to the MDL to initialize.
  7435. //
  7436. // BaseVa - Base virtual address mapped by the MDL.
  7437. //
  7438. // Length - Length, in bytes, of the buffer mapped by the MDL.
  7439. //
  7440. // Return Value:
  7441. //
  7442. // None.
  7443. //
  7444. //--
  7445. #define MmInitializeMdl(MemoryDescriptorList, BaseVa, Length) { \
  7446. (MemoryDescriptorList)->Next = (PMDL) NULL; \
  7447. (MemoryDescriptorList)->Size = (CSHORT)(sizeof(MDL) + \
  7448. (sizeof(ULONG) * ADDRESS_AND_SIZE_TO_SPAN_PAGES((BaseVa), (Length)))); \
  7449. (MemoryDescriptorList)->MdlFlags = 0; \
  7450. (MemoryDescriptorList)->StartVa = (PVOID) PAGE_ALIGN((BaseVa)); \
  7451. (MemoryDescriptorList)->ByteOffset = BYTE_OFFSET((BaseVa)); \
  7452. (MemoryDescriptorList)->ByteCount = (Length); \
  7453. }
  7454. //++
  7455. //
  7456. // PVOID
  7457. // MmGetSystemAddressForMdl (
  7458. // IN PMDL MDL
  7459. // )
  7460. //
  7461. // Routine Description:
  7462. //
  7463. // This routine returns the mapped address of an MDL, if the
  7464. // Mdl is not already mapped or a system address, it is mapped.
  7465. //
  7466. // Arguments:
  7467. //
  7468. // MemoryDescriptorList - Pointer to the MDL to map.
  7469. //
  7470. // Return Value:
  7471. //
  7472. // Returns the base address where the pages are mapped. The base address
  7473. // has the same offset as the virtual address in the MDL.
  7474. //
  7475. //--
  7476. //#define MmGetSystemAddressForMdl(MDL)
  7477. // (((MDL)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA)) ?
  7478. // ((MDL)->MappedSystemVa) :
  7479. // ((((MDL)->MdlFlags & (MDL_SOURCE_IS_NONPAGED_POOL)) ?
  7480. // ((PVOID)((ULONG)(MDL)->StartVa | (MDL)->ByteOffset)) :
  7481. // (MmMapLockedPages((MDL),KernelMode)))))
  7482. #define MmGetSystemAddressForMdl(MDL) \
  7483. (((MDL)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA | \
  7484. MDL_SOURCE_IS_NONPAGED_POOL)) ? \
  7485. ((MDL)->MappedSystemVa) : \
  7486. (MmMapLockedPages((MDL),KernelMode)))
  7487. //++
  7488. //
  7489. // VOID
  7490. // MmPrepareMdlForReuse (
  7491. // IN PMDL MDL
  7492. // )
  7493. //
  7494. // Routine Description:
  7495. //
  7496. // This routine will take all of the steps necessary to allow an MDL to be
  7497. // re-used.
  7498. //
  7499. // Arguments:
  7500. //
  7501. // MemoryDescriptorList - Pointer to the MDL that will be re-used.
  7502. //
  7503. // Return Value:
  7504. //
  7505. // None.
  7506. //
  7507. //--
  7508. #define MmPrepareMdlForReuse(MDL) \
  7509. if (((MDL)->MdlFlags & MDL_PARTIAL_HAS_BEEN_MAPPED) != 0) { \
  7510. ASSERT(((MDL)->MdlFlags & MDL_PARTIAL) != 0); \
  7511. MmUnmapLockedPages( (MDL)->MappedSystemVa, (MDL) ); \
  7512. } else if (((MDL)->MdlFlags & MDL_PARTIAL) == 0) { \
  7513. ASSERT(((MDL)->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA) == 0); \
  7514. }
  7515. //
  7516. // Security operation codes
  7517. //
  7518. typedef enum _SECURITY_OPERATION_CODE {
  7519. SetSecurityDescriptor,
  7520. QuerySecurityDescriptor,
  7521. DeleteSecurityDescriptor,
  7522. AssignSecurityDescriptor
  7523. } SECURITY_OPERATION_CODE, *PSECURITY_OPERATION_CODE;
  7524. //
  7525. // Data structure used to capture subject security context
  7526. // for access validations and auditing.
  7527. //
  7528. // THE FIELDS OF THIS DATA STRUCTURE SHOULD BE CONSIDERED OPAQUE
  7529. // BY ALL EXCEPT THE SECURITY ROUTINES.
  7530. //
  7531. typedef struct _SECURITY_SUBJECT_CONTEXT {
  7532. PACCESS_TOKEN ClientToken;
  7533. SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
  7534. PACCESS_TOKEN PrimaryToken;
  7535. PVOID ProcessAuditId;
  7536. } SECURITY_SUBJECT_CONTEXT, *PSECURITY_SUBJECT_CONTEXT;
  7537. ///////////////////////////////////////////////////////////////////////////////
  7538. // //
  7539. // ACCESS_STATE and related structures //
  7540. // //
  7541. ///////////////////////////////////////////////////////////////////////////////
  7542. //
  7543. // Initial Privilege Set - Room for three privileges, which should
  7544. // be enough for most applications. This structure exists so that
  7545. // it can be imbedded in an ACCESS_STATE structure. Use PRIVILEGE_SET
  7546. // for all other references to Privilege sets.
  7547. //
  7548. #define INITIAL_PRIVILEGE_COUNT 3
  7549. typedef struct _INITIAL_PRIVILEGE_SET {
  7550. ULONG PrivilegeCount;
  7551. ULONG Control;
  7552. LUID_AND_ATTRIBUTES Privilege[INITIAL_PRIVILEGE_COUNT];
  7553. } INITIAL_PRIVILEGE_SET, * PINITIAL_PRIVILEGE_SET;
  7554. //
  7555. // Combine the information that describes the state
  7556. // of an access-in-progress into a single structure
  7557. //
  7558. typedef struct _ACCESS_STATE {
  7559. LUID OperationID;
  7560. BOOLEAN SecurityEvaluated;
  7561. BOOLEAN GenerateAudit;
  7562. BOOLEAN GenerateOnClose;
  7563. BOOLEAN PrivilegesAllocated;
  7564. ULONG Flags;
  7565. ACCESS_MASK RemainingDesiredAccess;
  7566. ACCESS_MASK PreviouslyGrantedAccess;
  7567. ACCESS_MASK OriginalDesiredAccess;
  7568. SECURITY_SUBJECT_CONTEXT SubjectSecurityContext;
  7569. PSECURITY_DESCRIPTOR SecurityDescriptor;
  7570. PVOID AuxData;
  7571. union {
  7572. INITIAL_PRIVILEGE_SET InitialPrivilegeSet;
  7573. PRIVILEGE_SET PrivilegeSet;
  7574. } Privileges;
  7575. BOOLEAN AuditPrivileges;
  7576. UNICODE_STRING ObjectName;
  7577. UNICODE_STRING ObjectTypeName;
  7578. } ACCESS_STATE, *PACCESS_STATE;
  7579. NTKERNELAPI
  7580. NTSTATUS
  7581. SeAssignSecurity (
  7582. IN PSECURITY_DESCRIPTOR ParentDescriptor OPTIONAL,
  7583. IN PSECURITY_DESCRIPTOR ExplicitDescriptor,
  7584. OUT PSECURITY_DESCRIPTOR *NewDescriptor,
  7585. IN BOOLEAN IsDirectoryObject,
  7586. IN PSECURITY_SUBJECT_CONTEXT SubjectContext,
  7587. IN PGENERIC_MAPPING GenericMapping,
  7588. IN POOL_TYPE PoolType
  7589. );
  7590. NTKERNELAPI
  7591. NTSTATUS
  7592. SeDeassignSecurity (
  7593. IN OUT PSECURITY_DESCRIPTOR *SecurityDescriptor
  7594. );
  7595. //
  7596. // Define I/O system data structure type codes. Each major data structure in
  7597. // the I/O system has a type code The type field in each structure is at the
  7598. // same offset. The following values can be used to determine which type of
  7599. // data structure a pointer refers to.
  7600. //
  7601. #define IO_TYPE_ADAPTER 0x00000001
  7602. #define IO_TYPE_CONTROLLER 0x00000002
  7603. #define IO_TYPE_DEVICE 0x00000003
  7604. #define IO_TYPE_DRIVER 0x00000004
  7605. #define IO_TYPE_FILE 0x00000005
  7606. #define IO_TYPE_IRP 0x00000006
  7607. #define IO_TYPE_MASTER_ADAPTER 0x00000007
  7608. #define IO_TYPE_OPEN_PACKET 0x00000008
  7609. #define IO_TYPE_TIMER 0x00000009
  7610. #define IO_TYPE_VPB 0x0000000a
  7611. #define IO_TYPE_ERROR_LOG 0x0000000b
  7612. #define IO_TYPE_ERROR_MESSAGE 0x0000000c
  7613. #define IO_TYPE_DEVICE_OBJECT_EXTENSION 0x0000000d
  7614. //
  7615. // Define the major function codes for IRPs. The lower 128 codes, from 0x00 to
  7616. // 0x7f are reserved to Microsoft. The upper 128 codes, from 0x80 to 0xff, are
  7617. // reserved to customers of Microsoft.
  7618. //
  7619. #define IRP_MJ_CREATE 0x00
  7620. #define IRP_MJ_CREATE_NAMED_PIPE 0x01
  7621. #define IRP_MJ_CLOSE 0x02
  7622. #define IRP_MJ_READ 0x03
  7623. #define IRP_MJ_WRITE 0x04
  7624. #define IRP_MJ_QUERY_INFORMATION 0x05
  7625. #define IRP_MJ_SET_INFORMATION 0x06
  7626. #define IRP_MJ_QUERY_EA 0x07
  7627. #define IRP_MJ_SET_EA 0x08
  7628. #define IRP_MJ_FLUSH_BUFFERS 0x09
  7629. #define IRP_MJ_QUERY_VOLUME_INFORMATION 0x0a
  7630. #define IRP_MJ_SET_VOLUME_INFORMATION 0x0b
  7631. #define IRP_MJ_DIRECTORY_CONTROL 0x0c
  7632. #define IRP_MJ_FILE_SYSTEM_CONTROL 0x0d
  7633. #define IRP_MJ_DEVICE_CONTROL 0x0e
  7634. #define IRP_MJ_INTERNAL_DEVICE_CONTROL 0x0f
  7635. #define IRP_MJ_SHUTDOWN 0x10
  7636. #define IRP_MJ_LOCK_CONTROL 0x11
  7637. #define IRP_MJ_CLEANUP 0x12
  7638. #define IRP_MJ_CREATE_MAILSLOT 0x13
  7639. #define IRP_MJ_QUERY_SECURITY 0x14
  7640. #define IRP_MJ_SET_SECURITY 0x15
  7641. #define IRP_MJ_QUERY_POWER 0x16
  7642. #define IRP_MJ_NOT_DEFINED 0x17 // available
  7643. #define IRP_MJ_DEVICE_CHANGE 0x18
  7644. #define IRP_MJ_QUERY_QUOTA 0x19
  7645. #define IRP_MJ_SET_QUOTA 0x1a
  7646. #define IRP_MJ_PNP_POWER 0x1b
  7647. #define IRP_MJ_MAXIMUM_FUNCTION 0x1b
  7648. //
  7649. // Make the Scsi major code the same as internal device control.
  7650. //
  7651. #define IRP_MJ_SCSI IRP_MJ_INTERNAL_DEVICE_CONTROL
  7652. //
  7653. // Define the minor function codes for IRPs. The lower 128 codes, from 0x00 to
  7654. // 0x7f are reserved to Microsoft. The upper 128 codes, from 0x80 to 0xff, are
  7655. // reserved to customers of Microsoft.
  7656. //
  7657. //
  7658. // Directory control minor function codes
  7659. //
  7660. #define IRP_MN_QUERY_DIRECTORY 0x01
  7661. #define IRP_MN_NOTIFY_CHANGE_DIRECTORY 0x02
  7662. #define IRP_MN_QUERY_OLE_DIRECTORY 0x03
  7663. //
  7664. // File system control minor function codes. Note that "user request" is
  7665. // assumed to be zero by both the I/O system and file systems. Do not change
  7666. // this value.
  7667. //
  7668. #define IRP_MN_USER_FS_REQUEST 0x00
  7669. #define IRP_MN_MOUNT_VOLUME 0x01
  7670. #define IRP_MN_VERIFY_VOLUME 0x02
  7671. #define IRP_MN_LOAD_FILE_SYSTEM 0x03
  7672. //
  7673. // Lock control minor function codes
  7674. //
  7675. #define IRP_MN_LOCK 0x01
  7676. #define IRP_MN_UNLOCK_SINGLE 0x02
  7677. #define IRP_MN_UNLOCK_ALL 0x03
  7678. #define IRP_MN_UNLOCK_ALL_BY_KEY 0x04
  7679. //
  7680. // Read and Write minor function codes for file systems supporting Lan Manager
  7681. // software. All of these subfunction codes are invalid if the file has been
  7682. // opened with FO_NO_INTERMEDIATE_BUFFERING. They are also invalid in combi-
  7683. // nation with synchronous calls (Irp Flag or file open option).
  7684. //
  7685. // Note that "normal" is assumed to be zero by both the I/O system and file
  7686. // systems. Do not change this value.
  7687. //
  7688. #define IRP_MN_NORMAL 0x00
  7689. #define IRP_MN_DPC 0x01
  7690. #define IRP_MN_MDL 0x02
  7691. #define IRP_MN_COMPLETE 0x04
  7692. #define IRP_MN_COMPRESSED 0x08
  7693. #define IRP_MN_MDL_DPC (IRP_MN_MDL | IRP_MN_DPC)
  7694. #define IRP_MN_COMPLETE_MDL (IRP_MN_COMPLETE | IRP_MN_MDL)
  7695. #define IRP_MN_COMPLETE_MDL_DPC (IRP_MN_COMPLETE_MDL | IRP_MN_DPC)
  7696. //
  7697. // Device Control Request minor function codes for SCSI support. Note that
  7698. // user requests are assumed to be zero.
  7699. //
  7700. #define IRP_MN_SCSI_CLASS 0x01
  7701. //
  7702. // PNP/Power minor function codes.
  7703. //
  7704. #define IRP_MN_START_DEVICE 0x00
  7705. #define IRP_MN_QUERY_REMOVE_DEVICE 0x01
  7706. #define IRP_MN_REMOVE_DEVICE 0x02
  7707. #define IRP_MN_CANCEL_REMOVE_DEVICE 0x03
  7708. #define IRP_MN_STOP_DEVICE 0x04
  7709. #define IRP_MN_QUERY_STOP_DEVICE 0x05
  7710. #define IRP_MN_CANCEL_STOP_DEVICE 0x06
  7711. #define IRP_MN_QUERY_DEVICE_RELATIONS 0x07
  7712. #define IRP_MN_QUERY_INTERFACE 0x08
  7713. #define IRP_MN_QUERY_CAPABILITIES 0x09
  7714. #define IRP_MN_QUERY_RESOURCES 0x0A
  7715. #define IRP_MN_QUERY_RESOURCE_REQUIREMENTS 0x0B
  7716. #define IRP_MN_SET_RESOURCE_REQUIREMENTS 0x0C
  7717. #define IRP_MN_ADJUST_RESORUCES 0x0D
  7718. #define IRP_MN_SET_DEVICE_RESOURCES 0x0E
  7719. #define IRP_MN_READ_CONFIG 0x0F
  7720. #define IRP_MN_WRITE_CONFIG 0x10
  7721. #define IRP_MN_EJECT 0x11
  7722. #define IRP_MN_SET_LOCK 0x12
  7723. #define IRP_MN_QUERY_ID 0x13
  7724. #define IRP_MN_PNP_DEVICE_STATE 0x14
  7725. #define IRP_MN_WAIT_WAKE 0x15
  7726. #define IRP_MN_POWER_SEQUENCE 0x16
  7727. #define IRP_MN_SET_POWER 0x17
  7728. #define IRP_MN_QUERY_POWER 0x18
  7729. //
  7730. // Define option flags for IoCreateFile. Note that these values must be
  7731. // exactly the same as the SL_... flags for a create function. Note also
  7732. // that there are flags that may be passed to IoCreateFile that are not
  7733. // placed in the stack location for the create IRP. These flags start in
  7734. // the next byte.
  7735. //
  7736. #define IO_FORCE_ACCESS_CHECK 0x0001
  7737. #define IO_OPEN_PAGING_FILE 0x0002
  7738. #define IO_OPEN_TARGET_DIRECTORY 0x0004
  7739. //
  7740. // Define callout routine type for use in IoQueryDeviceDescription().
  7741. //
  7742. typedef NTSTATUS (*PIO_QUERY_DEVICE_ROUTINE)(
  7743. IN PVOID Context,
  7744. IN PUNICODE_STRING PathName,
  7745. IN INTERFACE_TYPE BusType,
  7746. IN ULONG BusNumber,
  7747. IN PKEY_VALUE_FULL_INFORMATION *BusInformation,
  7748. IN CONFIGURATION_TYPE ControllerType,
  7749. IN ULONG ControllerNumber,
  7750. IN PKEY_VALUE_FULL_INFORMATION *ControllerInformation,
  7751. IN CONFIGURATION_TYPE PeripheralType,
  7752. IN ULONG PeripheralNumber,
  7753. IN PKEY_VALUE_FULL_INFORMATION *PeripheralInformation
  7754. );
  7755. //
  7756. // Defines the order of the information in the array of
  7757. // PKEY_VALUE_FULL_INFORMATION.
  7758. //
  7759. typedef enum _IO_QUERY_DEVICE_DATA_FORMAT {
  7760. IoQueryDeviceIdentifier = 0,
  7761. IoQueryDeviceConfigurationData,
  7762. IoQueryDeviceComponentInformation,
  7763. IoQueryDeviceMaxData
  7764. } IO_QUERY_DEVICE_DATA_FORMAT, *PIO_QUERY_DEVICE_DATA_FORMAT;
  7765. //
  7766. // Define the objects that can be created by IoCreateFile.
  7767. //
  7768. typedef enum _CREATE_FILE_TYPE {
  7769. CreateFileTypeNone,
  7770. CreateFileTypeNamedPipe,
  7771. CreateFileTypeMailslot
  7772. } CREATE_FILE_TYPE;
  7773. //
  7774. // Define the structures used by the I/O system
  7775. //
  7776. //
  7777. // Define empty typedefs for the _IRP, _DEVICE_OBJECT, and _DRIVER_OBJECT
  7778. // structures so they may be referenced by function types before they are
  7779. // actually defined.
  7780. //
  7781. struct _DEVICE_OBJECT;
  7782. struct _DRIVER_OBJECT;
  7783. struct _DRIVE_LAYOUT_INFORMATION;
  7784. struct _DISK_PARTITION;
  7785. struct _FILE_OBJECT;
  7786. struct _IRP;
  7787. struct _SCSI_REQUEST_BLOCK;
  7788. //
  7789. // Define the I/O version of a DPC routine.
  7790. //
  7791. typedef
  7792. VOID
  7793. (*PIO_DPC_ROUTINE) (
  7794. IN PKDPC Dpc,
  7795. IN struct _DEVICE_OBJECT *DeviceObject,
  7796. IN struct _IRP *Irp,
  7797. IN PVOID Context
  7798. );
  7799. //
  7800. // Define driver timer routine type.
  7801. //
  7802. typedef
  7803. VOID
  7804. (*PIO_TIMER_ROUTINE) (
  7805. IN struct _DEVICE_OBJECT *DeviceObject,
  7806. IN PVOID Context
  7807. );
  7808. //
  7809. // Define driver initialization routine type.
  7810. //
  7811. typedef
  7812. NTSTATUS
  7813. (*PDRIVER_INITIALIZE) (
  7814. IN struct _DRIVER_OBJECT *DriverObject,
  7815. IN PUNICODE_STRING RegistryPath
  7816. );
  7817. //
  7818. // Define driver reinitialization routine type.
  7819. //
  7820. typedef
  7821. VOID
  7822. (*PDRIVER_REINITIALIZE) (
  7823. IN struct _DRIVER_OBJECT *DriverObject,
  7824. IN PVOID Context,
  7825. IN ULONG Count
  7826. );
  7827. //
  7828. // Define driver cancel routine type.
  7829. //
  7830. typedef
  7831. VOID
  7832. (*PDRIVER_CANCEL) (
  7833. IN struct _DEVICE_OBJECT *DeviceObject,
  7834. IN struct _IRP *Irp
  7835. );
  7836. //
  7837. // Define driver dispatch routine type.
  7838. //
  7839. typedef
  7840. NTSTATUS
  7841. (*PDRIVER_DISPATCH) (
  7842. IN struct _DEVICE_OBJECT *DeviceObject,
  7843. IN struct _IRP *Irp
  7844. );
  7845. //
  7846. // Define driver start I/O routine type.
  7847. //
  7848. typedef
  7849. VOID
  7850. (*PDRIVER_STARTIO) (
  7851. IN struct _DEVICE_OBJECT *DeviceObject,
  7852. IN struct _IRP *Irp
  7853. );
  7854. //
  7855. // Define driver unload routine type.
  7856. //
  7857. typedef
  7858. VOID
  7859. (*PDRIVER_UNLOAD) (
  7860. IN struct _DRIVER_OBJECT *DriverObject
  7861. );
  7862. //
  7863. // Define driver AddDevice routine type.
  7864. //
  7865. typedef
  7866. NTSTATUS
  7867. (*PDRIVER_ADD_DEVICE) (
  7868. IN struct _DRIVER_OBJECT *DriverObject,
  7869. IN struct _DEVICE_OBJECT *PhysicalDeviceObject
  7870. );
  7871. //
  7872. // Define fast I/O procedure prototypes.
  7873. //
  7874. // Fast I/O read and write procedures.
  7875. //
  7876. typedef
  7877. BOOLEAN
  7878. (*PFAST_IO_CHECK_IF_POSSIBLE) (
  7879. IN struct _FILE_OBJECT *FileObject,
  7880. IN PLARGE_INTEGER FileOffset,
  7881. IN ULONG Length,
  7882. IN BOOLEAN Wait,
  7883. IN ULONG LockKey,
  7884. IN BOOLEAN CheckForReadOperation,
  7885. OUT PIO_STATUS_BLOCK IoStatus,
  7886. IN struct _DEVICE_OBJECT *DeviceObject
  7887. );
  7888. typedef
  7889. BOOLEAN
  7890. (*PFAST_IO_READ) (
  7891. IN struct _FILE_OBJECT *FileObject,
  7892. IN PLARGE_INTEGER FileOffset,
  7893. IN ULONG Length,
  7894. IN BOOLEAN Wait,
  7895. IN ULONG LockKey,
  7896. OUT PVOID Buffer,
  7897. OUT PIO_STATUS_BLOCK IoStatus,
  7898. IN struct _DEVICE_OBJECT *DeviceObject
  7899. );
  7900. typedef
  7901. BOOLEAN
  7902. (*PFAST_IO_WRITE) (
  7903. IN struct _FILE_OBJECT *FileObject,
  7904. IN PLARGE_INTEGER FileOffset,
  7905. IN ULONG Length,
  7906. IN BOOLEAN Wait,
  7907. IN ULONG LockKey,
  7908. IN PVOID Buffer,
  7909. OUT PIO_STATUS_BLOCK IoStatus,
  7910. IN struct _DEVICE_OBJECT *DeviceObject
  7911. );
  7912. //
  7913. // Fast I/O query basic and standard information procedures.
  7914. //
  7915. typedef
  7916. BOOLEAN
  7917. (*PFAST_IO_QUERY_BASIC_INFO) (
  7918. IN struct _FILE_OBJECT *FileObject,
  7919. IN BOOLEAN Wait,
  7920. OUT PFILE_BASIC_INFORMATION Buffer,
  7921. OUT PIO_STATUS_BLOCK IoStatus,
  7922. IN struct _DEVICE_OBJECT *DeviceObject
  7923. );
  7924. typedef
  7925. BOOLEAN
  7926. (*PFAST_IO_QUERY_STANDARD_INFO) (
  7927. IN struct _FILE_OBJECT *FileObject,
  7928. IN BOOLEAN Wait,
  7929. OUT PFILE_STANDARD_INFORMATION Buffer,
  7930. OUT PIO_STATUS_BLOCK IoStatus,
  7931. IN struct _DEVICE_OBJECT *DeviceObject
  7932. );
  7933. //
  7934. // Fast I/O lock and unlock procedures.
  7935. //
  7936. typedef
  7937. BOOLEAN
  7938. (*PFAST_IO_LOCK) (
  7939. IN struct _FILE_OBJECT *FileObject,
  7940. IN PLARGE_INTEGER FileOffset,
  7941. IN PLARGE_INTEGER Length,
  7942. PEPROCESS ProcessId,
  7943. ULONG Key,
  7944. BOOLEAN FailImmediately,
  7945. BOOLEAN ExclusiveLock,
  7946. OUT PIO_STATUS_BLOCK IoStatus,
  7947. IN struct _DEVICE_OBJECT *DeviceObject
  7948. );
  7949. typedef
  7950. BOOLEAN
  7951. (*PFAST_IO_UNLOCK_SINGLE) (
  7952. IN struct _FILE_OBJECT *FileObject,
  7953. IN PLARGE_INTEGER FileOffset,
  7954. IN PLARGE_INTEGER Length,
  7955. PEPROCESS ProcessId,
  7956. ULONG Key,
  7957. OUT PIO_STATUS_BLOCK IoStatus,
  7958. IN struct _DEVICE_OBJECT *DeviceObject
  7959. );
  7960. typedef
  7961. BOOLEAN
  7962. (*PFAST_IO_UNLOCK_ALL) (
  7963. IN struct _FILE_OBJECT *FileObject,
  7964. PEPROCESS ProcessId,
  7965. OUT PIO_STATUS_BLOCK IoStatus,
  7966. IN struct _DEVICE_OBJECT *DeviceObject
  7967. );
  7968. typedef
  7969. BOOLEAN
  7970. (*PFAST_IO_UNLOCK_ALL_BY_KEY) (
  7971. IN struct _FILE_OBJECT *FileObject,
  7972. PVOID ProcessId,
  7973. ULONG Key,
  7974. OUT PIO_STATUS_BLOCK IoStatus,
  7975. IN struct _DEVICE_OBJECT *DeviceObject
  7976. );
  7977. //
  7978. // Fast I/O device control procedure.
  7979. //
  7980. typedef
  7981. BOOLEAN
  7982. (*PFAST_IO_DEVICE_CONTROL) (
  7983. IN struct _FILE_OBJECT *FileObject,
  7984. IN BOOLEAN Wait,
  7985. IN PVOID InputBuffer OPTIONAL,
  7986. IN ULONG InputBufferLength,
  7987. OUT PVOID OutputBuffer OPTIONAL,
  7988. IN ULONG OutputBufferLength,
  7989. IN ULONG IoControlCode,
  7990. OUT PIO_STATUS_BLOCK IoStatus,
  7991. IN struct _DEVICE_OBJECT *DeviceObject
  7992. );
  7993. //
  7994. // Define callbacks for NtCreateSection to synchronize correctly with
  7995. // the file system. It pre-acquires the resources that will be needed
  7996. // when calling to query and set file/allocation size in the file system.
  7997. //
  7998. typedef
  7999. VOID
  8000. (*PFAST_IO_ACQUIRE_FILE) (
  8001. IN struct _FILE_OBJECT *FileObject
  8002. );
  8003. typedef
  8004. VOID
  8005. (*PFAST_IO_RELEASE_FILE) (
  8006. IN struct _FILE_OBJECT *FileObject
  8007. );
  8008. //
  8009. // Define callback for drivers that have device objects attached to lower-
  8010. // level drivers' device objects. This callback is made when the lower-level
  8011. // driver is deleting its device object.
  8012. //
  8013. typedef
  8014. VOID
  8015. (*PFAST_IO_DETACH_DEVICE) (
  8016. IN struct _DEVICE_OBJECT *SourceDevice,
  8017. IN struct _DEVICE_OBJECT *TargetDevice
  8018. );
  8019. //
  8020. // This structure is used by the server to quickly get the information needed
  8021. // to service a server open call. It is takes what would be two fast io calls
  8022. // one for basic information and the other for standard information and makes
  8023. // it into one call.
  8024. //
  8025. typedef
  8026. BOOLEAN
  8027. (*PFAST_IO_QUERY_NETWORK_OPEN_INFO) (
  8028. IN struct _FILE_OBJECT *FileObject,
  8029. IN BOOLEAN Wait,
  8030. OUT struct _FILE_NETWORK_OPEN_INFORMATION *Buffer,
  8031. OUT struct _IO_STATUS_BLOCK *IoStatus,
  8032. IN struct _DEVICE_OBJECT *DeviceObject
  8033. );
  8034. //
  8035. // Define Mdl-based routines for the server to call
  8036. //
  8037. typedef
  8038. BOOLEAN
  8039. (*PFAST_IO_MDL_READ) (
  8040. IN struct _FILE_OBJECT *FileObject,
  8041. IN PLARGE_INTEGER FileOffset,
  8042. IN ULONG Length,
  8043. IN ULONG LockKey,
  8044. OUT PMDL *MdlChain,
  8045. OUT PIO_STATUS_BLOCK IoStatus,
  8046. IN struct _DEVICE_OBJECT *DeviceObject
  8047. );
  8048. typedef
  8049. BOOLEAN
  8050. (*PFAST_IO_MDL_READ_COMPLETE) (
  8051. IN struct _FILE_OBJECT *FileObject,
  8052. IN PMDL MdlChain,
  8053. IN struct _DEVICE_OBJECT *DeviceObject
  8054. );
  8055. typedef
  8056. BOOLEAN
  8057. (*PFAST_IO_PREPARE_MDL_WRITE) (
  8058. IN struct _FILE_OBJECT *FileObject,
  8059. IN PLARGE_INTEGER FileOffset,
  8060. IN ULONG Length,
  8061. IN ULONG LockKey,
  8062. OUT PMDL *MdlChain,
  8063. OUT PIO_STATUS_BLOCK IoStatus,
  8064. IN struct _DEVICE_OBJECT *DeviceObject
  8065. );
  8066. typedef
  8067. BOOLEAN
  8068. (*PFAST_IO_MDL_WRITE_COMPLETE) (
  8069. IN struct _FILE_OBJECT *FileObject,
  8070. IN PLARGE_INTEGER FileOffset,
  8071. IN PMDL MdlChain,
  8072. IN struct _DEVICE_OBJECT *DeviceObject
  8073. );
  8074. //
  8075. // If this routine is present, it will be called by FsRtl
  8076. // to acquire the file for the mapped page writer.
  8077. //
  8078. typedef
  8079. NTSTATUS
  8080. (*PFAST_IO_ACQUIRE_FOR_MOD_WRITE) (
  8081. IN struct _FILE_OBJECT *FileObject,
  8082. IN PLARGE_INTEGER EndingOffset,
  8083. OUT struct _ERESOURCE **ResourceToRelease,
  8084. IN struct _DEVICE_OBJECT *DeviceObject
  8085. );
  8086. typedef
  8087. NTSTATUS
  8088. (*PFAST_IO_RELEASE_FOR_MOD_WRITE) (
  8089. IN struct _FILE_OBJECT *FileObject,
  8090. IN struct _ERESOURCE *ResourceToRelease,
  8091. IN struct _DEVICE_OBJECT *DeviceObject
  8092. );
  8093. //
  8094. // If this routine is present, it will be called by FsRtl
  8095. // to acquire the file for the mapped page writer.
  8096. //
  8097. typedef
  8098. NTSTATUS
  8099. (*PFAST_IO_ACQUIRE_FOR_CCFLUSH) (
  8100. IN struct _FILE_OBJECT *FileObject,
  8101. IN struct _DEVICE_OBJECT *DeviceObject
  8102. );
  8103. typedef
  8104. NTSTATUS
  8105. (*PFAST_IO_RELEASE_FOR_CCFLUSH) (
  8106. IN struct _FILE_OBJECT *FileObject,
  8107. IN struct _DEVICE_OBJECT *DeviceObject
  8108. );
  8109. typedef
  8110. BOOLEAN
  8111. (*PFAST_IO_READ_COMPRESSED) (
  8112. IN struct _FILE_OBJECT *FileObject,
  8113. IN PLARGE_INTEGER FileOffset,
  8114. IN ULONG Length,
  8115. IN ULONG LockKey,
  8116. OUT PVOID Buffer,
  8117. OUT PMDL *MdlChain,
  8118. OUT PIO_STATUS_BLOCK IoStatus,
  8119. OUT struct _COMPRESSED_DATA_INFO *CompressedDataInfo,
  8120. IN ULONG CompressedDataInfoLength,
  8121. IN struct _DEVICE_OBJECT *DeviceObject
  8122. );
  8123. typedef
  8124. BOOLEAN
  8125. (*PFAST_IO_WRITE_COMPRESSED) (
  8126. IN struct _FILE_OBJECT *FileObject,
  8127. IN PLARGE_INTEGER FileOffset,
  8128. IN ULONG Length,
  8129. IN ULONG LockKey,
  8130. IN PVOID Buffer,
  8131. OUT PMDL *MdlChain,
  8132. OUT PIO_STATUS_BLOCK IoStatus,
  8133. IN struct _COMPRESSED_DATA_INFO *CompressedDataInfo,
  8134. IN ULONG CompressedDataInfoLength,
  8135. IN struct _DEVICE_OBJECT *DeviceObject
  8136. );
  8137. typedef
  8138. BOOLEAN
  8139. (*PFAST_IO_MDL_READ_COMPLETE_COMPRESSED) (
  8140. IN struct _FILE_OBJECT *FileObject,
  8141. IN PMDL MdlChain,
  8142. IN struct _DEVICE_OBJECT *DeviceObject
  8143. );
  8144. typedef
  8145. BOOLEAN
  8146. (*PFAST_IO_MDL_WRITE_COMPLETE_COMPRESSED) (
  8147. IN struct _FILE_OBJECT *FileObject,
  8148. IN PLARGE_INTEGER FileOffset,
  8149. IN PMDL MdlChain,
  8150. IN struct _DEVICE_OBJECT *DeviceObject
  8151. );
  8152. typedef
  8153. BOOLEAN
  8154. (*PFAST_IO_QUERY_OPEN) (
  8155. IN struct _IRP *Irp,
  8156. OUT PFILE_NETWORK_OPEN_INFORMATION NetworkInformation,
  8157. IN struct _DEVICE_OBJECT *DeviceObject
  8158. );
  8159. //
  8160. // Define the structure to describe the Fast I/O dispatch routines. Any
  8161. // additions made to this structure MUST be added monotonically to the end
  8162. // of the structure, and fields CANNOT be removed from the middle.
  8163. //
  8164. typedef struct _FAST_IO_DISPATCH {
  8165. ULONG SizeOfFastIoDispatch;
  8166. PFAST_IO_CHECK_IF_POSSIBLE FastIoCheckIfPossible;
  8167. PFAST_IO_READ FastIoRead;
  8168. PFAST_IO_WRITE FastIoWrite;
  8169. PFAST_IO_QUERY_BASIC_INFO FastIoQueryBasicInfo;
  8170. PFAST_IO_QUERY_STANDARD_INFO FastIoQueryStandardInfo;
  8171. PFAST_IO_LOCK FastIoLock;
  8172. PFAST_IO_UNLOCK_SINGLE FastIoUnlockSingle;
  8173. PFAST_IO_UNLOCK_ALL FastIoUnlockAll;
  8174. PFAST_IO_UNLOCK_ALL_BY_KEY FastIoUnlockAllByKey;
  8175. PFAST_IO_DEVICE_CONTROL FastIoDeviceControl;
  8176. PFAST_IO_ACQUIRE_FILE AcquireFileForNtCreateSection;
  8177. PFAST_IO_RELEASE_FILE ReleaseFileForNtCreateSection;
  8178. PFAST_IO_DETACH_DEVICE FastIoDetachDevice;
  8179. PFAST_IO_QUERY_NETWORK_OPEN_INFO FastIoQueryNetworkOpenInfo;
  8180. PFAST_IO_ACQUIRE_FOR_MOD_WRITE AcquireForModWrite;
  8181. PFAST_IO_MDL_READ MdlRead;
  8182. PFAST_IO_MDL_READ_COMPLETE MdlReadComplete;
  8183. PFAST_IO_PREPARE_MDL_WRITE PrepareMdlWrite;
  8184. PFAST_IO_MDL_WRITE_COMPLETE MdlWriteComplete;
  8185. PFAST_IO_READ_COMPRESSED FastIoReadCompressed;
  8186. PFAST_IO_WRITE_COMPRESSED FastIoWriteCompressed;
  8187. PFAST_IO_MDL_READ_COMPLETE_COMPRESSED MdlReadCompleteCompressed;
  8188. PFAST_IO_MDL_WRITE_COMPLETE_COMPRESSED MdlWriteCompleteCompressed;
  8189. PFAST_IO_QUERY_OPEN FastIoQueryOpen;
  8190. PFAST_IO_RELEASE_FOR_MOD_WRITE ReleaseForModWrite;
  8191. PFAST_IO_ACQUIRE_FOR_CCFLUSH AcquireForCcFlush;
  8192. PFAST_IO_RELEASE_FOR_CCFLUSH ReleaseForCcFlush;
  8193. } FAST_IO_DISPATCH, *PFAST_IO_DISPATCH;
  8194. //
  8195. // Define the actions that a driver execution routine may request of the
  8196. // adapter/controller allocation routines upon return.
  8197. //
  8198. typedef enum _IO_ALLOCATION_ACTION {
  8199. KeepObject = 1,
  8200. DeallocateObject,
  8201. DeallocateObjectKeepRegisters
  8202. } IO_ALLOCATION_ACTION, *PIO_ALLOCATION_ACTION;
  8203. //
  8204. // Define device driver adapter/controller execution routine.
  8205. //
  8206. typedef
  8207. IO_ALLOCATION_ACTION
  8208. (*PDRIVER_CONTROL) (
  8209. IN struct _DEVICE_OBJECT *DeviceObject,
  8210. IN struct _IRP *Irp,
  8211. IN PVOID MapRegisterBase,
  8212. IN PVOID Context
  8213. );
  8214. //
  8215. // Define the I/O system's security context type for use by file system's
  8216. // when checking access to volumes, files, and directories.
  8217. //
  8218. typedef struct _IO_SECURITY_CONTEXT {
  8219. PSECURITY_QUALITY_OF_SERVICE SecurityQos;
  8220. PACCESS_STATE AccessState;
  8221. ACCESS_MASK DesiredAccess;
  8222. ULONG FullCreateOptions;
  8223. } IO_SECURITY_CONTEXT, *PIO_SECURITY_CONTEXT;
  8224. //
  8225. // Define Volume Parameter Block (VPB) flags.
  8226. //
  8227. #define VPB_MOUNTED 0x00000001
  8228. #define VPB_LOCKED 0x00000002
  8229. #define VPB_PERSISTENT 0x00000004
  8230. //
  8231. // Volume Parameter Block (VPB)
  8232. //
  8233. #define MAXIMUM_VOLUME_LABEL_LENGTH (32 * sizeof(WCHAR)) // 32 characters
  8234. typedef struct _VPB {
  8235. CSHORT Type;
  8236. CSHORT Size;
  8237. USHORT Flags;
  8238. USHORT VolumeLabelLength; // in bytes
  8239. struct _DEVICE_OBJECT *DeviceObject;
  8240. struct _DEVICE_OBJECT *RealDevice;
  8241. ULONG SerialNumber;
  8242. ULONG ReferenceCount;
  8243. WCHAR VolumeLabel[MAXIMUM_VOLUME_LABEL_LENGTH / sizeof(WCHAR)];
  8244. } VPB, *PVPB;
  8245. //
  8246. // Define object type specific fields of various objects used by the I/O system
  8247. //
  8248. typedef struct _ADAPTER_OBJECT *PADAPTER_OBJECT; // ntndis
  8249. //
  8250. // Define Wait Context Block (WCB)
  8251. //
  8252. typedef struct _WAIT_CONTEXT_BLOCK {
  8253. KDEVICE_QUEUE_ENTRY WaitQueueEntry;
  8254. PDRIVER_CONTROL DeviceRoutine;
  8255. PVOID DeviceContext;
  8256. ULONG NumberOfMapRegisters;
  8257. PVOID DeviceObject;
  8258. PVOID CurrentIrp;
  8259. PKDPC BufferChainingDpc;
  8260. } WAIT_CONTEXT_BLOCK, *PWAIT_CONTEXT_BLOCK;
  8261. typedef struct _CONTROLLER_OBJECT {
  8262. CSHORT Type;
  8263. CSHORT Size;
  8264. PVOID ControllerExtension;
  8265. KDEVICE_QUEUE DeviceWaitQueue;
  8266. ULONG Spare1;
  8267. LARGE_INTEGER Spare2;
  8268. } CONTROLLER_OBJECT, *PCONTROLLER_OBJECT;
  8269. //
  8270. // Define Device Object (DO) flags
  8271. //
  8272. #define DO_UNLOAD_PENDING 0x00000001
  8273. #define DO_VERIFY_VOLUME 0x00000002
  8274. #define DO_BUFFERED_IO 0x00000004
  8275. #define DO_EXCLUSIVE 0x00000008
  8276. #define DO_DIRECT_IO 0x00000010
  8277. #define DO_MAP_IO_BUFFER 0x00000020
  8278. #define DO_DEVICE_HAS_NAME 0x00000040
  8279. #define DO_DEVICE_INITIALIZING 0x00000080
  8280. #define DO_SYSTEM_BOOT_PARTITION 0x00000100
  8281. #define DO_LONG_TERM_REQUESTS 0x00000200
  8282. #define DO_NEVER_LAST_DEVICE 0x00000400
  8283. #define DO_SHUTDOWN_REGISTERED 0x00000800
  8284. //
  8285. // Device Object structure definition
  8286. //
  8287. typedef struct _DEVICE_OBJECT {
  8288. CSHORT Type;
  8289. USHORT Size;
  8290. LONG ReferenceCount;
  8291. struct _DRIVER_OBJECT *DriverObject;
  8292. struct _DEVICE_OBJECT *NextDevice;
  8293. struct _DEVICE_OBJECT *AttachedDevice;
  8294. struct _IRP *CurrentIrp;
  8295. PIO_TIMER Timer;
  8296. ULONG Flags; // See above: DO_...
  8297. ULONG Characteristics; // See ntioapi: FILE_...
  8298. PVPB Vpb;
  8299. PVOID DeviceExtension;
  8300. DEVICE_TYPE DeviceType;
  8301. CCHAR StackSize;
  8302. union {
  8303. LIST_ENTRY ListEntry;
  8304. WAIT_CONTEXT_BLOCK Wcb;
  8305. } Queue;
  8306. ULONG AlignmentRequirement;
  8307. KDEVICE_QUEUE DeviceQueue;
  8308. KDPC Dpc;
  8309. //
  8310. // The following field is for exclusive use by the filesystem to keep
  8311. // track of the number of Fsp threads currently using the device
  8312. //
  8313. ULONG ActiveThreadCount;
  8314. PSECURITY_DESCRIPTOR SecurityDescriptor;
  8315. KEVENT DeviceLock;
  8316. USHORT SectorSize;
  8317. USHORT Spare1;
  8318. struct _DEVOBJ_EXTENSION *DeviceObjectExtension;
  8319. PVOID Reserved;
  8320. } DEVICE_OBJECT;
  8321. typedef struct _DEVICE_OBJECT *PDEVICE_OBJECT; // ntndis
  8322. typedef struct _DEVOBJ_EXTENSION {
  8323. //
  8324. //
  8325. //
  8326. CSHORT Type;
  8327. USHORT Size;
  8328. //
  8329. // Public part of the DeviceObjectExtension structure
  8330. //
  8331. PDEVICE_OBJECT DeviceObject; // owning device object
  8332. //
  8333. // Shared Power Management fields
  8334. //
  8335. ULONG IdleCount; // SHARED field via PoSetDeviceBusy()
  8336. POWER_STATE CurrentPowerState;
  8337. ULONG CurrentDevicePowerState;
  8338. BOOLEAN StartIoQueueHolding; // PO & IO
  8339. BOOLEAN UseAsyncPowerUp;
  8340. BOOLEAN PowerControlNeeded;
  8341. BOOLEAN PowerControlPagable;
  8342. //
  8343. // Note: any new shared fields get added here.
  8344. //
  8345. } DEVOBJ_EXTENSION, *PDEVOBJ_EXTENSION;
  8346. //
  8347. // Define Driver Object (DRVO) flags
  8348. //
  8349. #define DRVO_UNLOAD_INVOKED 0x00000001
  8350. typedef struct _DRIVER_EXTENSION {
  8351. //
  8352. // Back pointer to Driver Object
  8353. //
  8354. struct _DRIVER_OBJECT *DriverObject;
  8355. //
  8356. // The AddDevice entry point is called by the Plug & Play manager
  8357. // to inform the driver when a new device instance arrives that this
  8358. // driver must control.
  8359. //
  8360. PDRIVER_ADD_DEVICE AddDevice;
  8361. //
  8362. // The count field is used to count the number of times the driver has
  8363. // had its registered reinitialization routine invoked.
  8364. //
  8365. ULONG Count;
  8366. //
  8367. // The service name field is used by the pnp manager to determine
  8368. // where the driver related info is stored in the registry.
  8369. //
  8370. UNICODE_STRING ServiceKeyName;
  8371. } DRIVER_EXTENSION, *PDRIVER_EXTENSION;
  8372. typedef struct _DRIVER_OBJECT {
  8373. CSHORT Type;
  8374. CSHORT Size;
  8375. //
  8376. // The following links all of the devices created by a single driver
  8377. // together on a list, and the Flags word provides an extensible flag
  8378. // location for driver objects.
  8379. //
  8380. PDEVICE_OBJECT DeviceObject;
  8381. ULONG Flags;
  8382. //
  8383. // The following section describes where the driver is loaded. The count
  8384. // field is used to count the number of times the driver has had its
  8385. // registered reinitialization routine invoked.
  8386. //
  8387. PVOID DriverStart;
  8388. ULONG DriverSize;
  8389. PVOID DriverSection;
  8390. PDRIVER_EXTENSION DriverExtension;
  8391. //
  8392. // The driver name field is used by the error log thread
  8393. // determine the name of the driver that an I/O request is/was bound.
  8394. //
  8395. UNICODE_STRING DriverName;
  8396. //
  8397. // The following section is for registry support. Thise is a pointer
  8398. // to the path to the hardware information in the registry
  8399. //
  8400. PUNICODE_STRING HardwareDatabase;
  8401. //
  8402. // The following section contains the optional pointer to an array of
  8403. // alternate entry points to a driver for "fast I/O" support. Fast I/O
  8404. // is performed by invoking the driver routine directly with separate
  8405. // parameters, rather than using the standard IRP call mechanism. Note
  8406. // that these functions may only be used for synchronous I/O, and when
  8407. // the file is cached.
  8408. //
  8409. PFAST_IO_DISPATCH FastIoDispatch;
  8410. //
  8411. // The following section describes the entry points to this particular
  8412. // driver. Note that the major function dispatch table must be the last
  8413. // field in the object so that it remains extensible.
  8414. //
  8415. PDRIVER_INITIALIZE DriverInit;
  8416. PDRIVER_STARTIO DriverStartIo;
  8417. PDRIVER_UNLOAD DriverUnload;
  8418. PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION + 1];
  8419. } DRIVER_OBJECT;
  8420. typedef struct _DRIVER_OBJECT *PDRIVER_OBJECT; // ntndis
  8421. //
  8422. // The following structure is pointed to by the SectionObject pointer field
  8423. // of a file object, and is allocated by the various NT file systems.
  8424. //
  8425. typedef struct _SECTION_OBJECT_POINTERS {
  8426. PVOID DataSectionObject;
  8427. PVOID SharedCacheMap;
  8428. PVOID ImageSectionObject;
  8429. } SECTION_OBJECT_POINTERS;
  8430. typedef SECTION_OBJECT_POINTERS *PSECTION_OBJECT_POINTERS;
  8431. //
  8432. // Define the format of a completion message.
  8433. //
  8434. typedef struct _IO_COMPLETION_CONTEXT {
  8435. PVOID Port;
  8436. ULONG Key;
  8437. } IO_COMPLETION_CONTEXT, *PIO_COMPLETION_CONTEXT;
  8438. //
  8439. // Define File Object (FO) flags
  8440. //
  8441. #define FO_FILE_OPEN 0x00000001
  8442. #define FO_SYNCHRONOUS_IO 0x00000002
  8443. #define FO_ALERTABLE_IO 0x00000004
  8444. #define FO_NO_INTERMEDIATE_BUFFERING 0x00000008
  8445. #define FO_WRITE_THROUGH 0x00000010
  8446. #define FO_SEQUENTIAL_ONLY 0x00000020
  8447. #define FO_CACHE_SUPPORTED 0x00000040
  8448. #define FO_NAMED_PIPE 0x00000080
  8449. #define FO_STREAM_FILE 0x00000100
  8450. #define FO_MAILSLOT 0x00000200
  8451. #define FO_GENERATE_AUDIT_ON_CLOSE 0x00000400
  8452. #define FO_DIRECT_DEVICE_OPEN 0x00000800
  8453. #define FO_FILE_MODIFIED 0x00001000
  8454. #define FO_FILE_SIZE_CHANGED 0x00002000
  8455. #define FO_CLEANUP_COMPLETE 0x00004000
  8456. #define FO_TEMPORARY_FILE 0x00008000
  8457. #define FO_DELETE_ON_CLOSE 0x00010000
  8458. #define FO_OPENED_CASE_SENSITIVE 0x00020000
  8459. #define FO_HANDLE_CREATED 0x00040000
  8460. #define FO_FILE_FAST_IO_READ 0x00080000
  8461. #define FO_FILE_OLE_ACCESS 0x00100000
  8462. typedef struct _FILE_OBJECT {
  8463. CSHORT Type;
  8464. CSHORT Size;
  8465. PDEVICE_OBJECT DeviceObject;
  8466. PVPB Vpb;
  8467. PVOID FsContext;
  8468. PVOID FsContext2;
  8469. PSECTION_OBJECT_POINTERS SectionObjectPointer;
  8470. PVOID PrivateCacheMap;
  8471. NTSTATUS FinalStatus;
  8472. struct _FILE_OBJECT *RelatedFileObject;
  8473. BOOLEAN LockOperation;
  8474. BOOLEAN DeletePending;
  8475. BOOLEAN ReadAccess;
  8476. BOOLEAN WriteAccess;
  8477. BOOLEAN DeleteAccess;
  8478. BOOLEAN SharedRead;
  8479. BOOLEAN SharedWrite;
  8480. BOOLEAN SharedDelete;
  8481. ULONG Flags;
  8482. UNICODE_STRING FileName;
  8483. LARGE_INTEGER CurrentByteOffset;
  8484. ULONG Waiters;
  8485. ULONG Busy;
  8486. PVOID LastLock;
  8487. KEVENT Lock;
  8488. KEVENT Event;
  8489. PIO_COMPLETION_CONTEXT CompletionContext;
  8490. } FILE_OBJECT;
  8491. typedef struct _FILE_OBJECT *PFILE_OBJECT; // ntndis
  8492. //
  8493. // Define I/O Request Packet (IRP) flags
  8494. //
  8495. #define IRP_NOCACHE 0x00000001
  8496. #define IRP_PAGING_IO 0x00000002
  8497. #define IRP_MOUNT_COMPLETION 0x00000002
  8498. #define IRP_SYNCHRONOUS_API 0x00000004
  8499. #define IRP_ASSOCIATED_IRP 0x00000008
  8500. #define IRP_BUFFERED_IO 0x00000010
  8501. #define IRP_DEALLOCATE_BUFFER 0x00000020
  8502. #define IRP_INPUT_OPERATION 0x00000040
  8503. #define IRP_SYNCHRONOUS_PAGING_IO 0x00000040
  8504. #define IRP_CREATE_OPERATION 0x00000080
  8505. #define IRP_READ_OPERATION 0x00000100
  8506. #define IRP_WRITE_OPERATION 0x00000200
  8507. #define IRP_CLOSE_OPERATION 0x00000400
  8508. #define IRP_DEFER_IO_COMPLETION 0x00000800
  8509. #define IRP_OB_QUERY_NAME 0x00001000
  8510. #define IRP_HOLD_DEVICE_QUEUE 0x00002000
  8511. //
  8512. // Define I/O request packet (IRP) alternate flags for allocation control.
  8513. //
  8514. #define IRP_QUOTA_CHARGED 0x01
  8515. #define IRP_ALLOCATED_MUST_SUCCEED 0x02
  8516. #define IRP_ALLOCATED_FIXED_SIZE 0x04
  8517. //
  8518. // I/O Request Packet (IRP) definition
  8519. //
  8520. typedef struct _IRP {
  8521. CSHORT Type;
  8522. USHORT Size;
  8523. //
  8524. // Define the common fields used to control the IRP.
  8525. //
  8526. //
  8527. // Define a pointer to the Memory Descriptor List (MDL) for this I/O
  8528. // request. This field is only used if the I/O is "direct I/O".
  8529. //
  8530. PMDL MdlAddress;
  8531. //
  8532. // Flags word - used to remember various flags.
  8533. //
  8534. ULONG Flags;
  8535. //
  8536. // The following union is used for one of three purposes:
  8537. //
  8538. // 1. This IRP is an associated IRP. The field is a pointer to a master
  8539. // IRP.
  8540. //
  8541. // 2. This is the master IRP. The field is the count of the number of
  8542. // IRPs which must complete (associated IRPs) before the master can
  8543. // complete.
  8544. //
  8545. // 3. This operation is being buffered and the field is the address of
  8546. // the system space buffer.
  8547. //
  8548. union {
  8549. struct _IRP *MasterIrp;
  8550. LONG IrpCount;
  8551. PVOID SystemBuffer;
  8552. } AssociatedIrp;
  8553. //
  8554. // Thread list entry - allows queueing the IRP to the thread pending I/O
  8555. // request packet list.
  8556. //
  8557. LIST_ENTRY ThreadListEntry;
  8558. //
  8559. // I/O status - final status of operation.
  8560. //
  8561. IO_STATUS_BLOCK IoStatus;
  8562. //
  8563. // Requestor mode - mode of the original requestor of this operation.
  8564. //
  8565. KPROCESSOR_MODE RequestorMode;
  8566. //
  8567. // Pending returned - TRUE if pending was initially returned as the
  8568. // status for this packet.
  8569. //
  8570. BOOLEAN PendingReturned;
  8571. //
  8572. // Stack state information.
  8573. //
  8574. CHAR StackCount;
  8575. CHAR CurrentLocation;
  8576. //
  8577. // Cancel - packet has been canceled.
  8578. //
  8579. BOOLEAN Cancel;
  8580. //
  8581. // Cancel Irql - Irql at which the cancel spinlock was acquired.
  8582. //
  8583. KIRQL CancelIrql;
  8584. //
  8585. // ApcEnvironment - Used to save the APC environment at the time that the
  8586. // packet was initialized.
  8587. //
  8588. CCHAR ApcEnvironment;
  8589. //
  8590. // Allocation control flags.
  8591. //
  8592. UCHAR AllocationFlags;
  8593. //
  8594. // User parameters.
  8595. //
  8596. PIO_STATUS_BLOCK UserIosb;
  8597. PKEVENT UserEvent;
  8598. union {
  8599. struct {
  8600. PIO_APC_ROUTINE UserApcRoutine;
  8601. PVOID UserApcContext;
  8602. } AsynchronousParameters;
  8603. LARGE_INTEGER AllocationSize;
  8604. } Overlay;
  8605. //
  8606. // CancelRoutine - Used to contain the address of a cancel routine supplied
  8607. // by a device driver when the IRP is in a cancelable state.
  8608. //
  8609. PDRIVER_CANCEL CancelRoutine;
  8610. //
  8611. // Note that the UserBuffer parameter is outside of the stack so that I/O
  8612. // completion can copy data back into the user's address space without
  8613. // having to know exactly which service was being invoked. The length
  8614. // of the copy is stored in the second half of the I/O status block. If
  8615. // the UserBuffer field is NULL, then no copy is performed.
  8616. //
  8617. PVOID UserBuffer;
  8618. //
  8619. // Kernel structures
  8620. //
  8621. // The following section contains kernel structures which the IRP needs
  8622. // in order to place various work information in kernel controller system
  8623. // queues. Because the size and alignment cannot be controlled, they are
  8624. // placed here at the end so they just hang off and do not affect the
  8625. // alignment of other fields in the IRP.
  8626. //
  8627. union {
  8628. struct {
  8629. union {
  8630. //
  8631. // DeviceQueueEntry - The device queue entry field is used to
  8632. // queue the IRP to the device driver device queue.
  8633. //
  8634. KDEVICE_QUEUE_ENTRY DeviceQueueEntry;
  8635. struct {
  8636. //
  8637. // The following are available to the driver to use in
  8638. // whatever manner is desired, while the driver owns the
  8639. // packet.
  8640. //
  8641. PVOID DriverContext[4];
  8642. } ;
  8643. } ;
  8644. //
  8645. // Thread - pointer to caller's Thread Control Block.
  8646. //
  8647. PETHREAD Thread;
  8648. //
  8649. // Auxiliary buffer - pointer to any auxiliary buffer that is
  8650. // required to pass information to a driver that is not contained
  8651. // in a normal buffer.
  8652. //
  8653. PCHAR AuxiliaryBuffer;
  8654. //
  8655. // List entry - used to queue the packet to completion queue, among
  8656. // others.
  8657. //
  8658. LIST_ENTRY ListEntry;
  8659. //
  8660. // Current stack location - contains a pointer to the current
  8661. // IO_STACK_LOCATION structure in the IRP stack. This field
  8662. // should never be directly accessed by drivers. They should
  8663. // use the standard functions.
  8664. //
  8665. struct _IO_STACK_LOCATION *CurrentStackLocation;
  8666. //
  8667. // Original file object - pointer to the original file object
  8668. // that was used to open the file. This field is owned by the
  8669. // I/O system and should not be used by any other drivers.
  8670. //
  8671. PFILE_OBJECT OriginalFileObject;
  8672. } Overlay;
  8673. //
  8674. // APC - This APC control block is used for the special kernel APC as
  8675. // well as for the caller's APC, if one was specified in the original
  8676. // argument list. If so, then the APC is reused for the normal APC for
  8677. // whatever mode the caller was in and the "special" routine that is
  8678. // invoked before the APC gets control simply deallocates the IRP.
  8679. //
  8680. KAPC Apc;
  8681. //
  8682. // CompletionKey - This is the key that is used to distinguish
  8683. // individual I/O operations initiated on a single file handle.
  8684. //
  8685. ULONG CompletionKey;
  8686. } Tail;
  8687. } IRP, *PIRP;
  8688. //
  8689. // Define completion routine types for use in stack locations in an IRP
  8690. //
  8691. typedef
  8692. NTSTATUS
  8693. (*PIO_COMPLETION_ROUTINE) (
  8694. IN PDEVICE_OBJECT DeviceObject,
  8695. IN PIRP Irp,
  8696. IN PVOID Context
  8697. );
  8698. //
  8699. // Define stack location control flags
  8700. //
  8701. #define SL_PENDING_RETURNED 0x01
  8702. #define SL_INVOKE_ON_CANCEL 0x20
  8703. #define SL_INVOKE_ON_SUCCESS 0x40
  8704. #define SL_INVOKE_ON_ERROR 0x80
  8705. //
  8706. // Define flags for various functions
  8707. //
  8708. //
  8709. // Create / Create Named Pipe
  8710. //
  8711. // The following flags must exactly match those in the IoCreateFile call's
  8712. // options. The case sensitive flag is added in later, by the parse routine,
  8713. // and is not an actual option to open. Rather, it is part of the object
  8714. // manager's attributes structure.
  8715. //
  8716. #define SL_FORCE_ACCESS_CHECK 0x01
  8717. #define SL_OPEN_PAGING_FILE 0x02
  8718. #define SL_OPEN_TARGET_DIRECTORY 0x04
  8719. #define SL_CASE_SENSITIVE 0x80
  8720. //
  8721. // Read / Write
  8722. //
  8723. #define SL_KEY_SPECIFIED 0x01
  8724. #define SL_OVERRIDE_VERIFY_VOLUME 0x02
  8725. #define SL_WRITE_THROUGH 0x04
  8726. #define SL_FT_SEQUENTIAL_WRITE 0x08
  8727. //
  8728. // Device I/O Control
  8729. //
  8730. //
  8731. // Same SL_OVERRIDE_VERIFY_VOLUME as for read/write above.
  8732. //
  8733. //
  8734. // Lock
  8735. //
  8736. #define SL_FAIL_IMMEDIATELY 0x01
  8737. #define SL_EXCLUSIVE_LOCK 0x02
  8738. //
  8739. // QueryDirectory / QueryEa / QueryQuota
  8740. //
  8741. #define SL_RESTART_SCAN 0x01
  8742. #define SL_RETURN_SINGLE_ENTRY 0x02
  8743. #define SL_INDEX_SPECIFIED 0x04
  8744. //
  8745. // NotifyDirectory
  8746. //
  8747. #define SL_WATCH_TREE 0x01
  8748. //
  8749. // FileSystemControl
  8750. //
  8751. // minor: mount/verify volume
  8752. //
  8753. #define SL_ALLOW_RAW_MOUNT 0x01
  8754. //
  8755. // structure for IRP_MN_QUERY_CAPABILITIES
  8756. //
  8757. typedef struct _DEVICE_CAPABILITIES {
  8758. USHORT Size;
  8759. USHORT Version; // the version documented here is version 1
  8760. SYSTEM_POWER_STATE SystemWake;
  8761. DEVICE_POWER_STATE DeviceWake;
  8762. ULONG D1Latency;
  8763. ULONG D2Latency;
  8764. ULONG D3Latency;
  8765. BOOLEAN D0Inrush:1;
  8766. BOOLEAN D0Pagable:1;
  8767. BOOLEAN LockSupported:1;
  8768. BOOLEAN EjectSupported:1;
  8769. BOOLEAN Removable:1;
  8770. BOOLEAN DockDevice:1;
  8771. BOOLEAN UniqueID:1;
  8772. ULONG Reserved: 24;
  8773. } DEVICE_CAPABILITIES, *PDEVICE_CAPABILITIES;
  8774. //
  8775. // structure for IRP_MN_POWER_SEQUENCE
  8776. //
  8777. typedef struct _POWER_SEQUENCE {
  8778. ULONG SequenceD1;
  8779. ULONG SequenceD2;
  8780. ULONG SequenceD3;
  8781. } POWER_SEQUENCE, *PPOWER_SEQUENCE;
  8782. //
  8783. // Define Device Status for IoReportDeviceStatus
  8784. // 0 - 0x7fffffff are for private use and 0x80000000 -
  8785. // 0xffffffff are reserved for the system.
  8786. //
  8787. #define DEVICE_STATUS_OK 0x80000000
  8788. #define DEVICE_STATUS_MALFUNCTIONED 0x80000001
  8789. #define DEVICE_STATUS_REMOVED 0x80000002
  8790. #define DEVICE_STATUS_DISABLED 0x80000003
  8791. typedef enum _DEVICE_RELATION_TYPE {
  8792. BusRelations,
  8793. EjectionRelations,
  8794. PowerRelations
  8795. } DEVICE_RELATION_TYPE, *PDEVICE_RELATION_TYPE;
  8796. typedef enum {
  8797. DeviceID = 0, // bus dependent device id.
  8798. HardwareIDs = 1, // Hardware ids.
  8799. CompatibleIDs = 2, // compatible device ids.
  8800. InstanceID = 3 // system-wide unique device id (persistent across boots)
  8801. } BUS_QUERY_ID_TYPE, *PBUS_QUERY_ID_TYPE;
  8802. //
  8803. // Define I/O Request Packet (IRP) stack locations
  8804. //
  8805. #if !defined(_ALPHA_) && !defined(_IA64_)
  8806. #include "pshpack4.h"
  8807. #endif
  8808. typedef struct _IO_STACK_LOCATION {
  8809. UCHAR MajorFunction;
  8810. UCHAR MinorFunction;
  8811. UCHAR Flags;
  8812. UCHAR Control;
  8813. //
  8814. // The following user parameters are based on the service that is being
  8815. // invoked. Drivers and file systems can determine which set to use based
  8816. // on the above major and minor function codes.
  8817. //
  8818. union {
  8819. //
  8820. // System service parameters for: NtCreateFile
  8821. //
  8822. struct {
  8823. PIO_SECURITY_CONTEXT SecurityContext;
  8824. ULONG Options;
  8825. USHORT FileAttributes;
  8826. USHORT ShareAccess;
  8827. ULONG EaLength;
  8828. } Create;
  8829. //
  8830. // System service parameters for: NtReadFile
  8831. //
  8832. struct {
  8833. ULONG Length;
  8834. ULONG Key;
  8835. LARGE_INTEGER ByteOffset;
  8836. } Read;
  8837. //
  8838. // System service parameters for: NtWriteFile
  8839. //
  8840. struct {
  8841. ULONG Length;
  8842. ULONG Key;
  8843. LARGE_INTEGER ByteOffset;
  8844. } Write;
  8845. //
  8846. // System service parameters for: NtQueryInformationFile
  8847. //
  8848. struct {
  8849. ULONG Length;
  8850. FILE_INFORMATION_CLASS FileInformationClass;
  8851. } QueryFile;
  8852. //
  8853. // System service parameters for: NtSetInformationFile
  8854. //
  8855. struct {
  8856. ULONG Length;
  8857. FILE_INFORMATION_CLASS FileInformationClass;
  8858. PFILE_OBJECT FileObject;
  8859. union {
  8860. struct {
  8861. BOOLEAN ReplaceIfExists;
  8862. BOOLEAN AdvanceOnly;
  8863. };
  8864. ULONG ClusterCount;
  8865. HANDLE DeleteHandle;
  8866. };
  8867. } SetFile;
  8868. //
  8869. // System service parameters for: NtQueryVolumeInformationFile
  8870. //
  8871. struct {
  8872. ULONG Length;
  8873. FS_INFORMATION_CLASS FsInformationClass;
  8874. } QueryVolume;
  8875. //
  8876. // System service parameters for: NtFlushBuffersFile
  8877. //
  8878. // No extra user-supplied parameters.
  8879. //
  8880. //
  8881. // System service parameters for: NtDeviceIoControlFile
  8882. //
  8883. // Note that the user's output buffer is stored in the UserBuffer field
  8884. // and the user's input buffer is stored in the SystemBuffer field.
  8885. //
  8886. struct {
  8887. ULONG OutputBufferLength;
  8888. ULONG InputBufferLength;
  8889. ULONG IoControlCode;
  8890. PVOID Type3InputBuffer;
  8891. } DeviceIoControl;
  8892. //
  8893. // System service parameters for: NtQuerySecurityObject
  8894. //
  8895. struct {
  8896. SECURITY_INFORMATION SecurityInformation;
  8897. ULONG Length;
  8898. } QuerySecurity;
  8899. //
  8900. // System service parameters for: NtSetSecurityObject
  8901. //
  8902. struct {
  8903. SECURITY_INFORMATION SecurityInformation;
  8904. PSECURITY_DESCRIPTOR SecurityDescriptor;
  8905. } SetSecurity;
  8906. //
  8907. // Non-system service parameters.
  8908. //
  8909. // Parameters for MountVolume
  8910. //
  8911. struct {
  8912. PVPB Vpb;
  8913. PDEVICE_OBJECT DeviceObject;
  8914. } MountVolume;
  8915. //
  8916. // Parameters for VerifyVolume
  8917. //
  8918. struct {
  8919. PVPB Vpb;
  8920. PDEVICE_OBJECT DeviceObject;
  8921. } VerifyVolume;
  8922. //
  8923. // Parameters for Scsi with internal device contorl.
  8924. //
  8925. struct {
  8926. struct _SCSI_REQUEST_BLOCK *Srb;
  8927. } Scsi;
  8928. //
  8929. // Parameters for device capabilities
  8930. //
  8931. struct {
  8932. PDEVICE_CAPABILITIES Capabilities;
  8933. } DeviceCapabilities;
  8934. //
  8935. // Parameters for device wake
  8936. //
  8937. struct {
  8938. SYSTEM_POWER_STATE PowerState;
  8939. } WaitWake;
  8940. //
  8941. // Parameter for power sequence
  8942. //
  8943. struct {
  8944. PPOWER_SEQUENCE Device;
  8945. } PowerSequence;
  8946. //
  8947. // Parameters for set power or query power
  8948. //
  8949. struct {
  8950. ULONG SystemContext;
  8951. POWER_STATE_TYPE Type;
  8952. POWER_STATE State;
  8953. } Power;
  8954. //
  8955. // Parameters for device removal irp
  8956. //
  8957. struct {
  8958. PDEVICE_OBJECT DeviceToRemove;
  8959. } RemoveDevice;
  8960. //
  8961. // Parameters for the query device relations irp
  8962. //
  8963. struct {
  8964. DEVICE_RELATION_TYPE Type;
  8965. } QueryDeviceRelations;
  8966. //
  8967. // Parameters for IRP_MN_READ_CONFIG and IRP_MN_WRITE_CONFIG
  8968. //
  8969. struct {
  8970. ULONG WhichSpace;
  8971. PVOID Buffer;
  8972. ULONG Offset;
  8973. ULONG Length;
  8974. } ReadWriteConfig;
  8975. //
  8976. // Parameters for the query device id irp
  8977. //
  8978. struct {
  8979. BUS_QUERY_ID_TYPE IdType;
  8980. } QueryId;
  8981. //
  8982. // Parameters for StartDevice
  8983. //
  8984. struct {
  8985. PCM_RESOURCE_LIST AllocatedResources;
  8986. } StartDevice;
  8987. //
  8988. // Parameters for Cleanup
  8989. //
  8990. // No extra parameters supplied
  8991. //
  8992. //
  8993. // Others - driver-specific
  8994. //
  8995. struct {
  8996. PVOID Argument1;
  8997. PVOID Argument2;
  8998. PVOID Argument3;
  8999. PVOID Argument4;
  9000. } Others;
  9001. } Parameters;
  9002. //
  9003. // Save a pointer to this device driver's device object for this request
  9004. // so it can be passed to the completion routine if needed.
  9005. //
  9006. PDEVICE_OBJECT DeviceObject;
  9007. //
  9008. // The following location contains a pointer to the file object for this
  9009. //
  9010. PFILE_OBJECT FileObject;
  9011. //
  9012. // The following routine is invoked depending on the flags in the above
  9013. // flags field.
  9014. //
  9015. PIO_COMPLETION_ROUTINE CompletionRoutine;
  9016. //
  9017. // The following is used to store the address of the context parameter
  9018. // that should be passed to the CompletionRoutine.
  9019. //
  9020. PVOID Context;
  9021. } IO_STACK_LOCATION, *PIO_STACK_LOCATION;
  9022. #if !defined(_ALPHA_) && !defined(_IA64_)
  9023. #include "poppack.h"
  9024. #endif
  9025. //
  9026. // Define the share access structure used by file systems to determine
  9027. // whether or not another accessor may open the file.
  9028. //
  9029. typedef struct _SHARE_ACCESS {
  9030. ULONG OpenCount;
  9031. ULONG Readers;
  9032. ULONG Writers;
  9033. ULONG Deleters;
  9034. ULONG SharedRead;
  9035. ULONG SharedWrite;
  9036. ULONG SharedDelete;
  9037. } SHARE_ACCESS, *PSHARE_ACCESS;
  9038. // begin_nthal
  9039. //
  9040. // The following structure is used by drivers that are initializing to
  9041. // determine the number of devices of a particular type that have already
  9042. // been initialized. It is also used to track whether or not the AtDisk
  9043. // address range has already been claimed. Finally, it is used by the
  9044. // NtQuerySystemInformation system service to return device type counts.
  9045. //
  9046. typedef struct _CONFIGURATION_INFORMATION {
  9047. //
  9048. // This field indicates the total number of disks in the system. This
  9049. // number should be used by the driver to determine the name of new
  9050. // disks. This field should be updated by the driver as it finds new
  9051. // disks.
  9052. //
  9053. ULONG DiskCount; // Count of hard disks thus far
  9054. ULONG FloppyCount; // Count of floppy disks thus far
  9055. ULONG CdRomCount; // Count of CD-ROM drives thus far
  9056. ULONG TapeCount; // Count of tape drives thus far
  9057. ULONG ScsiPortCount; // Count of SCSI port adapters thus far
  9058. ULONG SerialCount; // Count of serial devices thus far
  9059. ULONG ParallelCount; // Count of parallel devices thus far
  9060. //
  9061. // These next two fields indicate ownership of one of the two IO address
  9062. // spaces that are used by WD1003-compatable disk controllers.
  9063. //
  9064. BOOLEAN AtDiskPrimaryAddressClaimed; // 0x1F0 - 0x1FF
  9065. BOOLEAN AtDiskSecondaryAddressClaimed; // 0x170 - 0x17F
  9066. } CONFIGURATION_INFORMATION, *PCONFIGURATION_INFORMATION;
  9067. //
  9068. // Public I/O routine definitions
  9069. //
  9070. NTKERNELAPI
  9071. VOID
  9072. IoAcquireCancelSpinLock(
  9073. OUT PKIRQL Irql
  9074. );
  9075. NTKERNELAPI
  9076. NTSTATUS
  9077. IoAllocateAdapterChannel(
  9078. IN PADAPTER_OBJECT AdapterObject,
  9079. IN PDEVICE_OBJECT DeviceObject,
  9080. IN ULONG NumberOfMapRegisters,
  9081. IN PDRIVER_CONTROL ExecutionRoutine,
  9082. IN PVOID Context
  9083. );
  9084. NTKERNELAPI
  9085. PVOID
  9086. IoAllocateErrorLogEntry(
  9087. IN PVOID IoObject,
  9088. IN UCHAR EntrySize
  9089. );
  9090. NTKERNELAPI
  9091. PIRP
  9092. IoAllocateIrp(
  9093. IN CCHAR StackSize,
  9094. IN BOOLEAN ChargeQuota
  9095. );
  9096. NTKERNELAPI
  9097. PMDL
  9098. IoAllocateMdl(
  9099. IN PVOID VirtualAddress,
  9100. IN ULONG Length,
  9101. IN BOOLEAN SecondaryBuffer,
  9102. IN BOOLEAN ChargeQuota,
  9103. IN OUT PIRP Irp OPTIONAL
  9104. );
  9105. //++
  9106. //
  9107. // VOID
  9108. // IoAssignArcName(
  9109. // IN PUNICODE_STRING ArcName,
  9110. // IN PUNICODE_STRING DeviceName
  9111. // )
  9112. //
  9113. // Routine Description:
  9114. //
  9115. // This routine is invoked by drivers of bootable media to create a symbolic
  9116. // link between the ARC name of their device and its NT name. This allows
  9117. // the system to determine which device in the system was actually booted
  9118. // from since the ARC firmware only deals in ARC names, and NT only deals
  9119. // in NT names.
  9120. //
  9121. // Arguments:
  9122. //
  9123. // ArcName - Supplies the Unicode string representing the ARC name.
  9124. //
  9125. // DeviceName - Supplies the name to which the ARCname refers.
  9126. //
  9127. // Return Value:
  9128. //
  9129. // None.
  9130. //
  9131. //--
  9132. #define IoAssignArcName( ArcName, DeviceName ) ( \
  9133. IoCreateSymbolicLink( (ArcName), (DeviceName) ) )
  9134. NTKERNELAPI
  9135. NTSTATUS
  9136. IoAttachDevice(
  9137. IN PDEVICE_OBJECT SourceDevice,
  9138. IN PUNICODE_STRING TargetDevice,
  9139. OUT PDEVICE_OBJECT *AttachedDevice
  9140. );
  9141. PDEVICE_OBJECT
  9142. IoAttachDeviceToDeviceStack(
  9143. IN PDEVICE_OBJECT SourceDevice,
  9144. IN PDEVICE_OBJECT TargetDevice
  9145. );
  9146. NTKERNELAPI
  9147. PIRP
  9148. IoBuildAsynchronousFsdRequest(
  9149. IN ULONG MajorFunction,
  9150. IN PDEVICE_OBJECT DeviceObject,
  9151. IN OUT PVOID Buffer OPTIONAL,
  9152. IN ULONG Length OPTIONAL,
  9153. IN PLARGE_INTEGER StartingOffset OPTIONAL,
  9154. IN PIO_STATUS_BLOCK IoStatusBlock OPTIONAL
  9155. );
  9156. NTKERNELAPI
  9157. PIRP
  9158. IoBuildDeviceIoControlRequest(
  9159. IN ULONG IoControlCode,
  9160. IN PDEVICE_OBJECT DeviceObject,
  9161. IN PVOID InputBuffer OPTIONAL,
  9162. IN ULONG InputBufferLength,
  9163. OUT PVOID OutputBuffer OPTIONAL,
  9164. IN ULONG OutputBufferLength,
  9165. IN BOOLEAN InternalDeviceIoControl,
  9166. IN PKEVENT Event,
  9167. OUT PIO_STATUS_BLOCK IoStatusBlock
  9168. );
  9169. NTKERNELAPI
  9170. PIRP
  9171. IoBuildSynchronousFsdRequest(
  9172. IN ULONG MajorFunction,
  9173. IN PDEVICE_OBJECT DeviceObject,
  9174. IN OUT PVOID Buffer OPTIONAL,
  9175. IN ULONG Length OPTIONAL,
  9176. IN PLARGE_INTEGER StartingOffset OPTIONAL,
  9177. IN PKEVENT Event,
  9178. OUT PIO_STATUS_BLOCK IoStatusBlock
  9179. );
  9180. NTKERNELAPI
  9181. NTSTATUS
  9182. FASTCALL
  9183. IofCallDriver(
  9184. IN PDEVICE_OBJECT DeviceObject,
  9185. IN OUT PIRP Irp
  9186. );
  9187. #define IoCallDriver(a,b) \
  9188. IofCallDriver(a,b)
  9189. NTKERNELAPI
  9190. BOOLEAN
  9191. IoCancelIrp(
  9192. IN PIRP Irp
  9193. );
  9194. NTKERNELAPI
  9195. NTSTATUS
  9196. IoCheckShareAccess(
  9197. IN ACCESS_MASK DesiredAccess,
  9198. IN ULONG DesiredShareAccess,
  9199. IN OUT PFILE_OBJECT FileObject,
  9200. IN OUT PSHARE_ACCESS ShareAccess,
  9201. IN BOOLEAN Update
  9202. );
  9203. NTKERNELAPI
  9204. VOID
  9205. FASTCALL
  9206. IofCompleteRequest(
  9207. IN PIRP Irp,
  9208. IN CCHAR PriorityBoost
  9209. );
  9210. #define IoCompleteRequest(a,b) \
  9211. IofCompleteRequest(a,b)
  9212. NTKERNELAPI
  9213. NTSTATUS
  9214. IoConnectInterrupt(
  9215. OUT PKINTERRUPT *InterruptObject,
  9216. IN PKSERVICE_ROUTINE ServiceRoutine,
  9217. IN PVOID ServiceContext,
  9218. IN PKSPIN_LOCK SpinLock OPTIONAL,
  9219. IN ULONG Vector,
  9220. IN KIRQL Irql,
  9221. IN KIRQL SynchronizeIrql,
  9222. IN KINTERRUPT_MODE InterruptMode,
  9223. IN BOOLEAN ShareVector,
  9224. IN KAFFINITY ProcessorEnableMask,
  9225. IN BOOLEAN FloatingSave
  9226. );
  9227. NTKERNELAPI
  9228. NTSTATUS
  9229. IoCreateDevice(
  9230. IN PDRIVER_OBJECT DriverObject,
  9231. IN ULONG DeviceExtensionSize,
  9232. IN PUNICODE_STRING DeviceName OPTIONAL,
  9233. IN DEVICE_TYPE DeviceType,
  9234. IN ULONG DeviceCharacteristics,
  9235. IN BOOLEAN Exclusive,
  9236. OUT PDEVICE_OBJECT *DeviceObject
  9237. );
  9238. NTSTATUS
  9239. IoCreateDriverObject(
  9240. IN PUNICODE_STRING ClassName,
  9241. IN PDRIVER_INITIALIZE InitializationFunction
  9242. );
  9243. NTKERNELAPI
  9244. NTSTATUS
  9245. IoCreateSymbolicLink(
  9246. IN PUNICODE_STRING SymbolicLinkName,
  9247. IN PUNICODE_STRING DeviceName
  9248. );
  9249. NTKERNELAPI
  9250. NTSTATUS
  9251. IoCreateUnprotectedSymbolicLink(
  9252. IN PUNICODE_STRING SymbolicLinkName,
  9253. IN PUNICODE_STRING DeviceName
  9254. );
  9255. //++
  9256. //
  9257. // VOID
  9258. // IoDeassignArcName(
  9259. // IN PUNICODE_STRING ArcName
  9260. // )
  9261. //
  9262. // Routine Description:
  9263. //
  9264. // This routine is invoked by drivers to deassign an ARC name that they
  9265. // created to a device. This is generally only called if the driver is
  9266. // deleting the device object, which means that the driver is probably
  9267. // unloading.
  9268. //
  9269. // Arguments:
  9270. //
  9271. // ArcName - Supplies the ARC name to be removed.
  9272. //
  9273. // Return Value:
  9274. //
  9275. // None.
  9276. //
  9277. //--
  9278. #define IoDeassignArcName( ArcName ) ( \
  9279. IoDeleteSymbolicLink( (ArcName) ) )
  9280. NTKERNELAPI
  9281. VOID
  9282. IoDeleteDevice(
  9283. IN PDEVICE_OBJECT DeviceObject
  9284. );
  9285. NTKERNELAPI
  9286. NTSTATUS
  9287. IoDeleteSymbolicLink(
  9288. IN PUNICODE_STRING SymbolicLinkName
  9289. );
  9290. NTKERNELAPI
  9291. VOID
  9292. IoDetachDevice(
  9293. IN OUT PDEVICE_OBJECT TargetDevice
  9294. );
  9295. NTKERNELAPI
  9296. VOID
  9297. IoDisconnectInterrupt(
  9298. IN PKINTERRUPT InterruptObject
  9299. );
  9300. NTKERNELAPI
  9301. VOID
  9302. IoFreeIrp(
  9303. IN PIRP Irp
  9304. );
  9305. NTKERNELAPI
  9306. VOID
  9307. IoFreeMdl(
  9308. IN PMDL Mdl
  9309. );
  9310. NTKERNELAPI
  9311. PCONFIGURATION_INFORMATION
  9312. IoGetConfigurationInformation( VOID );
  9313. //++
  9314. //
  9315. // PIO_STACK_LOCATION
  9316. // IoGetCurrentIrpStackLocation(
  9317. // IN PIRP Irp
  9318. // )
  9319. //
  9320. // Routine Description:
  9321. //
  9322. // This routine is invoked to return a pointer to the current stack location
  9323. // in an I/O Request Packet (IRP).
  9324. //
  9325. // Arguments:
  9326. //
  9327. // Irp - Pointer to the I/O Request Packet.
  9328. //
  9329. // Return Value:
  9330. //
  9331. // The function value is a pointer to the current stack location in the
  9332. // packet.
  9333. //
  9334. //--
  9335. #define IoGetCurrentIrpStackLocation( Irp ) ( (Irp)->Tail.Overlay.CurrentStackLocation )
  9336. // end_nthal
  9337. NTKERNELAPI
  9338. PEPROCESS
  9339. IoGetCurrentProcess(
  9340. VOID
  9341. );
  9342. // begin_nthal
  9343. NTKERNELAPI
  9344. NTSTATUS
  9345. IoGetDeviceObjectPointer(
  9346. IN PUNICODE_STRING ObjectName,
  9347. IN ACCESS_MASK DesiredAccess,
  9348. OUT PFILE_OBJECT *FileObject,
  9349. OUT PDEVICE_OBJECT *DeviceObject
  9350. );
  9351. // end_nthal
  9352. //++
  9353. //
  9354. // ULONG
  9355. // IoGetFunctionCodeFromCtlCode(
  9356. // IN ULONG ControlCode
  9357. // )
  9358. //
  9359. // Routine Description:
  9360. //
  9361. // This routine extracts the function code from IOCTL and FSCTL function
  9362. // control codes.
  9363. // This routine should only be used by kernel mode code.
  9364. //
  9365. // Arguments:
  9366. //
  9367. // ControlCode - A function control code (IOCTL or FSCTL) from which the
  9368. // function code must be extracted.
  9369. //
  9370. // Return Value:
  9371. //
  9372. // The extracted function code.
  9373. //
  9374. // Note:
  9375. //
  9376. // The CTL_CODE macro, used to create IOCTL and FSCTL function control
  9377. // codes, is defined in ntioapi.h
  9378. //
  9379. //--
  9380. #define IoGetFunctionCodeFromCtlCode( ControlCode ) (\
  9381. ( ControlCode >> 2) & 0x00000FFF )
  9382. // begin_nthal
  9383. //++
  9384. //
  9385. // PIO_STACK_LOCATION
  9386. // IoGetNextIrpStackLocation(
  9387. // IN PIRP Irp
  9388. // )
  9389. //
  9390. // Routine Description:
  9391. //
  9392. // This routine is invoked to return a pointer to the next stack location
  9393. // in an I/O Request Packet (IRP).
  9394. //
  9395. // Arguments:
  9396. //
  9397. // Irp - Pointer to the I/O Request Packet.
  9398. //
  9399. // Return Value:
  9400. //
  9401. // The function value is a pointer to the next stack location in the packet.
  9402. //
  9403. //--
  9404. #define IoGetNextIrpStackLocation( Irp ) (\
  9405. (Irp)->Tail.Overlay.CurrentStackLocation - 1 )
  9406. NTKERNELAPI
  9407. PDEVICE_OBJECT
  9408. IoGetRelatedDeviceObject(
  9409. IN PFILE_OBJECT FileObject
  9410. );
  9411. //++
  9412. //
  9413. // VOID
  9414. // IoInitializeDpcRequest(
  9415. // IN PDEVICE_OBJECT DeviceObject,
  9416. // IN PIO_DPC_ROUTINE DpcRoutine
  9417. // )
  9418. //
  9419. // Routine Description:
  9420. //
  9421. // This routine is invoked to initialize the DPC in a device object for a
  9422. // device driver during its initialization routine. The DPC is used later
  9423. // when the driver interrupt service routine requests that a DPC routine
  9424. // be queued for later execution.
  9425. //
  9426. // Arguments:
  9427. //
  9428. // DeviceObject - Pointer to the device object that the request is for.
  9429. //
  9430. // DpcRoutine - Address of the driver's DPC routine to be executed when
  9431. // the DPC is dequeued for processing.
  9432. //
  9433. // Return Value:
  9434. //
  9435. // None.
  9436. //
  9437. //--
  9438. #define IoInitializeDpcRequest( DeviceObject, DpcRoutine ) (\
  9439. KeInitializeDpc( &(DeviceObject)->Dpc, \
  9440. (PKDEFERRED_ROUTINE) (DpcRoutine), \
  9441. (DeviceObject) ) )
  9442. NTKERNELAPI
  9443. VOID
  9444. IoInitializeIrp(
  9445. IN OUT PIRP Irp,
  9446. IN USHORT PacketSize,
  9447. IN CCHAR StackSize
  9448. );
  9449. NTKERNELAPI
  9450. NTSTATUS
  9451. IoInitializeTimer(
  9452. IN PDEVICE_OBJECT DeviceObject,
  9453. IN PIO_TIMER_ROUTINE TimerRoutine,
  9454. IN PVOID Context
  9455. );
  9456. //++
  9457. //
  9458. // BOOLEAN
  9459. // IoIsErrorUserInduced(
  9460. // IN NTSTATUS Status
  9461. // )
  9462. //
  9463. // Routine Description:
  9464. //
  9465. // This routine is invoked to determine if an error was as a
  9466. // result of user actions. Typically these error are related
  9467. // to removable media and will result in a pop-up.
  9468. //
  9469. // Arguments:
  9470. //
  9471. // Status - The status value to check.
  9472. //
  9473. // Return Value:
  9474. //
  9475. // The function value is TRUE if the user induced the error,
  9476. // otherwise FALSE is returned.
  9477. //
  9478. //--
  9479. #define IoIsErrorUserInduced( Status ) ((BOOLEAN) \
  9480. (((Status) == STATUS_DEVICE_NOT_READY) || \
  9481. ((Status) == STATUS_IO_TIMEOUT) || \
  9482. ((Status) == STATUS_MEDIA_WRITE_PROTECTED) || \
  9483. ((Status) == STATUS_NO_MEDIA_IN_DEVICE) || \
  9484. ((Status) == STATUS_VERIFY_REQUIRED) || \
  9485. ((Status) == STATUS_UNRECOGNIZED_MEDIA) || \
  9486. ((Status) == STATUS_WRONG_VOLUME)))
  9487. //++
  9488. //
  9489. // VOID
  9490. // IoMarkIrpPending(
  9491. // IN OUT PIRP Irp
  9492. // )
  9493. //
  9494. // Routine Description:
  9495. //
  9496. // This routine marks the specified I/O Request Packet (IRP) to indicate
  9497. // that an initial status of STATUS_PENDING was returned to the caller.
  9498. // This is used so that I/O completion can determine whether or not to
  9499. // fully complete the I/O operation requested by the packet.
  9500. //
  9501. // Arguments:
  9502. //
  9503. // Irp - Pointer to the I/O Request Packet to be marked pending.
  9504. //
  9505. // Return Value:
  9506. //
  9507. // None.
  9508. //
  9509. //--
  9510. #define IoMarkIrpPending( Irp ) ( \
  9511. IoGetCurrentIrpStackLocation( (Irp) )->Control |= SL_PENDING_RETURNED )
  9512. NTKERNELAPI
  9513. NTSTATUS
  9514. IoQueryDeviceDescription(
  9515. IN PINTERFACE_TYPE BusType OPTIONAL,
  9516. IN PULONG BusNumber OPTIONAL,
  9517. IN PCONFIGURATION_TYPE ControllerType OPTIONAL,
  9518. IN PULONG ControllerNumber OPTIONAL,
  9519. IN PCONFIGURATION_TYPE PeripheralType OPTIONAL,
  9520. IN PULONG PeripheralNumber OPTIONAL,
  9521. IN PIO_QUERY_DEVICE_ROUTINE CalloutRoutine,
  9522. IN PVOID Context
  9523. );
  9524. NTKERNELAPI
  9525. NTSTATUS
  9526. IoRegisterShutdownNotification(
  9527. IN PDEVICE_OBJECT DeviceObject
  9528. );
  9529. NTKERNELAPI
  9530. VOID
  9531. IoReleaseCancelSpinLock(
  9532. IN KIRQL Irql
  9533. );
  9534. //++
  9535. //
  9536. // VOID
  9537. // IoRequestDpc(
  9538. // IN PDEVICE_OBJECT DeviceObject,
  9539. // IN PIRP Irp,
  9540. // IN PVOID Context
  9541. // )
  9542. //
  9543. // Routine Description:
  9544. //
  9545. // This routine is invoked by the device driver's interrupt service routine
  9546. // to request that a DPC routine be queued for later execution at a lower
  9547. // IRQL.
  9548. //
  9549. // Arguments:
  9550. //
  9551. // DeviceObject - Device object for which the request is being processed.
  9552. //
  9553. // Irp - Pointer to the current I/O Request Packet (IRP) for the specified
  9554. // device.
  9555. //
  9556. // Context - Provides a general context parameter to be passed to the
  9557. // DPC routine.
  9558. //
  9559. // Return Value:
  9560. //
  9561. // None.
  9562. //
  9563. //--
  9564. #define IoRequestDpc( DeviceObject, Irp, Context ) ( \
  9565. KeInsertQueueDpc( &(DeviceObject)->Dpc, (Irp), (Context) ) )
  9566. //++
  9567. //
  9568. // PDRIVER_CANCEL
  9569. // IoSetCancelRoutine(
  9570. // IN PIRP Irp,
  9571. // IN PDRIVER_CANCEL CancelRoutine
  9572. // )
  9573. //
  9574. // Routine Description:
  9575. //
  9576. // This routine is invoked to set the address of a cancel routine which
  9577. // is to be invoked when an I/O packet has been canceled.
  9578. //
  9579. // Arguments:
  9580. //
  9581. // Irp - Pointer to the I/O Request Packet itself.
  9582. //
  9583. // CancelRoutine - Address of the cancel routine that is to be invoked
  9584. // if the IRP is cancelled.
  9585. //
  9586. // Return Value:
  9587. //
  9588. // Previous value of CancelRoutine field in the IRP.
  9589. //
  9590. //--
  9591. #define IoSetCancelRoutine( Irp, NewCancelRoutine ) ( \
  9592. (PDRIVER_CANCEL) InterlockedExchange( (PLONG) &(Irp)->CancelRoutine, (LONG) (NewCancelRoutine) ) )
  9593. //++
  9594. //
  9595. // VOID
  9596. // IoSetCompletionRoutine(
  9597. // IN PIRP Irp,
  9598. // IN PIO_COMPLETION_ROUTINE CompletionRoutine,
  9599. // IN PVOID Context,
  9600. // IN BOOLEAN InvokeOnSuccess,
  9601. // IN BOOLEAN InvokeOnError,
  9602. // IN BOOLEAN InvokeOnCancel
  9603. // )
  9604. //
  9605. // Routine Description:
  9606. //
  9607. // This routine is invoked to set the address of a completion routine which
  9608. // is to be invoked when an I/O packet has been completed by a lower-level
  9609. // driver.
  9610. //
  9611. // Arguments:
  9612. //
  9613. // Irp - Pointer to the I/O Request Packet itself.
  9614. //
  9615. // CompletionRoutine - Address of the completion routine that is to be
  9616. // invoked once the next level driver completes the packet.
  9617. //
  9618. // Context - Specifies a context parameter to be passed to the completion
  9619. // routine.
  9620. //
  9621. // InvokeOnSuccess - Specifies that the completion routine is invoked when the
  9622. // operation is successfully completed.
  9623. //
  9624. // InvokeOnError - Specifies that the completion routine is invoked when the
  9625. // operation completes with an error status.
  9626. //
  9627. // InvokeOnCancel - Specifies that the completion routine is invoked when the
  9628. // operation is being canceled.
  9629. //
  9630. // Return Value:
  9631. //
  9632. // None.
  9633. //
  9634. //--
  9635. #define IoSetCompletionRoutine( Irp, Routine, CompletionContext, Success, Error, Cancel ) { \
  9636. PIO_STACK_LOCATION irpSp; \
  9637. ASSERT( (Success) | (Error) | (Cancel) ? (Routine) != NULL : TRUE ); \
  9638. irpSp = IoGetNextIrpStackLocation( (Irp) ); \
  9639. irpSp->CompletionRoutine = (Routine); \
  9640. irpSp->Context = (CompletionContext); \
  9641. irpSp->Control = 0; \
  9642. if ((Success)) { irpSp->Control = SL_INVOKE_ON_SUCCESS; } \
  9643. if ((Error)) { irpSp->Control |= SL_INVOKE_ON_ERROR; } \
  9644. if ((Cancel)) { irpSp->Control |= SL_INVOKE_ON_CANCEL; } }
  9645. //++
  9646. //
  9647. // VOID
  9648. // IoSetNextIrpStackLocation (
  9649. // IN OUT PIRP Irp
  9650. // )
  9651. //
  9652. // Routine Description:
  9653. //
  9654. // This routine is invoked to set the current IRP stack location to
  9655. // the next stack location, i.e. it "pushes" the stack.
  9656. //
  9657. // Arguments:
  9658. //
  9659. // Irp - Pointer to the I/O Request Packet (IRP).
  9660. //
  9661. // Return Value:
  9662. //
  9663. // None.
  9664. //
  9665. //--
  9666. #define IoSetNextIrpStackLocation( Irp ) { \
  9667. (Irp)->CurrentLocation--; \
  9668. (Irp)->Tail.Overlay.CurrentStackLocation--; }
  9669. NTKERNELAPI
  9670. VOID
  9671. IoSetShareAccess(
  9672. IN ACCESS_MASK DesiredAccess,
  9673. IN ULONG DesiredShareAccess,
  9674. IN OUT PFILE_OBJECT FileObject,
  9675. OUT PSHARE_ACCESS ShareAccess
  9676. );
  9677. //++
  9678. //
  9679. // USHORT
  9680. // IoSizeOfIrp(
  9681. // IN CCHAR StackSize
  9682. // )
  9683. //
  9684. // Routine Description:
  9685. //
  9686. // Determines the size of an IRP given the number of stack locations
  9687. // the IRP will have.
  9688. //
  9689. // Arguments:
  9690. //
  9691. // StackSize - Number of stack locations for the IRP.
  9692. //
  9693. // Return Value:
  9694. //
  9695. // Size in bytes of the IRP.
  9696. //
  9697. //--
  9698. #define IoSizeOfIrp( StackSize ) \
  9699. ((USHORT) (sizeof( IRP ) + ((StackSize) * (sizeof( IO_STACK_LOCATION )))))
  9700. NTKERNELAPI
  9701. VOID
  9702. IoStartNextPacket(
  9703. IN PDEVICE_OBJECT DeviceObject,
  9704. IN BOOLEAN Cancelable
  9705. );
  9706. NTKERNELAPI
  9707. VOID
  9708. IoStartNextPacketByKey(
  9709. IN PDEVICE_OBJECT DeviceObject,
  9710. IN BOOLEAN Cancelable,
  9711. IN ULONG Key
  9712. );
  9713. NTKERNELAPI
  9714. VOID
  9715. IoStartPacket(
  9716. IN PDEVICE_OBJECT DeviceObject,
  9717. IN PIRP Irp,
  9718. IN PULONG Key OPTIONAL,
  9719. IN PDRIVER_CANCEL CancelFunction OPTIONAL
  9720. );
  9721. NTKERNELAPI
  9722. VOID
  9723. IoStartTimer(
  9724. IN PDEVICE_OBJECT DeviceObject
  9725. );
  9726. NTKERNELAPI
  9727. VOID
  9728. IoStopTimer(
  9729. IN PDEVICE_OBJECT DeviceObject
  9730. );
  9731. NTKERNELAPI
  9732. VOID
  9733. IoUnregisterShutdownNotification(
  9734. IN PDEVICE_OBJECT DeviceObject
  9735. );
  9736. NTKERNELAPI
  9737. VOID
  9738. IoWriteErrorLogEntry(
  9739. IN PVOID ElEntry
  9740. );
  9741. #define MAX_CLASS_NAME_LEN 32 // defined by WIndows 95 in inc16\setupx.h
  9742. //
  9743. // Define PnP Device Property for IoGet/SetDeviceProperty
  9744. //
  9745. typedef enum {
  9746. DeviceDescription,
  9747. Configuration,
  9748. ConfigurationVector,
  9749. ClassGuid,
  9750. FriendlyName,
  9751. DeviceObjectName,
  9752. DriverKeyName,
  9753. DeviceSymbolicName
  9754. } DEVICE_REGISTRY_PROPERTY;
  9755. //
  9756. // Defines PnP notification event category
  9757. //
  9758. typedef enum _IO_NOTIFICATION_EVENT_CATEGORY {
  9759. EventCategoryHardwareProfileChange,
  9760. EventCategoryDeviceArrival,
  9761. EventCategoryDeviceRemoval
  9762. } IO_NOTIFICATION_EVENT_CATEGORY;
  9763. //
  9764. // Defines PnP notification event ids
  9765. //
  9766. typedef enum _IO_NOTIFICATION_EVENT_ID {
  9767. QueryHardwareProfileChange,
  9768. HardwareProfileChanged,
  9769. HardwareProfileChangeCancelled,
  9770. DeviceArrival,
  9771. DeviceQueryRemove,
  9772. DeviceQueryRemoveFailed,
  9773. DeviceRemoveComplete
  9774. } IO_NOTIFICATION_EVENT_ID;
  9775. typedef
  9776. NTSTATUS
  9777. (*PDRIVER_NOTIFICATION_ENTRY) (
  9778. IN PVOID Context,
  9779. IN IO_NOTIFICATION_EVENT_ID EventId,
  9780. IN PVOID NotificationStructure
  9781. );
  9782. //
  9783. // The following definitions are used in IoOpenDeviceRegistryKey
  9784. //
  9785. #define PLUGPLAY_REGKEY_DEVICE 1
  9786. #define PLUGPLAY_REGKEY_DRIVER 2
  9787. #define PLUGPLAY_REGKEY_CURRENT_HWPROFILE 4
  9788. NTKERNELAPI
  9789. NTSTATUS
  9790. IoOpenDeviceRegistryKey(
  9791. IN PDEVICE_OBJECT DeviceObject,
  9792. IN ULONG DevInstKeyType,
  9793. IN ACCESS_MASK DesiredAccess,
  9794. OUT PHANDLE DevInstRegKey
  9795. );
  9796. typedef VOID (*PCI_READ_WRITE_CONFIG)(
  9797. IN PDEVICE_OBJECT PciBusDeviceObject,
  9798. IN PVOID Buffer,
  9799. IN ULONG Offset,
  9800. IN ULONG Length
  9801. );
  9802. typedef enum {
  9803. // allocated interface ranges
  9804. BusInterfaceStandardFirst = 0,
  9805. BusInterfaceStandardLast = 0xff,
  9806. BusInterfaceBusTypeSpecificFirst = 0x100,
  9807. BusInterfaceBusTypeSpecificLast = 0x1ff,
  9808. // specified interfaces
  9809. BusInterfaceStandardBusAccess = 0,
  9810. } BUS_QUERY_INTERFACE_ENUM, *PBUS_QUERY_INTERFACE_ENUM;
  9811. typedef struct _BUS_QUERY_INTERFACE {
  9812. IN BUS_QUERY_INTERFACE_ENUM Interface;
  9813. OUT PVOID InterfaceEntryPoints;
  9814. } BUS_QUERY_INTERFACE, *PBUS_QUERY_INTERFACE;
  9815. typedef BOOLEAN (*PTRANSLATE_BUS_ADDRESS)(
  9816. IN DEVICE_OBJECT BusDeviceObject,
  9817. IN PHYSICAL_ADDRESS BusAddress,
  9818. IN OUT PULONG AddressSpace,
  9819. OUT PPHYSICAL_ADDRESS TranslatedAddress
  9820. );
  9821. typedef ULONG (*PGET_INTERRUPT_VECTOR)(
  9822. IN ULONG BusInterruptLevel,
  9823. IN ULONG BusInterruptVector,
  9824. OUT ULONG Vector,
  9825. OUT PKIRQL Irql,
  9826. OUT PKAFFINITY Affinity
  9827. );
  9828. typedef struct _DMA_OPERATIONS {
  9829. // PPUT_DMA_ADAPTER PutDmaAdapter;
  9830. // PALLOCATE_COMMON_BUFFER AllocateCommonBuffer;
  9831. // PFREE_COMMON_BUFFER FreeCommonBuffer;
  9832. // PALLOCATE_ADAPTER_CHANNEL AllocateAdapterChannel;
  9833. // PFLUSH_ADAPTER_BUFFER FlushAdapterBuffers;
  9834. // PFREE_ADAPTER_CHANNEL FreeAdapterChannel;
  9835. // PFREE_MAP_REGISTERS FreeMapRegisters;
  9836. // PMAP_TRANSFER MapTransfer;
  9837. // PGET_DMA_ALIGNMENT GetDmaAlignment;
  9838. // PREAD_DMA_COUNTER ReadDmaCounter;
  9839. ULONG WaitingForNTToDefineTHoseServices;
  9840. } DMA_OPERATIONS, *PDMA_OPERATIONS;
  9841. typedef struct _DMA_ADAPTER {
  9842. PDMA_OPERATIONS DmaOperations;
  9843. // Private Bus Device Driver data follows,
  9844. } DMA_ADAPTER, *PDMA_ADAPTER;
  9845. typedef PDMA_ADAPTER (*PGET_DMA_ADAPTER)(
  9846. IN DEVICE_OBJECT BusDeviceObject,
  9847. // IN PDEVICE_DESCRIPTION DeviceDescriptor,
  9848. OUT PULONG NumberOfMapRegisters
  9849. );
  9850. typedef VOID (*PPUT_DMA_ADAPTER)(
  9851. PDMA_ADAPTER DmaAdapter
  9852. );
  9853. typedef ULONG (*PGET_SET_DEVICE_DATA)(
  9854. IN PDEVICE_OBJECT BusDeviceObject,
  9855. IN ULONG DataType,
  9856. IN PVOID Buffer,
  9857. IN ULONG Offset,
  9858. IN ULONG Length
  9859. );
  9860. typedef VOID (*PCI_READ_WRITE_CONFIG)(
  9861. IN PDEVICE_OBJECT PciBusDeviceObject,
  9862. IN PVOID Buffer,
  9863. IN ULONG Offset,
  9864. IN ULONG Length
  9865. );
  9866. typedef struct _BUS_INTERFACE_STANDARD {
  9867. PTRANSLATE_BUS_ADDRESS TranslateBusAddress;
  9868. PGET_INTERRUPT_VECTOR GetInterruptVector;
  9869. PGET_DMA_ADAPTER GetDmaAdapter;
  9870. PGET_SET_DEVICE_DATA SetBusData;
  9871. PGET_SET_DEVICE_DATA GetBusData;
  9872. } BUS_INTERFACE_STANDARD, *PBUS_INTERFACE_STANDARD;
  9873. typedef VOID (*PCI_PIN_TO_LINE)(
  9874. IN PDEVICE_OBJECT PciBusDeviceObject,
  9875. IN PPCI_COMMON_CONFIG PciData
  9876. );
  9877. typedef VOID (*PCI_LINE_TO_PIN)(
  9878. IN PDEVICE_OBJECT PciBusDeviceObject,
  9879. IN PPCI_COMMON_CONFIG PciNewData,
  9880. IN PPCI_COMMON_CONFIG PciOldData
  9881. );
  9882. typedef enum {
  9883. PciBusInterface = BusInterfaceBusTypeSpecificFirst,
  9884. } PCI_BUS_QUERY_INTERFACE_TYPE, *PPCI_BUS_QUERY_INTERFACE_TYPE;
  9885. typedef struct _PCI_BUS_INTERFACE_STANDARD {
  9886. PCI_READ_WRITE_CONFIG ReadConfig;
  9887. PCI_READ_WRITE_CONFIG WriteConfig;
  9888. PCI_PIN_TO_LINE PinToLIne;
  9889. PCI_LINE_TO_PIN LineToPin;
  9890. } PCI_BUS_INTERFACE_STANDARD, *PPCI_BUS_INTERFACE_STANDARD;
  9891. //
  9892. // A POWER_STATE is in a POWER_STATE_SET
  9893. // if (PowerStateSet & (1 << PowerState)).
  9894. //
  9895. typedef ULONG POWER_STATE_SET;
  9896. typedef struct _BUS_QUERY_CAPABILITIES {
  9897. IN USHORT Size;
  9898. IN USHORT Version; // the version documented here is version 1
  9899. IN OUT POWER_STATE_SET ResumeSupported;
  9900. IN OUT ULONG PowerSupported: 1;
  9901. IN OUT ULONG LockSupported: 1;
  9902. IN OUT ULONG EjectSupported: 1;
  9903. IN OUT ULONG Removable: 1;
  9904. IN OUT ULONG GlobalUniqueId: 1;
  9905. IN OUT ULONG Reserved: 27;
  9906. } BUS_QUERY_CAPABILITIES, *PBUS_QUERY_CAPABILITIES;
  9907. typedef struct _DEVICE_RELATIONS {
  9908. ULONG Count;
  9909. PDEVICE_OBJECT Objects[1];
  9910. } DEVICE_RELATIONS, *PDEVICE_RELATIONS;
  9911. NTKERNELAPI
  9912. NTSTATUS
  9913. IoRegisterPlugPlayNotification(
  9914. IN IO_NOTIFICATION_EVENT_CATEGORY Event,
  9915. IN LPGUID ResourceType OPTIONAL,
  9916. IN PVOID ResourceDescription OPTIONAL,
  9917. IN PDEVICE_OBJECT DeviceObject,
  9918. IN PDRIVER_NOTIFICATION_ENTRY NotificationEntry,
  9919. IN PVOID Context
  9920. );
  9921. NTKERNELAPI
  9922. NTSTATUS
  9923. IoUnregisterPlugPlayNotification(
  9924. IN IO_NOTIFICATION_EVENT_CATEGORY Event,
  9925. IN LPGUID ResourceType OPTIONAL,
  9926. IN PVOID ResourceDescription OPTIONAL,
  9927. IN PDEVICE_OBJECT DeviceObject,
  9928. IN PDRIVER_NOTIFICATION_ENTRY NotificationEntry
  9929. );
  9930. NTKERNELAPI
  9931. NTSTATUS
  9932. IoGetDeviceProperty(
  9933. IN PDEVICE_OBJECT DeviceObject,
  9934. IN DEVICE_REGISTRY_PROPERTY DeviceProperty,
  9935. IN ULONG BufferLength,
  9936. OUT PVOID PropertyBuffer,
  9937. OUT PULONG ResultLength
  9938. );
  9939. NTKERNELAPI
  9940. NTSTATUS
  9941. IoSetDeviceClassAssociation(
  9942. IN PDEVICE_OBJECT PhysicalDeviceObject,
  9943. IN PDEVICE_OBJECT TargetDeviceObject,
  9944. IN LPGUID ClassGuid,
  9945. IN PUNICODE_STRING ReferenceString,
  9946. IN BOOLEAN Install
  9947. );
  9948. NTKERNELAPI
  9949. NTSTATUS
  9950. IoGetDeviceClassAssociations(
  9951. IN LPGUID ClassGuid,
  9952. OUT PWSTR *SymbolicLinkList
  9953. );
  9954. NTKERNELAPI
  9955. VOID
  9956. IoInvalidateDeviceRelations(
  9957. IN PDEVICE_OBJECT DeviceObject,
  9958. IN DEVICE_RELATION_TYPE Type
  9959. );
  9960. NTKERNELAPI
  9961. NTSTATUS
  9962. IoReportDeviceStatus(
  9963. IN PDEVICE_OBJECT DeviceObject,
  9964. IN ULONG DeviceStatus
  9965. );
  9966. NTKERNELAPI
  9967. NTSTATUS
  9968. IoSetDeviceProperty(
  9969. IN PDEVICE_OBJECT DeviceObject,
  9970. IN DEVICE_REGISTRY_PROPERTY DeviceProperty,
  9971. IN PVOID PropertyBuffer,
  9972. IN ULONG BufferLength
  9973. );
  9974. //
  9975. // structure for IRP_MN_SET_POWER
  9976. //
  9977. //
  9978. // Define the device description structure.
  9979. //
  9980. typedef struct _DEVICE_DESCRIPTION {
  9981. ULONG Version;
  9982. BOOLEAN Master;
  9983. BOOLEAN ScatterGather;
  9984. BOOLEAN DemandMode;
  9985. BOOLEAN AutoInitialize;
  9986. BOOLEAN Dma32BitAddresses;
  9987. BOOLEAN IgnoreCount;
  9988. BOOLEAN Reserved1; // must be false
  9989. BOOLEAN Reserved2; // must be false
  9990. ULONG BusNumber;
  9991. ULONG DmaChannel;
  9992. INTERFACE_TYPE InterfaceType;
  9993. DMA_WIDTH DmaWidth;
  9994. DMA_SPEED DmaSpeed;
  9995. ULONG MaximumLength;
  9996. ULONG DmaPort;
  9997. } DEVICE_DESCRIPTION, *PDEVICE_DESCRIPTION;
  9998. //
  9999. // Define the supported version numbers for the device description structure.
  10000. //
  10001. #define DEVICE_DESCRIPTION_VERSION 0
  10002. #define DEVICE_DESCRIPTION_VERSION1 1
  10003. //
  10004. // The following function prototypes are for HAL routines with a prefix of Hal.
  10005. //
  10006. // General functions.
  10007. //
  10008. typedef
  10009. BOOLEAN
  10010. (*PHAL_RESET_DISPLAY_PARAMETERS) (
  10011. IN ULONG Columns,
  10012. IN ULONG Rows
  10013. );
  10014. #if defined(_MIPS_) || defined(_ALPHA_) || defined(_PPC_)
  10015. NTHALAPI
  10016. ULONG
  10017. HalGetDmaAlignmentRequirement (
  10018. VOID
  10019. );
  10020. #endif
  10021. #if defined(_M_IX86)
  10022. #define HalGetDmaAlignmentRequirement() 1L
  10023. #endif
  10024. #if !defined(_M_IX86)
  10025. NTHALAPI
  10026. VOID
  10027. KeFlushWriteBuffer (
  10028. VOID
  10029. );
  10030. #endif
  10031. //
  10032. // I/O driver configuration functions.
  10033. //
  10034. NTHALAPI
  10035. ULONG
  10036. HalGetInterruptVector(
  10037. IN INTERFACE_TYPE InterfaceType,
  10038. IN ULONG BusNumber,
  10039. IN ULONG BusInterruptLevel,
  10040. IN ULONG BusInterruptVector,
  10041. OUT PKIRQL Irql,
  10042. OUT PKAFFINITY Affinity
  10043. );
  10044. NTHALAPI
  10045. BOOLEAN
  10046. HalTranslateBusAddress(
  10047. IN INTERFACE_TYPE InterfaceType,
  10048. IN ULONG BusNumber,
  10049. IN PHYSICAL_ADDRESS BusAddress,
  10050. IN OUT PULONG AddressSpace,
  10051. OUT PPHYSICAL_ADDRESS TranslatedAddress
  10052. );
  10053. //
  10054. // Values for AddressSpace parameter of HalTranslateBusAddress
  10055. //
  10056. // 0x0 - Memory space
  10057. // 0x1 - Port space
  10058. // 0x2 - 0x1F - Address spaces specific for Alpha
  10059. // 0x2 - UserMode view of memory space
  10060. // 0x3 - UserMode view of port space
  10061. // 0x4 - Dense memory space
  10062. // 0x5 - reserved
  10063. // 0x6 - UserMode view of dense memory space
  10064. // 0x7 - 0x1F - reserved
  10065. //
  10066. //
  10067. // DMA adapter object functions.
  10068. //
  10069. NTHALAPI
  10070. PVOID
  10071. HalAllocateCommonBuffer(
  10072. IN PADAPTER_OBJECT AdapterObject,
  10073. IN ULONG Length,
  10074. OUT PPHYSICAL_ADDRESS LogicalAddress,
  10075. IN BOOLEAN CacheEnabled
  10076. );
  10077. NTHALAPI
  10078. VOID
  10079. HalFreeCommonBuffer(
  10080. IN PADAPTER_OBJECT AdapterObject,
  10081. IN ULONG Length,
  10082. IN PHYSICAL_ADDRESS LogicalAddress,
  10083. IN PVOID VirtualAddress,
  10084. IN BOOLEAN CacheEnabled
  10085. );
  10086. NTHALAPI
  10087. PADAPTER_OBJECT
  10088. HalGetAdapter(
  10089. IN PDEVICE_DESCRIPTION DeviceDescription,
  10090. IN OUT PULONG NumberOfMapRegisters
  10091. );
  10092. //
  10093. // The following function prototypes are for HAL routines with a prefix of Io.
  10094. //
  10095. // DMA adapter object functions.
  10096. //
  10097. NTHALAPI
  10098. ULONG
  10099. HalReadDmaCounter(
  10100. IN PADAPTER_OBJECT AdapterObject
  10101. );
  10102. NTHALAPI
  10103. BOOLEAN
  10104. IoFlushAdapterBuffers(
  10105. IN PADAPTER_OBJECT AdapterObject,
  10106. IN PMDL Mdl,
  10107. IN PVOID MapRegisterBase,
  10108. IN PVOID CurrentVa,
  10109. IN ULONG Length,
  10110. IN BOOLEAN WriteToDevice
  10111. );
  10112. NTHALAPI
  10113. VOID
  10114. IoFreeAdapterChannel(
  10115. IN PADAPTER_OBJECT AdapterObject
  10116. );
  10117. NTHALAPI
  10118. VOID
  10119. IoFreeMapRegisters(
  10120. IN PADAPTER_OBJECT AdapterObject,
  10121. IN PVOID MapRegisterBase,
  10122. IN ULONG NumberOfMapRegisters
  10123. );
  10124. NTHALAPI
  10125. PHYSICAL_ADDRESS
  10126. IoMapTransfer(
  10127. IN PADAPTER_OBJECT AdapterObject,
  10128. IN PMDL Mdl,
  10129. IN PVOID MapRegisterBase,
  10130. IN PVOID CurrentVa,
  10131. IN OUT PULONG Length,
  10132. IN BOOLEAN WriteToDevice
  10133. );
  10134. //
  10135. // Performance counter function.
  10136. //
  10137. NTHALAPI
  10138. LARGE_INTEGER
  10139. KeQueryPerformanceCounter (
  10140. IN PLARGE_INTEGER PerformanceFrequency OPTIONAL
  10141. );
  10142. // begin_ntndis
  10143. //
  10144. // Stall processor execution function.
  10145. //
  10146. NTHALAPI
  10147. VOID
  10148. KeStallExecutionProcessor (
  10149. IN ULONG MicroSeconds
  10150. );
  10151. #if defined(_X86_)
  10152. // for the information class "HalMcaLogInformation"
  10153. //
  10154. // ADDR register for each MCA bank
  10155. //
  10156. typedef union _MCI_ADDR{
  10157. struct {
  10158. ULONG Address;
  10159. ULONG Reserved;
  10160. };
  10161. ULONGLONG QuadPart;
  10162. } MCI_ADDR, *PMCI_ADDR;
  10163. typedef enum {
  10164. HAL_MCE_RECORD,
  10165. HAL_MCA_RECORD
  10166. } MCA_EXCEPTION_TYPE;
  10167. //
  10168. // MCA exception log entry
  10169. // Defined as a union to contain MCA specific log or Pentium style MCE info.
  10170. //
  10171. typedef struct _MCA_EXCEPTION {
  10172. ULONG VersionNumber; // Version number of this record type
  10173. MCA_EXCEPTION_TYPE ExceptionType; // MCA or MCE
  10174. LARGE_INTEGER TimeStamp; // exception recording timestamp
  10175. ULONG ProcessorNumber;
  10176. union {
  10177. struct {
  10178. UCHAR BankNumber;
  10179. MCI_STATS Status;
  10180. MCI_ADDR Address;
  10181. ULONGLONG Misc;
  10182. } Mca;
  10183. struct {
  10184. ULONGLONG Address; // physical addr of cycle causing the error
  10185. ULONGLONG Type; // cycle specification causing the error
  10186. } Mce;
  10187. } u;
  10188. } MCA_EXCEPTION, *PMCA_EXCEPTION;
  10189. // for the information class "HalMcaRegisterDriver"
  10190. typedef
  10191. VOID
  10192. (*PDRIVER_EXCPTN_CALLBACK) (
  10193. IN PVOID Context,
  10194. IN PMCA_EXCEPTION BankLog
  10195. );
  10196. //
  10197. // Structure to record the callbacks from driver
  10198. //
  10199. typedef struct _MCA_DRIVER_INFO {
  10200. PDRIVER_EXCPTN_CALLBACK ExceptionCallback;
  10201. PKDEFERRED_ROUTINE DpcCallback;
  10202. PVOID DeviceContext;
  10203. } MCA_DRIVER_INFO, *PMCA_DRIVER_INFO;
  10204. #endif
  10205. //
  10206. // Object Manager types
  10207. //
  10208. typedef struct _OBJECT_HANDLE_INFORMATION {
  10209. ULONG HandleAttributes;
  10210. ACCESS_MASK GrantedAccess;
  10211. } OBJECT_HANDLE_INFORMATION, *POBJECT_HANDLE_INFORMATION;
  10212. NTKERNELAPI
  10213. NTSTATUS
  10214. ObReferenceObjectByHandle(
  10215. IN HANDLE Handle,
  10216. IN ACCESS_MASK DesiredAccess,
  10217. IN POBJECT_TYPE ObjectType OPTIONAL,
  10218. IN KPROCESSOR_MODE AccessMode,
  10219. OUT PVOID *Object,
  10220. OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL
  10221. );
  10222. #define ObDereferenceObject(a) \
  10223. ObfDereferenceObject(a)
  10224. #define ObReferenceObject(Object) ObfReferenceObject(Object)
  10225. NTKERNELAPI
  10226. VOID
  10227. FASTCALL
  10228. ObfReferenceObject(
  10229. IN PVOID Object
  10230. );
  10231. NTKERNELAPI
  10232. NTSTATUS
  10233. ObReferenceObjectByPointer(
  10234. IN PVOID Object,
  10235. IN ACCESS_MASK DesiredAccess,
  10236. IN POBJECT_TYPE ObjectType,
  10237. IN KPROCESSOR_MODE AccessMode
  10238. );
  10239. NTKERNELAPI
  10240. VOID
  10241. FASTCALL
  10242. ObfDereferenceObject(
  10243. IN PVOID Object
  10244. );
  10245. #ifdef POOL_TAGGING
  10246. #define ExAllocatePool(a,b) ExAllocatePoolWithTag(a,b,' kdD')
  10247. #endif
  10248. extern POBJECT_TYPE *IoFileObjectType;
  10249. extern POBJECT_TYPE *ExEventObjectType;
  10250. //
  10251. // Define exported ZwXxx routines to device drivers.
  10252. //
  10253. NTSYSAPI
  10254. NTSTATUS
  10255. NTAPI
  10256. ZwCreateFile(
  10257. OUT PHANDLE FileHandle,
  10258. IN ACCESS_MASK DesiredAccess,
  10259. IN POBJECT_ATTRIBUTES ObjectAttributes,
  10260. OUT PIO_STATUS_BLOCK IoStatusBlock,
  10261. IN PLARGE_INTEGER AllocationSize OPTIONAL,
  10262. IN ULONG FileAttributes,
  10263. IN ULONG ShareAccess,
  10264. IN ULONG CreateDisposition,
  10265. IN ULONG CreateOptions,
  10266. IN PVOID EaBuffer OPTIONAL,
  10267. IN ULONG EaLength
  10268. );
  10269. NTSYSAPI
  10270. NTSTATUS
  10271. NTAPI
  10272. ZwClose(
  10273. IN HANDLE Handle
  10274. );
  10275. NTSYSAPI
  10276. NTSTATUS
  10277. NTAPI
  10278. ZwCreateDirectoryObject(
  10279. OUT PHANDLE DirectoryHandle,
  10280. IN ACCESS_MASK DesiredAccess,
  10281. IN POBJECT_ATTRIBUTES ObjectAttributes
  10282. );
  10283. NTSYSAPI
  10284. NTSTATUS
  10285. NTAPI
  10286. ZwOpenSection(
  10287. OUT PHANDLE SectionHandle,
  10288. IN ACCESS_MASK DesiredAccess,
  10289. IN POBJECT_ATTRIBUTES ObjectAttributes
  10290. );
  10291. NTSYSAPI
  10292. NTSTATUS
  10293. NTAPI
  10294. ZwMapViewOfSection(
  10295. IN HANDLE SectionHandle,
  10296. IN HANDLE ProcessHandle,
  10297. IN OUT PVOID *BaseAddress,
  10298. IN ULONG ZeroBits,
  10299. IN ULONG CommitSize,
  10300. IN OUT PLARGE_INTEGER SectionOffset OPTIONAL,
  10301. IN OUT PULONG ViewSize,
  10302. IN SECTION_INHERIT InheritDisposition,
  10303. IN ULONG AllocationType,
  10304. IN ULONG Protect
  10305. );
  10306. NTSYSAPI
  10307. NTSTATUS
  10308. NTAPI
  10309. ZwUnmapViewOfSection(
  10310. IN HANDLE ProcessHandle,
  10311. IN PVOID BaseAddress
  10312. );
  10313. NTSYSAPI
  10314. NTSTATUS
  10315. NTAPI
  10316. ZwCreateKey(
  10317. OUT PHANDLE KeyHandle,
  10318. IN ACCESS_MASK DesiredAccess,
  10319. IN POBJECT_ATTRIBUTES ObjectAttributes,
  10320. IN ULONG TitleIndex,
  10321. IN PUNICODE_STRING Class OPTIONAL,
  10322. IN ULONG CreateOptions,
  10323. OUT PULONG Disposition OPTIONAL
  10324. );
  10325. NTSYSAPI
  10326. NTSTATUS
  10327. NTAPI
  10328. ZwOpenKey(
  10329. OUT PHANDLE KeyHandle,
  10330. IN ACCESS_MASK DesiredAccess,
  10331. IN POBJECT_ATTRIBUTES ObjectAttributes
  10332. );
  10333. NTSYSAPI
  10334. NTSTATUS
  10335. NTAPI
  10336. ZwDeleteKey(
  10337. IN HANDLE KeyHandle
  10338. );
  10339. NTSYSAPI
  10340. NTSTATUS
  10341. NTAPI
  10342. ZwEnumerateKey(
  10343. IN HANDLE KeyHandle,
  10344. IN ULONG Index,
  10345. IN KEY_INFORMATION_CLASS KeyInformationClass,
  10346. OUT PVOID KeyInformation,
  10347. IN ULONG Length,
  10348. OUT PULONG ResultLength
  10349. );
  10350. NTSYSAPI
  10351. NTSTATUS
  10352. NTAPI
  10353. ZwEnumerateValueKey(
  10354. IN HANDLE KeyHandle,
  10355. IN ULONG Index,
  10356. IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
  10357. OUT PVOID KeyValueInformation,
  10358. IN ULONG Length,
  10359. OUT PULONG ResultLength
  10360. );
  10361. NTSYSAPI
  10362. NTSTATUS
  10363. NTAPI
  10364. ZwQueryKey(
  10365. IN HANDLE KeyHandle,
  10366. IN KEY_INFORMATION_CLASS KeyInformationClass,
  10367. OUT PVOID KeyInformation,
  10368. IN ULONG Length,
  10369. OUT PULONG ResultLength
  10370. );
  10371. NTSYSAPI
  10372. NTSTATUS
  10373. NTAPI
  10374. ZwQueryValueKey(
  10375. IN HANDLE KeyHandle,
  10376. IN PUNICODE_STRING ValueName,
  10377. IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
  10378. OUT PVOID KeyValueInformation,
  10379. IN ULONG Length,
  10380. OUT PULONG ResultLength
  10381. );
  10382. NTSYSAPI
  10383. NTSTATUS
  10384. NTAPI
  10385. ZwSetValueKey(
  10386. IN HANDLE KeyHandle,
  10387. IN PUNICODE_STRING ValueName,
  10388. IN ULONG TitleIndex OPTIONAL,
  10389. IN ULONG Type,
  10390. IN PVOID Data,
  10391. IN ULONG DataSize
  10392. );
  10393. #endif // _WDMDDK_