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

552 lines
15 KiB

  1. /*++ BUILD Version: 0003 // Increment this if a change has global effects
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. ntosdef.h
  5. Abstract:
  6. Common type definitions for the NTOS component that are private to
  7. NTOS, but shared between NTOS sub-components.
  8. Author:
  9. Steve Wood (stevewo) 08-May-1989
  10. Revision History:
  11. --*/
  12. #ifndef _NTOSDEF_
  13. #define _NTOSDEF_
  14. // begin_ntosp
  15. //
  16. // Define per processor nonpaged lookaside list descriptor structure.
  17. //
  18. struct _NPAGED_LOOKASIDE_LIST;
  19. typedef struct _PP_LOOKASIDE_LIST {
  20. struct _GENERAL_LOOKASIDE *P;
  21. struct _GENERAL_LOOKASIDE *L;
  22. } PP_LOOKASIDE_LIST, *PPP_LOOKASIDE_LIST;
  23. //
  24. // Define the number of small pool lists.
  25. //
  26. // N.B. This value is used in pool.h and is used to allocate single entry
  27. // lookaside lists in the processor block of each processor.
  28. #define POOL_SMALL_LISTS 32
  29. // begin_ntddk begin_wdm begin_nthal begin_ntifs
  30. //
  31. // Define alignment macros to align structure sizes and pointers up and down.
  32. //
  33. #define ALIGN_DOWN(length, type) \
  34. ((ULONG)(length) & ~(sizeof(type) - 1))
  35. #define ALIGN_UP(length, type) \
  36. (ALIGN_DOWN(((ULONG)(length) + sizeof(type) - 1), type))
  37. #define ALIGN_DOWN_POINTER(address, type) \
  38. ((PVOID)((ULONG_PTR)(address) & ~((ULONG_PTR)sizeof(type) - 1)))
  39. #define ALIGN_UP_POINTER(address, type) \
  40. (ALIGN_DOWN_POINTER(((ULONG_PTR)(address) + sizeof(type) - 1), type))
  41. #define POOL_TAGGING 1
  42. #ifndef DBG
  43. #define DBG 0
  44. #endif
  45. #if DBG
  46. #define IF_DEBUG if (TRUE)
  47. #else
  48. #define IF_DEBUG if (FALSE)
  49. #endif
  50. #if DEVL
  51. // end_ntddk end_wdm end_nthal end_ntifs end_ntosp
  52. //
  53. // Global flag set by NtPartyByNumber(6) controls behaviour of
  54. // NT. See \nt\sdk\inc\ntexapi.h for flag definitions
  55. //
  56. // begin_ntddk begin_wdm begin_nthal begin_ntifs begin_ntosp
  57. extern ULONG NtGlobalFlag;
  58. #define IF_NTOS_DEBUG( FlagName ) \
  59. if (NtGlobalFlag & (FLG_ ## FlagName))
  60. #else
  61. #define IF_NTOS_DEBUG( FlagName ) if (FALSE)
  62. #endif
  63. //
  64. // Kernel definitions that need to be here for forward reference purposes
  65. //
  66. // begin_ntndis
  67. //
  68. // Processor modes.
  69. //
  70. typedef CCHAR KPROCESSOR_MODE;
  71. typedef enum _MODE {
  72. KernelMode,
  73. UserMode,
  74. MaximumMode
  75. } MODE;
  76. // end_ntndis
  77. //
  78. // APC function types
  79. //
  80. //
  81. // Put in an empty definition for the KAPC so that the
  82. // routines can reference it before it is declared.
  83. //
  84. struct _KAPC;
  85. typedef
  86. VOID
  87. (*PKNORMAL_ROUTINE) (
  88. IN PVOID NormalContext,
  89. IN PVOID SystemArgument1,
  90. IN PVOID SystemArgument2
  91. );
  92. typedef
  93. VOID
  94. (*PKKERNEL_ROUTINE) (
  95. IN struct _KAPC *Apc,
  96. IN OUT PKNORMAL_ROUTINE *NormalRoutine,
  97. IN OUT PVOID *NormalContext,
  98. IN OUT PVOID *SystemArgument1,
  99. IN OUT PVOID *SystemArgument2
  100. );
  101. typedef
  102. VOID
  103. (*PKRUNDOWN_ROUTINE) (
  104. IN struct _KAPC *Apc
  105. );
  106. typedef
  107. BOOLEAN
  108. (*PKSYNCHRONIZE_ROUTINE) (
  109. IN PVOID SynchronizeContext
  110. );
  111. typedef
  112. BOOLEAN
  113. (*PKTRANSFER_ROUTINE) (
  114. VOID
  115. );
  116. //
  117. //
  118. // Asynchronous Procedure Call (APC) object
  119. //
  120. //
  121. typedef struct _KAPC {
  122. CSHORT Type;
  123. CSHORT Size;
  124. ULONG Spare0;
  125. struct _KTHREAD *Thread;
  126. LIST_ENTRY ApcListEntry;
  127. PKKERNEL_ROUTINE KernelRoutine;
  128. PKRUNDOWN_ROUTINE RundownRoutine;
  129. PKNORMAL_ROUTINE NormalRoutine;
  130. PVOID NormalContext;
  131. //
  132. // N.B. The following two members MUST be together.
  133. //
  134. PVOID SystemArgument1;
  135. PVOID SystemArgument2;
  136. CCHAR ApcStateIndex;
  137. KPROCESSOR_MODE ApcMode;
  138. BOOLEAN Inserted;
  139. } KAPC, *PKAPC, *RESTRICTED_POINTER PRKAPC;
  140. // begin_ntndis
  141. //
  142. // DPC routine
  143. //
  144. struct _KDPC;
  145. typedef
  146. VOID
  147. (*PKDEFERRED_ROUTINE) (
  148. IN struct _KDPC *Dpc,
  149. IN PVOID DeferredContext,
  150. IN PVOID SystemArgument1,
  151. IN PVOID SystemArgument2
  152. );
  153. //
  154. // Define DPC importance.
  155. //
  156. // LowImportance - Queue DPC at end of target DPC queue.
  157. // MediumImportance - Queue DPC at end of target DPC queue.
  158. // HighImportance - Queue DPC at front of target DPC DPC queue.
  159. //
  160. // If there is currently a DPC active on the target processor, or a DPC
  161. // interrupt has already been requested on the target processor when a
  162. // DPC is queued, then no further action is necessary. The DPC will be
  163. // executed on the target processor when its queue entry is processed.
  164. //
  165. // If there is not a DPC active on the target processor and a DPC interrupt
  166. // has not been requested on the target processor, then the exact treatment
  167. // of the DPC is dependent on whether the host system is a UP system or an
  168. // MP system.
  169. //
  170. // UP system.
  171. //
  172. // If the DPC is of medium or high importance, the current DPC queue depth
  173. // is greater than the maximum target depth, or current DPC request rate is
  174. // less the minimum target rate, then a DPC interrupt is requested on the
  175. // host processor and the DPC will be processed when the interrupt occurs.
  176. // Otherwise, no DPC interupt is requested and the DPC execution will be
  177. // delayed until the DPC queue depth is greater that the target depth or the
  178. // minimum DPC rate is less than the target rate.
  179. //
  180. // MP system.
  181. //
  182. // If the DPC is being queued to another processor and the depth of the DPC
  183. // queue on the target processor is greater than the maximum target depth or
  184. // the DPC is of high importance, then a DPC interrupt is requested on the
  185. // target processor and the DPC will be processed when the interrupt occurs.
  186. // Otherwise, the DPC execution will be delayed on the target processor until
  187. // the DPC queue depth on the target processor is greater that the maximum
  188. // target depth or the minimum DPC rate on the target processor is less than
  189. // the target mimimum rate.
  190. //
  191. // If the DPC is being queued to the current processor and the DPC is not of
  192. // low importance, the current DPC queue depth is greater than the maximum
  193. // target depth, or the minimum DPC rate is less than the minimum target rate,
  194. // then a DPC interrupt is request on the current processor and the DPV will
  195. // be processed whne the interrupt occurs. Otherwise, no DPC interupt is
  196. // requested and the DPC execution will be delayed until the DPC queue depth
  197. // is greater that the target depth or the minimum DPC rate is less than the
  198. // target rate.
  199. //
  200. typedef enum _KDPC_IMPORTANCE {
  201. LowImportance,
  202. MediumImportance,
  203. HighImportance
  204. } KDPC_IMPORTANCE;
  205. //
  206. // Deferred Procedure Call (DPC) object
  207. //
  208. typedef struct _KDPC {
  209. CSHORT Type;
  210. UCHAR Number;
  211. UCHAR Importance;
  212. LIST_ENTRY DpcListEntry;
  213. PKDEFERRED_ROUTINE DeferredRoutine;
  214. PVOID DeferredContext;
  215. PVOID SystemArgument1;
  216. PVOID SystemArgument2;
  217. PULONG_PTR Lock;
  218. } KDPC, *PKDPC, *RESTRICTED_POINTER PRKDPC;
  219. //
  220. // Interprocessor interrupt worker routine function prototype.
  221. //
  222. typedef PVOID PKIPI_CONTEXT;
  223. typedef
  224. VOID
  225. (*PKIPI_WORKER)(
  226. IN PKIPI_CONTEXT PacketContext,
  227. IN PVOID Parameter1,
  228. IN PVOID Parameter2,
  229. IN PVOID Parameter3
  230. );
  231. //
  232. // Define interprocessor interrupt performance counters.
  233. //
  234. typedef struct _KIPI_COUNTS {
  235. ULONG Freeze;
  236. ULONG Packet;
  237. ULONG DPC;
  238. ULONG APC;
  239. ULONG FlushSingleTb;
  240. ULONG FlushMultipleTb;
  241. ULONG FlushEntireTb;
  242. ULONG GenericCall;
  243. ULONG ChangeColor;
  244. ULONG SweepDcache;
  245. ULONG SweepIcache;
  246. ULONG SweepIcacheRange;
  247. ULONG FlushIoBuffers;
  248. ULONG GratuitousDPC;
  249. } KIPI_COUNTS, *PKIPI_COUNTS;
  250. #if defined(NT_UP)
  251. #define HOT_STATISTIC(a) a
  252. #else
  253. #define HOT_STATISTIC(a) (KeGetCurrentPrcb()->a)
  254. #endif
  255. //
  256. // I/O system definitions.
  257. //
  258. // Define a Memory Descriptor List (MDL)
  259. //
  260. // An MDL describes pages in a virtual buffer in terms of physical pages. The
  261. // pages associated with the buffer are described in an array that is allocated
  262. // just after the MDL header structure itself. In a future compiler this will
  263. // be placed at:
  264. //
  265. // ULONG Pages[];
  266. //
  267. // Until this declaration is permitted, however, one simply calculates the
  268. // base of the array by adding one to the base MDL pointer:
  269. //
  270. // Pages = (PULONG) (Mdl + 1);
  271. //
  272. // Notice that while in the context of the subject thread, the base virtual
  273. // address of a buffer mapped by an MDL may be referenced using the following:
  274. //
  275. // Mdl->StartVa | Mdl->ByteOffset
  276. //
  277. typedef struct _MDL {
  278. struct _MDL *Next;
  279. CSHORT Size;
  280. CSHORT MdlFlags;
  281. struct _EPROCESS *Process;
  282. PVOID MappedSystemVa;
  283. PVOID StartVa;
  284. ULONG ByteCount;
  285. ULONG ByteOffset;
  286. } MDL, *PMDL;
  287. #define MDL_MAPPED_TO_SYSTEM_VA 0x0001
  288. #define MDL_PAGES_LOCKED 0x0002
  289. #define MDL_SOURCE_IS_NONPAGED_POOL 0x0004
  290. #define MDL_ALLOCATED_FIXED_SIZE 0x0008
  291. #define MDL_PARTIAL 0x0010
  292. #define MDL_PARTIAL_HAS_BEEN_MAPPED 0x0020
  293. #define MDL_IO_PAGE_READ 0x0040
  294. #define MDL_WRITE_OPERATION 0x0080
  295. #define MDL_PARENT_MAPPED_SYSTEM_VA 0x0100
  296. #define MDL_FREE_EXTRA_PTES 0x0200
  297. #define MDL_IO_SPACE 0x0800
  298. #define MDL_NETWORK_HEADER 0x1000
  299. #define MDL_MAPPING_CAN_FAIL 0x2000
  300. #define MDL_ALLOCATED_MUST_SUCCEED 0x4000
  301. #define MDL_MAPPING_FLAGS (MDL_MAPPED_TO_SYSTEM_VA | \
  302. MDL_PAGES_LOCKED | \
  303. MDL_SOURCE_IS_NONPAGED_POOL | \
  304. MDL_PARTIAL_HAS_BEEN_MAPPED | \
  305. MDL_PARENT_MAPPED_SYSTEM_VA | \
  306. MDL_SYSTEM_VA | \
  307. MDL_IO_SPACE )
  308. // end_ntndis
  309. //
  310. // switch to DBG when appropriate
  311. //
  312. #if DBG
  313. #define PAGED_CODE() \
  314. { if (KeGetCurrentIrql() > APC_LEVEL) { \
  315. KdPrint(( "EX: Pageable code called at IRQL %d\n", KeGetCurrentIrql() )); \
  316. ASSERT(FALSE); \
  317. } \
  318. }
  319. #else
  320. #define PAGED_CODE() NOP_FUNCTION;
  321. #endif
  322. // end_ntddk end_wdm end_nthal end_ntifs end_ntosp
  323. // begin_ntifs begin_ntosp
  324. //
  325. // Data structure used to represent client security context for a thread.
  326. // This data structure is used to support impersonation.
  327. //
  328. // THE FIELDS OF THIS DATA STRUCTURE SHOULD BE CONSIDERED OPAQUE
  329. // BY ALL EXCEPT THE SECURITY ROUTINES.
  330. //
  331. typedef struct _SECURITY_CLIENT_CONTEXT {
  332. SECURITY_QUALITY_OF_SERVICE SecurityQos;
  333. PACCESS_TOKEN ClientToken;
  334. BOOLEAN DirectlyAccessClientToken;
  335. BOOLEAN DirectAccessEffectiveOnly;
  336. BOOLEAN ServerIsRemote;
  337. TOKEN_CONTROL ClientTokenControl;
  338. } SECURITY_CLIENT_CONTEXT, *PSECURITY_CLIENT_CONTEXT;
  339. //
  340. // where
  341. //
  342. // SecurityQos - is the security quality of service information in effect
  343. // for this client. This information is used when directly accessing
  344. // the client's token. In this case, the information here over-rides
  345. // the information in the client's token. If a copy of the client's
  346. // token is requested, it must be generated using this information,
  347. // not the information in the client's token. In all cases, this
  348. // information may not provide greater access than the information
  349. // in the client's token. In particular, if the client's token is
  350. // an impersonation token with an impersonation level of
  351. // "SecurityDelegation", but the information in this field indicates
  352. // an impersonation level of "SecurityIdentification", then
  353. // the server may only get a copy of the token with an Identification
  354. // level of impersonation.
  355. //
  356. // ClientToken - If the DirectlyAccessClientToken field is FALSE,
  357. // then this field contains a pointer to a duplicate of the
  358. // client's token. Otherwise, this field points directly to
  359. // the client's token.
  360. //
  361. // DirectlyAccessClientToken - This boolean flag indicates whether the
  362. // token pointed to by ClientToken is a copy of the client's token
  363. // or is a direct reference to the client's token. A value of TRUE
  364. // indicates the client's token is directly accessed, FALSE indicates
  365. // a copy has been made.
  366. //
  367. // DirectAccessEffectiveOnly - This boolean flag indicates whether the
  368. // the disabled portions of the token that is currently directly
  369. // referenced may be enabled. This field is only valid if the
  370. // DirectlyAccessClientToken field is TRUE. In that case, this
  371. // value supersedes the EffectiveOnly value in the SecurityQos
  372. // FOR THE CURRENT TOKEN ONLY! If the client changes to impersonate
  373. // another client, this value may change. This value is always
  374. // minimized by the EffectiveOnly flag in the SecurityQos field.
  375. //
  376. // ServerIsRemote - If TRUE indicates that the server of the client's
  377. // request is remote. This is used for determining the legitimacy
  378. // of certain levels of impersonation and to determine how to
  379. // track context.
  380. //
  381. // ClientTokenControl - If the ServerIsRemote flag is TRUE, and the
  382. // tracking mode is DYNAMIC, then this field contains a copy of
  383. // the TOKEN_SOURCE from the client's token to assist in deciding
  384. // whether the information at the remote server needs to be
  385. // updated to match the current state of the client's security
  386. // context.
  387. //
  388. //
  389. // NOTE: At some point, we may find it worthwhile to keep an array of
  390. // elements in this data structure, where each element of the
  391. // array contains {ClientToken, ClientTokenControl} fields.
  392. // This would allow efficient handling of the case where a client
  393. // thread was constantly switching between a couple different
  394. // contexts - presumably impersonating client's of its own.
  395. //
  396. // end_ntifs end_ntosp
  397. //
  398. // Define function decoration depending on whether a driver, a file system,
  399. // or a kernel component is being built.
  400. //
  401. #if (defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || defined(_NTOSP_)) && !defined(_BLDR_)
  402. // begin_ntosp
  403. #if defined(_NTSYSTEM_)
  404. #define NTKERNELAPI
  405. #else
  406. #define NTKERNELAPI DECLSPEC_IMPORT // wdm ntddk nthal ntndis ntifs
  407. #endif
  408. // end_ntosp
  409. #else
  410. #define NTKERNELAPI
  411. #endif
  412. //
  413. // Define function decoration depending on whether the HAL or other kernel
  414. // component is being build.
  415. // begin_ntddk
  416. #if !defined(_NTHAL_) && !defined(_BLDR_)
  417. #define NTHALAPI DECLSPEC_IMPORT // wdm ntndis ntifs ntosp
  418. #else
  419. #define NTHALAPI // nthal
  420. #endif
  421. // end_ntddk
  422. // begin_ntddk begin_wdm begin_nthal begin_ntifs begin_ntndis begin_ntosp
  423. //
  424. // Common dispatcher object header
  425. //
  426. // N.B. The size field contains the number of dwords in the structure.
  427. //
  428. typedef struct _DISPATCHER_HEADER {
  429. UCHAR Type;
  430. UCHAR Absolute;
  431. UCHAR Size;
  432. UCHAR Inserted;
  433. LONG SignalState;
  434. LIST_ENTRY WaitListHead;
  435. } DISPATCHER_HEADER;
  436. //
  437. // Event object
  438. //
  439. typedef struct _KEVENT {
  440. DISPATCHER_HEADER Header;
  441. } KEVENT, *PKEVENT, *RESTRICTED_POINTER PRKEVENT;
  442. //
  443. // Timer object
  444. //
  445. typedef struct _KTIMER {
  446. DISPATCHER_HEADER Header;
  447. ULARGE_INTEGER DueTime;
  448. LIST_ENTRY TimerListEntry;
  449. struct _KDPC *Dpc;
  450. LONG Period;
  451. } KTIMER, *PKTIMER, *RESTRICTED_POINTER PRKTIMER;
  452. // end_ntddk end_wdm end_nthal end_ntifs end_ntndis end_ntosp
  453. #endif // _NTOSDEF_