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

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