Move more stuff to wdm.h
[reactos.git] / include / ddk / wdm.h
1 #ifndef _WDMDDK_
2 #define _WDMDDK_
3
4 /* Helper macro to enable gcc's extension. */
5 #ifndef __GNU_EXTENSION
6 #ifdef __GNUC__
7 #define __GNU_EXTENSION __extension__
8 #else
9 #define __GNU_EXTENSION
10 #endif
11 #endif
12
13 //
14 // Dependencies
15 //
16 #define NT_INCLUDED
17 #include <excpt.h>
18 #include <ntdef.h>
19 #include <ntstatus.h>
20
21 #ifndef GUID_DEFINED
22 #include <guiddef.h>
23 #endif /* GUID_DEFINED */
24
25 #include "intrin.h"
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 #define NTKERNELAPI DECLSPEC_IMPORT
32
33 #ifdef _WIN64
34 #define PORT_MAXIMUM_MESSAGE_LENGTH 512
35 #else
36 #define PORT_MAXIMUM_MESSAGE_LENGTH 256
37 #endif
38
39
40 #if defined(_MSC_VER)
41
42 //
43 // Indicate if #pragma alloc_text() is supported
44 //
45 #if defined(_M_IX86) || defined(_M_AMD64) || defined(_M_IA64)
46 #define ALLOC_PRAGMA 1
47 #endif
48
49 //
50 // Indicate if #pragma data_seg() is supported
51 //
52 #if defined(_M_IX86) || defined(_M_AMD64)
53 #define ALLOC_DATA_PRAGMA 1
54 #endif
55
56 #endif
57
58
59 /*
60 * Alignment Macros
61 */
62 #define ALIGN_DOWN(s, t) \
63 ((ULONG)(s) & ~(sizeof(t) - 1))
64
65 #define ALIGN_UP(s, t) \
66 (ALIGN_DOWN(((ULONG)(s) + sizeof(t) - 1), t))
67
68 #define ALIGN_DOWN_POINTER(p, t) \
69 ((PVOID)((ULONG_PTR)(p) & ~((ULONG_PTR)sizeof(t) - 1)))
70
71 #define ALIGN_UP_POINTER(p, t) \
72 (ALIGN_DOWN_POINTER(((ULONG_PTR)(p) + sizeof(t) - 1), t))
73
74 /*
75 * GUID Comparison
76 */
77
78 #ifndef __IID_ALIGNED__
79 #define __IID_ALIGNED__
80 #ifdef __cplusplus
81 inline int IsEqualGUIDAligned(REFGUID guid1, REFGUID guid2)
82 {
83 return ((*(PLONGLONG)(&guid1) == *(PLONGLONG)(&guid2)) && (*((PLONGLONG)(&guid1) + 1) == *((PLONGLONG)(&guid2) + 1)));
84 }
85 #else
86 #define IsEqualGUIDAligned(guid1, guid2) \
87 ((*(PLONGLONG)(guid1) == *(PLONGLONG)(guid2)) && (*((PLONGLONG)(guid1) + 1) == *((PLONGLONG)(guid2) + 1)))
88 #endif
89 #endif
90
91 /*
92 ** Forward declarations
93 */
94
95 struct _IRP;
96 struct _MDL;
97 struct _KAPC;
98 struct _KDPC;
99 struct _FILE_OBJECT;
100 struct _DMA_ADAPTER;
101 struct _DEVICE_OBJECT;
102 struct _DRIVER_OBJECT;
103 struct _IO_STATUS_BLOCK;
104 struct _DEVICE_DESCRIPTION;
105 struct _SCATTER_GATHER_LIST;
106 struct _DRIVE_LAYOUT_INFORMATION;
107
108 typedef PVOID PSID;
109
110 /*
111 ** Simple structures
112 */
113
114 typedef UCHAR KIRQL, *PKIRQL;
115
116 typedef enum _MODE {
117 KernelMode,
118 UserMode,
119 MaximumMode
120 } MODE;
121
122 /* Constants */
123 #define NtCurrentProcess() ( (HANDLE)(LONG_PTR) -1 )
124 #define ZwCurrentProcess() NtCurrentProcess()
125 #define NtCurrentThread() ( (HANDLE)(LONG_PTR) -2 )
126 #define ZwCurrentThread() NtCurrentThread()
127
128 #if (_M_IX86)
129 #define KIP0PCRADDRESS 0xffdff000
130 #endif
131
132 #if defined(_WIN64)
133 #define MAXIMUM_PROCESSORS 64
134 #else
135 #define MAXIMUM_PROCESSORS 32
136 #endif
137
138 #define MAXIMUM_WAIT_OBJECTS 64
139
140 #define EX_RUNDOWN_ACTIVE 0x1
141 #define EX_RUNDOWN_COUNT_SHIFT 0x1
142 #define EX_RUNDOWN_COUNT_INC (1 << EX_RUNDOWN_COUNT_SHIFT)
143
144 #define METHOD_BUFFERED 0
145 #define METHOD_IN_DIRECT 1
146 #define METHOD_OUT_DIRECT 2
147 #define METHOD_NEITHER 3
148
149 #define LOW_PRIORITY 0
150 #define LOW_REALTIME_PRIORITY 16
151 #define HIGH_PRIORITY 31
152 #define MAXIMUM_PRIORITY 32
153
154 #define MAXIMUM_SUSPEND_COUNT MAXCHAR
155
156 #define MAXIMUM_FILENAME_LENGTH 256
157
158 #define FILE_SUPERSEDED 0x00000000
159 #define FILE_OPENED 0x00000001
160 #define FILE_CREATED 0x00000002
161 #define FILE_OVERWRITTEN 0x00000003
162 #define FILE_EXISTS 0x00000004
163 #define FILE_DOES_NOT_EXIST 0x00000005
164
165 #define FILE_USE_FILE_POINTER_POSITION 0xfffffffe
166 #define FILE_WRITE_TO_END_OF_FILE 0xffffffff
167
168 /* also in winnt.h */
169 #define FILE_LIST_DIRECTORY 0x00000001
170 #define FILE_READ_DATA 0x00000001
171 #define FILE_ADD_FILE 0x00000002
172 #define FILE_WRITE_DATA 0x00000002
173 #define FILE_ADD_SUBDIRECTORY 0x00000004
174 #define FILE_APPEND_DATA 0x00000004
175 #define FILE_CREATE_PIPE_INSTANCE 0x00000004
176 #define FILE_READ_EA 0x00000008
177 #define FILE_WRITE_EA 0x00000010
178 #define FILE_EXECUTE 0x00000020
179 #define FILE_TRAVERSE 0x00000020
180 #define FILE_DELETE_CHILD 0x00000040
181 #define FILE_READ_ATTRIBUTES 0x00000080
182 #define FILE_WRITE_ATTRIBUTES 0x00000100
183
184 #define FILE_SHARE_READ 0x00000001
185 #define FILE_SHARE_WRITE 0x00000002
186 #define FILE_SHARE_DELETE 0x00000004
187 #define FILE_SHARE_VALID_FLAGS 0x00000007
188
189 #define FILE_ATTRIBUTE_READONLY 0x00000001
190 #define FILE_ATTRIBUTE_HIDDEN 0x00000002
191 #define FILE_ATTRIBUTE_SYSTEM 0x00000004
192 #define FILE_ATTRIBUTE_DIRECTORY 0x00000010
193 #define FILE_ATTRIBUTE_ARCHIVE 0x00000020
194 #define FILE_ATTRIBUTE_DEVICE 0x00000040
195 #define FILE_ATTRIBUTE_NORMAL 0x00000080
196 #define FILE_ATTRIBUTE_TEMPORARY 0x00000100
197 #define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
198 #define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
199 #define FILE_ATTRIBUTE_COMPRESSED 0x00000800
200 #define FILE_ATTRIBUTE_OFFLINE 0x00001000
201 #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
202 #define FILE_ATTRIBUTE_ENCRYPTED 0x00004000
203
204 #define FILE_ATTRIBUTE_VALID_FLAGS 0x00007fb7
205 #define FILE_ATTRIBUTE_VALID_SET_FLAGS 0x000031a7
206
207 #define FILE_VALID_OPTION_FLAGS 0x00ffffff
208 #define FILE_VALID_PIPE_OPTION_FLAGS 0x00000032
209 #define FILE_VALID_MAILSLOT_OPTION_FLAGS 0x00000032
210 #define FILE_VALID_SET_FLAGS 0x00000036
211
212 #define FILE_SUPERSEDE 0x00000000
213 #define FILE_OPEN 0x00000001
214 #define FILE_CREATE 0x00000002
215 #define FILE_OPEN_IF 0x00000003
216 #define FILE_OVERWRITE 0x00000004
217 #define FILE_OVERWRITE_IF 0x00000005
218 #define FILE_MAXIMUM_DISPOSITION 0x00000005
219
220 #define FILE_DIRECTORY_FILE 0x00000001
221 #define FILE_WRITE_THROUGH 0x00000002
222 #define FILE_SEQUENTIAL_ONLY 0x00000004
223 #define FILE_NO_INTERMEDIATE_BUFFERING 0x00000008
224 #define FILE_SYNCHRONOUS_IO_ALERT 0x00000010
225 #define FILE_SYNCHRONOUS_IO_NONALERT 0x00000020
226 #define FILE_NON_DIRECTORY_FILE 0x00000040
227 #define FILE_CREATE_TREE_CONNECTION 0x00000080
228 #define FILE_COMPLETE_IF_OPLOCKED 0x00000100
229 #define FILE_NO_EA_KNOWLEDGE 0x00000200
230
231
232 /* Simple types */
233 typedef UCHAR KPROCESSOR_MODE;
234 typedef LONG KPRIORITY;
235 typedef PVOID PSECURITY_DESCRIPTOR;
236 typedef ULONG SECURITY_INFORMATION, *PSECURITY_INFORMATION;
237
238 /* Structures not exposed to drivers */
239 typedef struct _OBJECT_TYPE *POBJECT_TYPE;
240 typedef struct _HAL_DISPATCH_TABLE *PHAL_DISPATCH_TABLE;
241 typedef struct _HAL_PRIVATE_DISPATCH_TABLE *PHAL_PRIVATE_DISPATCH_TABLE;
242 typedef struct _DEVICE_HANDLER_OBJECT *PDEVICE_HANDLER_OBJECT;
243 typedef struct _BUS_HANDLER *PBUS_HANDLER;
244
245 typedef struct _ADAPTER_OBJECT *PADAPTER_OBJECT;
246 typedef struct _CALLBACK_OBJECT *PCALLBACK_OBJECT;
247 typedef struct _ETHREAD *PETHREAD;
248 typedef struct _EPROCESS *PEPROCESS;
249 typedef struct _IO_TIMER *PIO_TIMER;
250 typedef struct _KINTERRUPT *PKINTERRUPT;
251 typedef struct _KPROCESS *PKPROCESS;
252 typedef struct _KTHREAD *PKTHREAD, *PRKTHREAD;
253
254
255 typedef struct _CONTEXT *PCONTEXT;
256
257 //
258 // Resource list definitions
259 //
260 typedef int CM_RESOURCE_TYPE;
261
262 #define CmResourceTypeNull 0
263 #define CmResourceTypePort 1
264 #define CmResourceTypeInterrupt 2
265 #define CmResourceTypeMemory 3
266 #define CmResourceTypeDma 4
267 #define CmResourceTypeDeviceSpecific 5
268 #define CmResourceTypeBusNumber 6
269 #define CmResourceTypeNonArbitrated 128
270 #define CmResourceTypeConfigData 128
271 #define CmResourceTypeDevicePrivate 129
272 #define CmResourceTypePcCardConfig 130
273 #define CmResourceTypeMfCardConfig 131
274
275 typedef enum _INTERFACE_TYPE {
276 InterfaceTypeUndefined = -1,
277 Internal,
278 Isa,
279 Eisa,
280 MicroChannel,
281 TurboChannel,
282 PCIBus,
283 VMEBus,
284 NuBus,
285 PCMCIABus,
286 CBus,
287 MPIBus,
288 MPSABus,
289 ProcessorInternal,
290 InternalPowerBus,
291 PNPISABus,
292 PNPBus,
293 MaximumInterfaceType
294 } INTERFACE_TYPE, *PINTERFACE_TYPE;
295
296 /* IO_RESOURCE_DESCRIPTOR.Option */
297
298 #define IO_RESOURCE_PREFERRED 0x01
299 #define IO_RESOURCE_DEFAULT 0x02
300 #define IO_RESOURCE_ALTERNATIVE 0x08
301
302 typedef struct _IO_RESOURCE_DESCRIPTOR {
303 UCHAR Option;
304 UCHAR Type;
305 UCHAR ShareDisposition;
306 UCHAR Spare1;
307 USHORT Flags;
308 USHORT Spare2;
309 union {
310 struct {
311 ULONG Length;
312 ULONG Alignment;
313 PHYSICAL_ADDRESS MinimumAddress;
314 PHYSICAL_ADDRESS MaximumAddress;
315 } Port;
316 struct {
317 ULONG Length;
318 ULONG Alignment;
319 PHYSICAL_ADDRESS MinimumAddress;
320 PHYSICAL_ADDRESS MaximumAddress;
321 } Memory;
322 struct {
323 ULONG MinimumVector;
324 ULONG MaximumVector;
325 } Interrupt;
326 struct {
327 ULONG MinimumChannel;
328 ULONG MaximumChannel;
329 } Dma;
330 struct {
331 ULONG Length;
332 ULONG Alignment;
333 PHYSICAL_ADDRESS MinimumAddress;
334 PHYSICAL_ADDRESS MaximumAddress;
335 } Generic;
336 struct {
337 ULONG Data[3];
338 } DevicePrivate;
339 struct {
340 ULONG Length;
341 ULONG MinBusNumber;
342 ULONG MaxBusNumber;
343 ULONG Reserved;
344 } BusNumber;
345 struct {
346 ULONG Priority;
347 ULONG Reserved1;
348 ULONG Reserved2;
349 } ConfigData;
350 } u;
351 } IO_RESOURCE_DESCRIPTOR, *PIO_RESOURCE_DESCRIPTOR;
352
353 typedef struct _IO_RESOURCE_LIST {
354 USHORT Version;
355 USHORT Revision;
356 ULONG Count;
357 IO_RESOURCE_DESCRIPTOR Descriptors[1];
358 } IO_RESOURCE_LIST, *PIO_RESOURCE_LIST;
359
360 typedef struct _IO_RESOURCE_REQUIREMENTS_LIST {
361 ULONG ListSize;
362 INTERFACE_TYPE InterfaceType;
363 ULONG BusNumber;
364 ULONG SlotNumber;
365 ULONG Reserved[3];
366 ULONG AlternativeLists;
367 IO_RESOURCE_LIST List[1];
368 } IO_RESOURCE_REQUIREMENTS_LIST, *PIO_RESOURCE_REQUIREMENTS_LIST;
369
370 //
371 // Global debug flag
372 //
373 extern ULONG NtGlobalFlag;
374
375
376 #include <pshpack4.h>
377 typedef struct _CM_PARTIAL_RESOURCE_DESCRIPTOR {
378 UCHAR Type;
379 UCHAR ShareDisposition;
380 USHORT Flags;
381 union {
382 struct {
383 PHYSICAL_ADDRESS Start;
384 ULONG Length;
385 } Generic;
386 struct {
387 PHYSICAL_ADDRESS Start;
388 ULONG Length;
389 } Port;
390 struct {
391 ULONG Level;
392 ULONG Vector;
393 KAFFINITY Affinity;
394 } Interrupt;
395 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
396 struct {
397 __GNU_EXTENSION union {
398 struct {
399 USHORT Reserved;
400 USHORT MessageCount;
401 ULONG Vector;
402 KAFFINITY Affinity;
403 } Raw;
404 struct {
405 ULONG Level;
406 ULONG Vector;
407 KAFFINITY Affinity;
408 } Translated;
409 };
410 } MessageInterrupt;
411 #endif
412 struct {
413 PHYSICAL_ADDRESS Start;
414 ULONG Length;
415 } Memory;
416 struct {
417 ULONG Channel;
418 ULONG Port;
419 ULONG Reserved1;
420 } Dma;
421 struct {
422 ULONG Data[3];
423 } DevicePrivate;
424 struct {
425 ULONG Start;
426 ULONG Length;
427 ULONG Reserved;
428 } BusNumber;
429 struct {
430 ULONG DataSize;
431 ULONG Reserved1;
432 ULONG Reserved2;
433 } DeviceSpecificData;
434 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
435 struct {
436 PHYSICAL_ADDRESS Start;
437 ULONG Length40;
438 } Memory40;
439 struct {
440 PHYSICAL_ADDRESS Start;
441 ULONG Length48;
442 } Memory48;
443 struct {
444 PHYSICAL_ADDRESS Start;
445 ULONG Length64;
446 } Memory64;
447 #endif
448 } u;
449 } CM_PARTIAL_RESOURCE_DESCRIPTOR, *PCM_PARTIAL_RESOURCE_DESCRIPTOR;
450 #include <poppack.h>
451
452 //
453 // Section map options
454 //
455 typedef enum _SECTION_INHERIT {
456 ViewShare = 1,
457 ViewUnmap = 2
458 } SECTION_INHERIT;
459
460 //
461 // Section access rights
462 //
463 #define SECTION_QUERY 0x0001
464 #define SECTION_MAP_WRITE 0x0002
465 #define SECTION_MAP_READ 0x0004
466 #define SECTION_MAP_EXECUTE 0x0008
467 #define SECTION_EXTEND_SIZE 0x0010
468 #define SECTION_MAP_EXECUTE_EXPLICIT 0x0020
469
470 #define SECTION_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SECTION_QUERY|\
471 SECTION_MAP_WRITE | \
472 SECTION_MAP_READ | \
473 SECTION_MAP_EXECUTE | \
474 SECTION_EXTEND_SIZE)
475
476 #define SESSION_QUERY_ACCESS 0x0001
477 #define SESSION_MODIFY_ACCESS 0x0002
478
479 #define SESSION_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | \
480 SESSION_QUERY_ACCESS | \
481 SESSION_MODIFY_ACCESS)
482
483
484
485 #define SEGMENT_ALL_ACCESS SECTION_ALL_ACCESS
486
487 #define PAGE_NOACCESS 0x01
488 #define PAGE_READONLY 0x02
489 #define PAGE_READWRITE 0x04
490 #define PAGE_WRITECOPY 0x08
491 #define PAGE_EXECUTE 0x10
492 #define PAGE_EXECUTE_READ 0x20
493 #define PAGE_EXECUTE_READWRITE 0x40
494 #define PAGE_EXECUTE_WRITECOPY 0x80
495 #define PAGE_GUARD 0x100
496 #define PAGE_NOCACHE 0x200
497 #define PAGE_WRITECOMBINE 0x400
498
499 #define MEM_COMMIT 0x1000
500 #define MEM_RESERVE 0x2000
501 #define MEM_DECOMMIT 0x4000
502 #define MEM_RELEASE 0x8000
503 #define MEM_FREE 0x10000
504 #define MEM_PRIVATE 0x20000
505 #define MEM_MAPPED 0x40000
506 #define MEM_RESET 0x80000
507 #define MEM_TOP_DOWN 0x100000
508 #define MEM_LARGE_PAGES 0x20000000
509 #define MEM_4MB_PAGES 0x80000000
510
511 #define SEC_RESERVE 0x4000000
512 #define SEC_LARGE_PAGES 0x80000000
513
514 #define PROCESS_DUP_HANDLE (0x0040)
515
516 #if (NTDDI_VERSION >= NTDDI_VISTA)
517 #define PROCESS_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
518 0xFFFF)
519 #else
520 #define PROCESS_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
521 0xFFF)
522 #endif
523
524
525
526 //
527 // Processor features
528 //
529 #define PF_FLOATING_POINT_PRECISION_ERRATA 0
530 #define PF_FLOATING_POINT_EMULATED 1
531 #define PF_COMPARE_EXCHANGE_DOUBLE 2
532 #define PF_MMX_INSTRUCTIONS_AVAILABLE 3
533 #define PF_PPC_MOVEMEM_64BIT_OK 4
534 #define PF_ALPHA_BYTE_INSTRUCTIONS 5
535 #define PF_XMMI_INSTRUCTIONS_AVAILABLE 6
536 #define PF_3DNOW_INSTRUCTIONS_AVAILABLE 7
537 #define PF_RDTSC_INSTRUCTION_AVAILABLE 8
538 #define PF_PAE_ENABLED 9
539 #define PF_XMMI64_INSTRUCTIONS_AVAILABLE 10
540 #define PF_SSE_DAZ_MODE_AVAILABLE 11
541 #define PF_NX_ENABLED 12
542 #define PF_SSE3_INSTRUCTIONS_AVAILABLE 13
543 #define PF_COMPARE_EXCHANGE128 14
544 #define PF_COMPARE64_EXCHANGE128 15
545 #define PF_CHANNELS_ENABLED 16
546
547
548
549 //
550 // Intrinsics (note: taken from our winnt.h)
551 // FIXME: 64-bit
552 //
553 #if defined(__GNUC__)
554
555 static __inline__ BOOLEAN
556 InterlockedBitTestAndSet(IN LONG volatile *Base,
557 IN LONG Bit)
558 {
559 #if defined(_M_IX86)
560 LONG OldBit;
561 __asm__ __volatile__("lock "
562 "btsl %2,%1\n\t"
563 "sbbl %0,%0\n\t"
564 :"=r" (OldBit),"+m" (*Base)
565 :"Ir" (Bit)
566 : "memory");
567 return OldBit;
568 #else
569 return (_InterlockedOr(Base, 1 << Bit) >> Bit) & 1;
570 #endif
571 }
572
573 static __inline__ BOOLEAN
574 InterlockedBitTestAndReset(IN LONG volatile *Base,
575 IN LONG Bit)
576 {
577 #if defined(_M_IX86)
578 LONG OldBit;
579 __asm__ __volatile__("lock "
580 "btrl %2,%1\n\t"
581 "sbbl %0,%0\n\t"
582 :"=r" (OldBit),"+m" (*Base)
583 :"Ir" (Bit)
584 : "memory");
585 return OldBit;
586 #else
587 return (_InterlockedAnd(Base, ~(1 << Bit)) >> Bit) & 1;
588 #endif
589 }
590
591 #endif
592
593 #define BitScanForward _BitScanForward
594 #define BitScanReverse _BitScanReverse
595
596 #define BitTest _bittest
597 #define BitTestAndComplement _bittestandcomplement
598 #define BitTestAndSet _bittestandset
599 #define BitTestAndReset _bittestandreset
600 #define InterlockedBitTestAndSet _interlockedbittestandset
601 #define InterlockedBitTestAndReset _interlockedbittestandreset
602
603
604 /** INTERLOCKED FUNCTIONS *****************************************************/
605
606 #if !defined(__INTERLOCKED_DECLARED)
607 #define __INTERLOCKED_DECLARED
608
609 #if defined (_X86_)
610 #if defined(NO_INTERLOCKED_INTRINSICS)
611 NTKERNELAPI
612 LONG
613 FASTCALL
614 InterlockedIncrement(
615 IN OUT LONG volatile *Addend);
616
617 NTKERNELAPI
618 LONG
619 FASTCALL
620 InterlockedDecrement(
621 IN OUT LONG volatile *Addend);
622
623 NTKERNELAPI
624 LONG
625 FASTCALL
626 InterlockedCompareExchange(
627 IN OUT LONG volatile *Destination,
628 IN LONG Exchange,
629 IN LONG Comparand);
630
631 NTKERNELAPI
632 LONG
633 FASTCALL
634 InterlockedExchange(
635 IN OUT LONG volatile *Destination,
636 IN LONG Value);
637
638 NTKERNELAPI
639 LONG
640 FASTCALL
641 InterlockedExchangeAdd(
642 IN OUT LONG volatile *Addend,
643 IN LONG Value);
644
645 #else // !defined(NO_INTERLOCKED_INTRINSICS)
646
647 #define InterlockedExchange _InterlockedExchange
648 #define InterlockedIncrement _InterlockedIncrement
649 #define InterlockedDecrement _InterlockedDecrement
650 #define InterlockedExchangeAdd _InterlockedExchangeAdd
651 #define InterlockedCompareExchange _InterlockedCompareExchange
652 #define InterlockedOr _InterlockedOr
653 #define InterlockedAnd _InterlockedAnd
654 #define InterlockedXor _InterlockedXor
655
656 #endif // !defined(NO_INTERLOCKED_INTRINSICS)
657
658 #endif // defined (_X86_)
659
660 #if !defined (_WIN64)
661 /*
662 * PVOID
663 * InterlockedExchangePointer(
664 * IN OUT PVOID volatile *Target,
665 * IN PVOID Value)
666 */
667 #define InterlockedExchangePointer(Target, Value) \
668 ((PVOID) InterlockedExchange((PLONG) Target, (LONG) Value))
669
670 /*
671 * PVOID
672 * InterlockedCompareExchangePointer(
673 * IN OUT PVOID *Destination,
674 * IN PVOID Exchange,
675 * IN PVOID Comparand)
676 */
677 #define InterlockedCompareExchangePointer(Destination, Exchange, Comparand) \
678 ((PVOID) InterlockedCompareExchange((PLONG) Destination, (LONG) Exchange, (LONG) Comparand))
679
680 #define InterlockedExchangeAddSizeT(a, b) InterlockedExchangeAdd((LONG *)a, b)
681 #define InterlockedIncrementSizeT(a) InterlockedIncrement((LONG *)a)
682 #define InterlockedDecrementSizeT(a) InterlockedDecrement((LONG *)a)
683
684 #endif // !defined (_WIN64)
685
686 #if defined (_M_AMD64)
687
688 #define InterlockedExchangeAddSizeT(a, b) InterlockedExchangeAdd64((LONGLONG *)a, (LONGLONG)b)
689 #define InterlockedIncrementSizeT(a) InterlockedIncrement64((LONGLONG *)a)
690 #define InterlockedDecrementSizeT(a) InterlockedDecrement64((LONGLONG *)a)
691 #define InterlockedAnd _InterlockedAnd
692 #define InterlockedOr _InterlockedOr
693 #define InterlockedXor _InterlockedXor
694 #define InterlockedIncrement _InterlockedIncrement
695 #define InterlockedDecrement _InterlockedDecrement
696 #define InterlockedAdd _InterlockedAdd
697 #define InterlockedExchange _InterlockedExchange
698 #define InterlockedExchangeAdd _InterlockedExchangeAdd
699 #define InterlockedCompareExchange _InterlockedCompareExchange
700 #define InterlockedAnd64 _InterlockedAnd64
701 #define InterlockedOr64 _InterlockedOr64
702 #define InterlockedXor64 _InterlockedXor64
703 #define InterlockedIncrement64 _InterlockedIncrement64
704 #define InterlockedDecrement64 _InterlockedDecrement64
705 #define InterlockedAdd64 _InterlockedAdd64
706 #define InterlockedExchange64 _InterlockedExchange64
707 #define InterlockedExchangeAdd64 _InterlockedExchangeAdd64
708 #define InterlockedCompareExchange64 _InterlockedCompareExchange64
709 #define InterlockedCompareExchangePointer _InterlockedCompareExchangePointer
710 #define InterlockedExchangePointer _InterlockedExchangePointer
711 #define InterlockedBitTestAndSet64 _interlockedbittestandset64
712 #define InterlockedBitTestAndReset64 _interlockedbittestandreset64
713
714 #endif // _M_AMD64
715
716 #if defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
717 //#if !defined(_X86AMD64_) // FIXME: what's _X86AMD64_ used for?
718 FORCEINLINE
719 LONG64
720 InterlockedAdd64(
721 IN OUT LONG64 volatile *Addend,
722 IN LONG64 Value)
723 {
724 return InterlockedExchangeAdd64(Addend, Value) + Value;
725 }
726 //#endif
727 #endif
728
729 #endif /* !__INTERLOCKED_DECLARED */
730
731 #if defined(_M_IX86)
732 #define YieldProcessor _mm_pause
733 #elif defined (_M_AMD64)
734 #define YieldProcessor _mm_pause
735 #elif defined(_M_PPC)
736 #define YieldProcessor() __asm__ __volatile__("nop");
737 #elif defined(_M_MIPS)
738 #define YieldProcessor() __asm__ __volatile__("nop");
739 #elif defined(_M_ARM)
740 #define YieldProcessor()
741 #else
742 #error Unknown architecture
743 #endif
744
745
746
747 //
748 // Slist Header
749 //
750 #ifndef _SLIST_HEADER_
751 #define _SLIST_HEADER_
752
753 #if defined(_WIN64)
754 typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY *PSLIST_ENTRY;
755 typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY {
756 PSLIST_ENTRY Next;
757 } SLIST_ENTRY;
758 typedef union DECLSPEC_ALIGN(16) _SLIST_HEADER {
759 struct {
760 ULONGLONG Alignment;
761 ULONGLONG Region;
762 } DUMMYSTRUCTNAME;
763 struct {
764 ULONGLONG Depth:16;
765 ULONGLONG Sequence:9;
766 ULONGLONG NextEntry:39;
767 ULONGLONG HeaderType:1;
768 ULONGLONG Init:1;
769 ULONGLONG Reserved:59;
770 ULONGLONG Region:3;
771 } Header8;
772 struct {
773 ULONGLONG Depth:16;
774 ULONGLONG Sequence:48;
775 ULONGLONG HeaderType:1;
776 ULONGLONG Init:1;
777 ULONGLONG Reserved:2;
778 ULONGLONG NextEntry:60;
779 } Header16;
780 } SLIST_HEADER, *PSLIST_HEADER;
781 #else
782 #define SLIST_ENTRY SINGLE_LIST_ENTRY
783 #define _SLIST_ENTRY _SINGLE_LIST_ENTRY
784 #define PSLIST_ENTRY PSINGLE_LIST_ENTRY
785 typedef union _SLIST_HEADER {
786 ULONGLONG Alignment;
787 struct {
788 SLIST_ENTRY Next;
789 USHORT Depth;
790 USHORT Sequence;
791 } DUMMYSTRUCTNAME;
792 } SLIST_HEADER, *PSLIST_HEADER;
793 #endif
794
795 #endif /* _SLIST_HEADER_ */
796
797
798
799 //
800 // Power States/Levels
801 //
802 typedef enum _SYSTEM_POWER_STATE {
803 PowerSystemUnspecified,
804 PowerSystemWorking,
805 PowerSystemSleeping1,
806 PowerSystemSleeping2,
807 PowerSystemSleeping3,
808 PowerSystemHibernate,
809 PowerSystemShutdown,
810 PowerSystemMaximum
811 } SYSTEM_POWER_STATE, *PSYSTEM_POWER_STATE;
812
813 #define POWER_SYSTEM_MAXIMUM PowerSystemMaximum
814
815 typedef enum _POWER_INFORMATION_LEVEL {
816 SystemPowerPolicyAc,
817 SystemPowerPolicyDc,
818 VerifySystemPolicyAc,
819 VerifySystemPolicyDc,
820 SystemPowerCapabilities,
821 SystemBatteryState,
822 SystemPowerStateHandler,
823 ProcessorStateHandler,
824 SystemPowerPolicyCurrent,
825 AdministratorPowerPolicy,
826 SystemReserveHiberFile,
827 ProcessorInformation,
828 SystemPowerInformation,
829 ProcessorStateHandler2,
830 LastWakeTime,
831 LastSleepTime,
832 SystemExecutionState,
833 SystemPowerStateNotifyHandler,
834 ProcessorPowerPolicyAc,
835 ProcessorPowerPolicyDc,
836 VerifyProcessorPowerPolicyAc,
837 VerifyProcessorPowerPolicyDc,
838 ProcessorPowerPolicyCurrent
839 } POWER_INFORMATION_LEVEL;
840
841 typedef enum {
842 PowerActionNone,
843 PowerActionReserved,
844 PowerActionSleep,
845 PowerActionHibernate,
846 PowerActionShutdown,
847 PowerActionShutdownReset,
848 PowerActionShutdownOff,
849 PowerActionWarmEject
850 } POWER_ACTION, *PPOWER_ACTION;
851
852 typedef enum _DEVICE_POWER_STATE {
853 PowerDeviceUnspecified,
854 PowerDeviceD0,
855 PowerDeviceD1,
856 PowerDeviceD2,
857 PowerDeviceD3,
858 PowerDeviceMaximum
859 } DEVICE_POWER_STATE, *PDEVICE_POWER_STATE;
860
861 #define ES_SYSTEM_REQUIRED 0x00000001
862 #define ES_DISPLAY_REQUIRED 0x00000002
863 #define ES_USER_PRESENT 0x00000004
864 #define ES_CONTINUOUS 0x80000000
865
866 typedef ULONG EXECUTION_STATE;
867
868 typedef enum {
869 LT_DONT_CARE,
870 LT_LOWEST_LATENCY
871 } LATENCY_TIME;
872
873
874
875 //
876 // Access/Security Stuff
877 //
878 typedef ULONG ACCESS_MASK, *PACCESS_MASK;
879 typedef PVOID PACCESS_TOKEN;
880
881 #define DELETE 0x00010000L
882 #define READ_CONTROL 0x00020000L
883 #define WRITE_DAC 0x00040000L
884 #define WRITE_OWNER 0x00080000L
885 #define SYNCHRONIZE 0x00100000L
886 #define STANDARD_RIGHTS_REQUIRED 0x000F0000L
887 #define STANDARD_RIGHTS_READ READ_CONTROL
888 #define STANDARD_RIGHTS_WRITE READ_CONTROL
889 #define STANDARD_RIGHTS_EXECUTE READ_CONTROL
890 #define STANDARD_RIGHTS_ALL 0x001F0000L
891 #define SPECIFIC_RIGHTS_ALL 0x0000FFFFL
892 #define ACCESS_SYSTEM_SECURITY 0x01000000L
893 #define MAXIMUM_ALLOWED 0x02000000L
894 #define GENERIC_READ 0x80000000L
895 #define GENERIC_WRITE 0x40000000L
896 #define GENERIC_EXECUTE 0x20000000L
897 #define GENERIC_ALL 0x10000000L
898
899 typedef struct _GENERIC_MAPPING {
900 ACCESS_MASK GenericRead;
901 ACCESS_MASK GenericWrite;
902 ACCESS_MASK GenericExecute;
903 ACCESS_MASK GenericAll;
904 } GENERIC_MAPPING, *PGENERIC_MAPPING;
905
906 #define ACL_REVISION 2
907 #define ACL_REVISION_DS 4
908
909 #define ACL_REVISION1 1
910 #define ACL_REVISION2 2
911 #define ACL_REVISION3 3
912 #define ACL_REVISION4 4
913 #define MIN_ACL_REVISION ACL_REVISION2
914 #define MAX_ACL_REVISION ACL_REVISION4
915
916 typedef struct _ACL {
917 UCHAR AclRevision;
918 UCHAR Sbz1;
919 USHORT AclSize;
920 USHORT AceCount;
921 USHORT Sbz2;
922 } ACL, *PACL;
923
924
925
926 //
927 // Current security descriptor revision value
928 //
929 #define SECURITY_DESCRIPTOR_REVISION (1)
930 #define SECURITY_DESCRIPTOR_REVISION1 (1)
931
932 //
933 // Privilege attributes
934 //
935 #define SE_PRIVILEGE_ENABLED_BY_DEFAULT (0x00000001L)
936 #define SE_PRIVILEGE_ENABLED (0x00000002L)
937 #define SE_PRIVILEGE_REMOVED (0X00000004L)
938 #define SE_PRIVILEGE_USED_FOR_ACCESS (0x80000000L)
939
940 #define SE_PRIVILEGE_VALID_ATTRIBUTES (SE_PRIVILEGE_ENABLED_BY_DEFAULT | \
941 SE_PRIVILEGE_ENABLED | \
942 SE_PRIVILEGE_REMOVED | \
943 SE_PRIVILEGE_USED_FOR_ACCESS)
944
945 #include <pshpack4.h>
946 typedef struct _LUID_AND_ATTRIBUTES {
947 LUID Luid;
948 ULONG Attributes;
949 } LUID_AND_ATTRIBUTES, *PLUID_AND_ATTRIBUTES;
950 #include <poppack.h>
951 typedef LUID_AND_ATTRIBUTES LUID_AND_ATTRIBUTES_ARRAY[ANYSIZE_ARRAY];
952 typedef LUID_AND_ATTRIBUTES_ARRAY *PLUID_AND_ATTRIBUTES_ARRAY;
953
954
955
956 //
957 // Privilege sets
958 //
959 #define PRIVILEGE_SET_ALL_NECESSARY (1)
960
961 typedef struct _PRIVILEGE_SET {
962 ULONG PrivilegeCount;
963 ULONG Control;
964 LUID_AND_ATTRIBUTES Privilege[ANYSIZE_ARRAY];
965 } PRIVILEGE_SET,*PPRIVILEGE_SET;
966
967 typedef enum _SECURITY_IMPERSONATION_LEVEL {
968 SecurityAnonymous,
969 SecurityIdentification,
970 SecurityImpersonation,
971 SecurityDelegation
972 } SECURITY_IMPERSONATION_LEVEL, * PSECURITY_IMPERSONATION_LEVEL;
973
974 #define SECURITY_MAX_IMPERSONATION_LEVEL SecurityDelegation
975 #define SECURITY_MIN_IMPERSONATION_LEVEL SecurityAnonymous
976 #define DEFAULT_IMPERSONATION_LEVEL SecurityImpersonation
977 #define VALID_IMPERSONATION_LEVEL(Level) (((Level) >= SECURITY_MIN_IMPERSONATION_LEVEL) && ((Level) <= SECURITY_MAX_IMPERSONATION_LEVEL))
978
979 #define SECURITY_DYNAMIC_TRACKING (TRUE)
980 #define SECURITY_STATIC_TRACKING (FALSE)
981
982 typedef BOOLEAN SECURITY_CONTEXT_TRACKING_MODE, *PSECURITY_CONTEXT_TRACKING_MODE;
983
984 typedef struct _SECURITY_QUALITY_OF_SERVICE {
985 ULONG Length;
986 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
987 SECURITY_CONTEXT_TRACKING_MODE ContextTrackingMode;
988 BOOLEAN EffectiveOnly;
989 } SECURITY_QUALITY_OF_SERVICE, *PSECURITY_QUALITY_OF_SERVICE;
990
991 typedef struct _SE_IMPERSONATION_STATE {
992 PACCESS_TOKEN Token;
993 BOOLEAN CopyOnOpen;
994 BOOLEAN EffectiveOnly;
995 SECURITY_IMPERSONATION_LEVEL Level;
996 } SE_IMPERSONATION_STATE, *PSE_IMPERSONATION_STATE;
997
998 #define OWNER_SECURITY_INFORMATION (0x00000001L)
999 #define GROUP_SECURITY_INFORMATION (0x00000002L)
1000 #define DACL_SECURITY_INFORMATION (0x00000004L)
1001 #define SACL_SECURITY_INFORMATION (0x00000008L)
1002 #define LABEL_SECURITY_INFORMATION (0x00000010L)
1003
1004 #define PROTECTED_DACL_SECURITY_INFORMATION (0x80000000L)
1005 #define PROTECTED_SACL_SECURITY_INFORMATION (0x40000000L)
1006 #define UNPROTECTED_DACL_SECURITY_INFORMATION (0x20000000L)
1007 #define UNPROTECTED_SACL_SECURITY_INFORMATION (0x10000000L)
1008
1009
1010
1011 //
1012 // Registry Access Rights
1013 //
1014 #define KEY_QUERY_VALUE (0x0001)
1015 #define KEY_SET_VALUE (0x0002)
1016 #define KEY_CREATE_SUB_KEY (0x0004)
1017 #define KEY_ENUMERATE_SUB_KEYS (0x0008)
1018 #define KEY_NOTIFY (0x0010)
1019 #define KEY_CREATE_LINK (0x0020)
1020 #define KEY_WOW64_32KEY (0x0200)
1021 #define KEY_WOW64_64KEY (0x0100)
1022 #define KEY_WOW64_RES (0x0300)
1023
1024 #define KEY_READ ((STANDARD_RIGHTS_READ |\
1025 KEY_QUERY_VALUE |\
1026 KEY_ENUMERATE_SUB_KEYS |\
1027 KEY_NOTIFY) \
1028 & \
1029 (~SYNCHRONIZE))
1030
1031 #define KEY_WRITE ((STANDARD_RIGHTS_WRITE |\
1032 KEY_SET_VALUE |\
1033 KEY_CREATE_SUB_KEY) \
1034 & \
1035 (~SYNCHRONIZE))
1036
1037 #define KEY_EXECUTE ((KEY_READ) \
1038 & \
1039 (~SYNCHRONIZE))
1040
1041 #define KEY_ALL_ACCESS ((STANDARD_RIGHTS_ALL |\
1042 KEY_QUERY_VALUE |\
1043 KEY_SET_VALUE |\
1044 KEY_CREATE_SUB_KEY |\
1045 KEY_ENUMERATE_SUB_KEYS |\
1046 KEY_NOTIFY |\
1047 KEY_CREATE_LINK) \
1048 & \
1049 (~SYNCHRONIZE))
1050
1051 //
1052 // Registry Open/Create Options
1053 //
1054 #define REG_OPTION_RESERVED (0x00000000L)
1055 #define REG_OPTION_NON_VOLATILE (0x00000000L)
1056 #define REG_OPTION_VOLATILE (0x00000001L)
1057 #define REG_OPTION_CREATE_LINK (0x00000002L)
1058 #define REG_OPTION_BACKUP_RESTORE (0x00000004L)
1059 #define REG_OPTION_OPEN_LINK (0x00000008L)
1060
1061 #define REG_LEGAL_OPTION \
1062 (REG_OPTION_RESERVED |\
1063 REG_OPTION_NON_VOLATILE |\
1064 REG_OPTION_VOLATILE |\
1065 REG_OPTION_CREATE_LINK |\
1066 REG_OPTION_BACKUP_RESTORE |\
1067 REG_OPTION_OPEN_LINK)
1068
1069 //
1070 // Key creation/open disposition
1071 //
1072 #define REG_CREATED_NEW_KEY (0x00000001L)
1073 #define REG_OPENED_EXISTING_KEY (0x00000002L)
1074
1075 //
1076 // Key restore & hive load flags
1077 //
1078 #define REG_WHOLE_HIVE_VOLATILE (0x00000001L)
1079 #define REG_REFRESH_HIVE (0x00000002L)
1080 #define REG_NO_LAZY_FLUSH (0x00000004L)
1081 #define REG_FORCE_RESTORE (0x00000008L)
1082 #define REG_APP_HIVE (0x00000010L)
1083 #define REG_PROCESS_PRIVATE (0x00000020L)
1084 #define REG_START_JOURNAL (0x00000040L)
1085 #define REG_HIVE_EXACT_FILE_GROWTH (0x00000080L)
1086 #define REG_HIVE_NO_RM (0x00000100L)
1087 #define REG_HIVE_SINGLE_LOG (0x00000200L)
1088
1089 //
1090 // Unload Flags
1091 //
1092 #define REG_FORCE_UNLOAD 1
1093
1094 //
1095 // Notify Filter Values
1096 //
1097 #define REG_NOTIFY_CHANGE_NAME (0x00000001L)
1098 #define REG_NOTIFY_CHANGE_ATTRIBUTES (0x00000002L)
1099 #define REG_NOTIFY_CHANGE_LAST_SET (0x00000004L)
1100 #define REG_NOTIFY_CHANGE_SECURITY (0x00000008L)
1101
1102 #define REG_LEGAL_CHANGE_FILTER \
1103 (REG_NOTIFY_CHANGE_NAME |\
1104 REG_NOTIFY_CHANGE_ATTRIBUTES |\
1105 REG_NOTIFY_CHANGE_LAST_SET |\
1106 REG_NOTIFY_CHANGE_SECURITY)
1107
1108
1109
1110 //
1111 // Thread Access Rights
1112 //
1113 #define THREAD_TERMINATE (0x0001)
1114 #define THREAD_SUSPEND_RESUME (0x0002)
1115 #define THREAD_ALERT (0x0004)
1116 #define THREAD_GET_CONTEXT (0x0008)
1117 #define THREAD_SET_CONTEXT (0x0010)
1118 #define THREAD_SET_INFORMATION (0x0020)
1119 #define THREAD_SET_LIMITED_INFORMATION (0x0400)
1120 #define THREAD_QUERY_LIMITED_INFORMATION (0x0800)
1121 #if (NTDDI_VERSION >= NTDDI_VISTA)
1122 #define THREAD_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
1123 0xFFFF)
1124 #else
1125 #define THREAD_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
1126 0x3FF)
1127 #endif
1128
1129 //
1130 // Service Start Types
1131 //
1132 #define SERVICE_BOOT_START 0x00000000
1133 #define SERVICE_SYSTEM_START 0x00000001
1134 #define SERVICE_AUTO_START 0x00000002
1135 #define SERVICE_DEMAND_START 0x00000003
1136 #define SERVICE_DISABLED 0x00000004
1137
1138 //
1139 // Exception Records
1140 //
1141 #define EXCEPTION_NONCONTINUABLE 1
1142 #define EXCEPTION_MAXIMUM_PARAMETERS 15
1143
1144 typedef struct _EXCEPTION_RECORD {
1145 NTSTATUS ExceptionCode;
1146 ULONG ExceptionFlags;
1147 struct _EXCEPTION_RECORD *ExceptionRecord;
1148 PVOID ExceptionAddress;
1149 ULONG NumberParameters;
1150 ULONG_PTR ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
1151 } EXCEPTION_RECORD, *PEXCEPTION_RECORD;
1152
1153 typedef struct _EXCEPTION_RECORD32 {
1154 NTSTATUS ExceptionCode;
1155 ULONG ExceptionFlags;
1156 ULONG ExceptionRecord;
1157 ULONG ExceptionAddress;
1158 ULONG NumberParameters;
1159 ULONG ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
1160 } EXCEPTION_RECORD32, *PEXCEPTION_RECORD32;
1161
1162 typedef struct _EXCEPTION_RECORD64 {
1163 NTSTATUS ExceptionCode;
1164 ULONG ExceptionFlags;
1165 ULONG64 ExceptionRecord;
1166 ULONG64 ExceptionAddress;
1167 ULONG NumberParameters;
1168 ULONG __unusedAlignment;
1169 ULONG64 ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
1170 } EXCEPTION_RECORD64, *PEXCEPTION_RECORD64;
1171
1172 typedef struct _EXCEPTION_POINTERS {
1173 PEXCEPTION_RECORD ExceptionRecord;
1174 PCONTEXT ContextRecord;
1175 } EXCEPTION_POINTERS, *PEXCEPTION_POINTERS;
1176
1177
1178
1179 //
1180 // Process Qoutas
1181 //
1182 typedef struct _QUOTA_LIMITS {
1183 SIZE_T PagedPoolLimit;
1184 SIZE_T NonPagedPoolLimit;
1185 SIZE_T MinimumWorkingSetSize;
1186 SIZE_T MaximumWorkingSetSize;
1187 SIZE_T PagefileLimit;
1188 LARGE_INTEGER TimeLimit;
1189 } QUOTA_LIMITS, *PQUOTA_LIMITS;
1190
1191 #define QUOTA_LIMITS_HARDWS_MIN_ENABLE 0x00000001
1192 #define QUOTA_LIMITS_HARDWS_MIN_DISABLE 0x00000002
1193 #define QUOTA_LIMITS_HARDWS_MAX_ENABLE 0x00000004
1194 #define QUOTA_LIMITS_HARDWS_MAX_DISABLE 0x00000008
1195 #define QUOTA_LIMITS_USE_DEFAULT_LIMITS 0x00000010
1196
1197
1198 /******************************************************************************
1199 * WINBASE Functions *
1200 ******************************************************************************/
1201 #if !defined(_WINBASE_)
1202
1203 #if defined(_WIN64)
1204
1205 #define InterlockedPopEntrySList(Head) \
1206 ExpInterlockedPopEntrySList(Head)
1207
1208 #define InterlockedPushEntrySList(Head, Entry) \
1209 ExpInterlockedPushEntrySList(Head, Entry)
1210
1211 #define InterlockedFlushSList(Head) \
1212 ExpInterlockedFlushSList(Head)
1213
1214 #define QueryDepthSList(Head) \
1215 ExQueryDepthSList(Head)
1216
1217 #else // !defined(_WIN64)
1218
1219 NTKERNELAPI
1220 PSLIST_ENTRY
1221 FASTCALL
1222 InterlockedPopEntrySList(
1223 IN PSLIST_HEADER ListHead);
1224
1225 NTKERNELAPI
1226 PSLIST_ENTRY
1227 FASTCALL
1228 InterlockedPushEntrySList(
1229 IN PSLIST_HEADER ListHead,
1230 IN PSLIST_ENTRY ListEntry);
1231
1232 #define InterlockedFlushSList(ListHead) \
1233 ExInterlockedFlushSList(ListHead)
1234
1235 #define QueryDepthSList(Head) \
1236 ExQueryDepthSList(Head)
1237
1238 #endif // !defined(_WIN64)
1239
1240 #endif // !defined(_WINBASE_)
1241
1242
1243 /******************************************************************************
1244 * Kernel Types *
1245 ******************************************************************************/
1246
1247 typedef struct _DISPATCHER_HEADER
1248 {
1249 __GNU_EXTENSION union
1250 {
1251 __GNU_EXTENSION struct
1252 {
1253 UCHAR Type;
1254 __GNU_EXTENSION union
1255 {
1256 UCHAR Absolute;
1257 UCHAR NpxIrql;
1258 };
1259 __GNU_EXTENSION union
1260 {
1261 UCHAR Size;
1262 UCHAR Hand;
1263 };
1264 __GNU_EXTENSION union
1265 {
1266 UCHAR Inserted;
1267 BOOLEAN DebugActive;
1268 };
1269 };
1270 volatile LONG Lock;
1271 };
1272 LONG SignalState;
1273 LIST_ENTRY WaitListHead;
1274 } DISPATCHER_HEADER, *PDISPATCHER_HEADER;
1275
1276 typedef ULONG_PTR KSPIN_LOCK, *PKSPIN_LOCK;
1277
1278 typedef struct _KEVENT {
1279 DISPATCHER_HEADER Header;
1280 } KEVENT, *PKEVENT, *RESTRICTED_POINTER PRKEVENT;
1281
1282 typedef struct _KSEMAPHORE {
1283 DISPATCHER_HEADER Header;
1284 LONG Limit;
1285 } KSEMAPHORE, *PKSEMAPHORE, *RESTRICTED_POINTER PRKSEMAPHORE;
1286
1287 /******************************************************************************
1288 * RTL Types *
1289 ******************************************************************************/
1290
1291 #define RTL_REGISTRY_ABSOLUTE 0
1292 #define RTL_REGISTRY_SERVICES 1
1293 #define RTL_REGISTRY_CONTROL 2
1294 #define RTL_REGISTRY_WINDOWS_NT 3
1295 #define RTL_REGISTRY_DEVICEMAP 4
1296 #define RTL_REGISTRY_USER 5
1297 #define RTL_REGISTRY_MAXIMUM 6
1298 #define RTL_REGISTRY_HANDLE 0x40000000
1299 #define RTL_REGISTRY_OPTIONAL 0x80000000
1300
1301 /* RTL_QUERY_REGISTRY_TABLE.Flags */
1302 #define RTL_QUERY_REGISTRY_SUBKEY 0x00000001
1303 #define RTL_QUERY_REGISTRY_TOPKEY 0x00000002
1304 #define RTL_QUERY_REGISTRY_REQUIRED 0x00000004
1305 #define RTL_QUERY_REGISTRY_NOVALUE 0x00000008
1306 #define RTL_QUERY_REGISTRY_NOEXPAND 0x00000010
1307 #define RTL_QUERY_REGISTRY_DIRECT 0x00000020
1308 #define RTL_QUERY_REGISTRY_DELETE 0x00000040
1309
1310 typedef struct _RTL_BITMAP {
1311 ULONG SizeOfBitMap;
1312 PULONG Buffer;
1313 } RTL_BITMAP, *PRTL_BITMAP;
1314
1315 typedef struct _RTL_BITMAP_RUN {
1316 ULONG StartingIndex;
1317 ULONG NumberOfBits;
1318 } RTL_BITMAP_RUN, *PRTL_BITMAP_RUN;
1319
1320 typedef NTSTATUS
1321 (DDKAPI *PRTL_QUERY_REGISTRY_ROUTINE)(
1322 IN PWSTR ValueName,
1323 IN ULONG ValueType,
1324 IN PVOID ValueData,
1325 IN ULONG ValueLength,
1326 IN PVOID Context,
1327 IN PVOID EntryContext);
1328
1329 typedef struct _RTL_QUERY_REGISTRY_TABLE {
1330 PRTL_QUERY_REGISTRY_ROUTINE QueryRoutine;
1331 ULONG Flags;
1332 PCWSTR Name;
1333 PVOID EntryContext;
1334 ULONG DefaultType;
1335 PVOID DefaultData;
1336 ULONG DefaultLength;
1337 } RTL_QUERY_REGISTRY_TABLE, *PRTL_QUERY_REGISTRY_TABLE;
1338
1339 typedef struct _TIME_FIELDS {
1340 CSHORT Year;
1341 CSHORT Month;
1342 CSHORT Day;
1343 CSHORT Hour;
1344 CSHORT Minute;
1345 CSHORT Second;
1346 CSHORT Milliseconds;
1347 CSHORT Weekday;
1348 } TIME_FIELDS, *PTIME_FIELDS;
1349
1350
1351 /******************************************************************************
1352 * RTL Functions *
1353 ******************************************************************************/
1354
1355 NTSYSAPI
1356 VOID
1357 NTAPI
1358 RtlAssert(
1359 IN PVOID FailedAssertion,
1360 IN PVOID FileName,
1361 IN ULONG LineNumber,
1362 IN PCHAR Message);
1363
1364 /* VOID
1365 * RtlCopyMemory(
1366 * IN VOID UNALIGNED *Destination,
1367 * IN CONST VOID UNALIGNED *Source,
1368 * IN SIZE_T Length)
1369 */
1370 #define RtlCopyMemory(Destination, Source, Length) \
1371 memcpy(Destination, Source, Length)
1372
1373 #define RtlCopyBytes RtlCopyMemory
1374
1375 #if defined(_M_AMD64)
1376 NTSYSAPI
1377 VOID
1378 NTAPI
1379 RtlCopyMemoryNonTemporal(
1380 VOID UNALIGNED *Destination,
1381 CONST VOID UNALIGNED *Source,
1382 SIZE_T Length);
1383 #else
1384 #define RtlCopyMemoryNonTemporal RtlCopyMemory
1385 #endif
1386
1387 /* BOOLEAN
1388 * RtlEqualLuid(
1389 * IN PLUID Luid1,
1390 * IN PLUID Luid2)
1391 */
1392 #define RtlEqualLuid(Luid1, Luid2) \
1393 (((Luid1)->LowPart == (Luid2)->LowPart) && ((Luid1)->HighPart == (Luid2)->HighPart))
1394
1395 /* ULONG
1396 * RtlEqualMemory(
1397 * IN VOID UNALIGNED *Destination,
1398 * IN CONST VOID UNALIGNED *Source,
1399 * IN SIZE_T Length)
1400 */
1401 #define RtlEqualMemory(Destination, Source, Length) \
1402 (!memcmp(Destination, Source, Length))
1403
1404 /* VOID
1405 * RtlFillMemory(
1406 * IN VOID UNALIGNED *Destination,
1407 * IN SIZE_T Length,
1408 * IN UCHAR Fill)
1409 */
1410 #define RtlFillMemory(Destination, Length, Fill) \
1411 memset(Destination, Fill, Length)
1412
1413 #define RtlFillBytes RtlFillMemory
1414
1415 NTSYSAPI
1416 VOID
1417 NTAPI
1418 RtlFreeUnicodeString(
1419 IN PUNICODE_STRING UnicodeString);
1420
1421 NTSYSAPI
1422 NTSTATUS
1423 NTAPI
1424 RtlGUIDFromString(
1425 IN PUNICODE_STRING GuidString,
1426 OUT GUID *Guid);
1427
1428 NTSYSAPI
1429 VOID
1430 NTAPI
1431 RtlInitUnicodeString(
1432 IN OUT PUNICODE_STRING DestinationString,
1433 IN PCWSTR SourceString);
1434
1435 /* VOID
1436 * RtlMoveMemory(
1437 * IN VOID UNALIGNED *Destination,
1438 * IN CONST VOID UNALIGNED *Source,
1439 * IN SIZE_T Length)
1440 */
1441 #define RtlMoveMemory(Destination, Source, Length) \
1442 memmove(Destination, Source, Length)
1443
1444 NTSYSAPI
1445 NTSTATUS
1446 NTAPI
1447 RtlStringFromGUID(
1448 IN REFGUID Guid,
1449 OUT PUNICODE_STRING GuidString);
1450
1451 /* VOID
1452 * RtlZeroMemory(
1453 * IN VOID UNALIGNED *Destination,
1454 * IN SIZE_T Length)
1455 */
1456 #define RtlZeroMemory(Destination, Length) \
1457 memset(Destination, 0, Length)
1458
1459 #define RtlZeroBytes RtlZeroMemory
1460
1461
1462 #if (NTDDI_VERSION >= NTDDI_WIN2K)
1463 NTSYSAPI
1464 BOOLEAN
1465 NTAPI
1466 RtlAreBitsClear(
1467 IN PRTL_BITMAP BitMapHeader,
1468 IN ULONG StartingIndex,
1469 IN ULONG Length);
1470
1471 NTSYSAPI
1472 BOOLEAN
1473 NTAPI
1474 RtlAreBitsSet(
1475 IN PRTL_BITMAP BitMapHeader,
1476 IN ULONG StartingIndex,
1477 IN ULONG Length);
1478
1479 NTSYSAPI
1480 NTSTATUS
1481 NTAPI
1482 RtlAnsiStringToUnicodeString(
1483 IN OUT PUNICODE_STRING DestinationString,
1484 IN PANSI_STRING SourceString,
1485 IN BOOLEAN AllocateDestinationString);
1486
1487 NTSYSAPI
1488 ULONG
1489 NTAPI
1490 RtlxAnsiStringToUnicodeSize(
1491 IN PCANSI_STRING AnsiString);
1492
1493 #define RtlAnsiStringToUnicodeSize(String) ( \
1494 NLS_MB_CODE_PAGE_TAG ? \
1495 RtlxAnsiStringToUnicodeSize(String) : \
1496 ((String)->Length + sizeof(ANSI_NULL)) * sizeof(WCHAR) \
1497 )
1498
1499 NTSYSAPI
1500 NTSTATUS
1501 NTAPI
1502 RtlAppendUnicodeStringToString(
1503 IN OUT PUNICODE_STRING Destination,
1504 IN PCUNICODE_STRING Source);
1505
1506 NTSYSAPI
1507 NTSTATUS
1508 NTAPI
1509 RtlAppendUnicodeToString(
1510 IN OUT PUNICODE_STRING Destination,
1511 IN PCWSTR Source);
1512
1513 NTSYSAPI
1514 NTSTATUS
1515 NTAPI
1516 RtlCheckRegistryKey(
1517 IN ULONG RelativeTo,
1518 IN PWSTR Path);
1519
1520 NTSYSAPI
1521 VOID
1522 NTAPI
1523 RtlClearAllBits(
1524 IN PRTL_BITMAP BitMapHeader);
1525
1526 NTSYSAPI
1527 VOID
1528 NTAPI
1529 RtlClearBits(
1530 IN PRTL_BITMAP BitMapHeader,
1531 IN ULONG StartingIndex,
1532 IN ULONG NumberToClear);
1533
1534 NTSYSAPI
1535 SIZE_T
1536 NTAPI
1537 RtlCompareMemory(
1538 IN CONST VOID *Source1,
1539 IN CONST VOID *Source2,
1540 IN SIZE_T Length);
1541
1542 NTSYSAPI
1543 LONG
1544 NTAPI
1545 RtlCompareUnicodeString(
1546 IN PCUNICODE_STRING String1,
1547 IN PCUNICODE_STRING String2,
1548 IN BOOLEAN CaseInSensitive);
1549
1550 NTSYSAPI
1551 LONG
1552 NTAPI
1553 RtlCompareUnicodeStrings(
1554 IN PCWCH String1,
1555 IN SIZE_T String1Length,
1556 IN PCWCH String2,
1557 IN SIZE_T String2Length,
1558 IN BOOLEAN CaseInSensitive);
1559
1560 NTSYSAPI
1561 VOID
1562 NTAPI
1563 RtlCopyUnicodeString(
1564 IN OUT PUNICODE_STRING DestinationString,
1565 IN PCUNICODE_STRING SourceString);
1566
1567 NTSYSAPI
1568 NTSTATUS
1569 NTAPI
1570 RtlCreateRegistryKey(
1571 IN ULONG RelativeTo,
1572 IN PWSTR Path);
1573
1574 NTSYSAPI
1575 NTSTATUS
1576 NTAPI
1577 RtlCreateSecurityDescriptor(
1578 IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
1579 IN ULONG Revision);
1580
1581 NTSYSAPI
1582 NTSTATUS
1583 NTAPI
1584 RtlDeleteRegistryValue(
1585 IN ULONG RelativeTo,
1586 IN PCWSTR Path,
1587 IN PCWSTR ValueName);
1588
1589 NTSYSAPI
1590 BOOLEAN
1591 NTAPI
1592 RtlEqualUnicodeString(
1593 IN CONST UNICODE_STRING *String1,
1594 IN CONST UNICODE_STRING *String2,
1595 IN BOOLEAN CaseInSensitive);
1596
1597 #if !defined(_AMD64_) && !defined(_IA64_)
1598 NTSYSAPI
1599 LARGE_INTEGER
1600 NTAPI
1601 RtlExtendedIntegerMultiply(
1602 IN LARGE_INTEGER Multiplicand,
1603 IN LONG Multiplier);
1604
1605 NTSYSAPI
1606 LARGE_INTEGER
1607 NTAPI
1608 RtlExtendedLargeIntegerDivide(
1609 IN LARGE_INTEGER Dividend,
1610 IN ULONG Divisor,
1611 IN OUT PULONG Remainder);
1612 #endif
1613
1614 #if defined(_X86_) || defined(_IA64_)
1615 NTSYSAPI
1616 LARGE_INTEGER
1617 NTAPI
1618 RtlExtendedMagicDivide(
1619 IN LARGE_INTEGER Dividend,
1620 IN LARGE_INTEGER MagicDivisor,
1621 IN CCHAR ShiftCount);
1622 #endif
1623
1624 NTSYSAPI
1625 VOID
1626 NTAPI
1627 RtlFreeAnsiString(
1628 IN PANSI_STRING AnsiString);
1629
1630 NTSYSAPI
1631 ULONG
1632 NTAPI
1633 RtlFindClearBits(
1634 IN PRTL_BITMAP BitMapHeader,
1635 IN ULONG NumberToFind,
1636 IN ULONG HintIndex);
1637
1638 NTSYSAPI
1639 ULONG
1640 NTAPI
1641 RtlFindClearBitsAndSet(
1642 IN PRTL_BITMAP BitMapHeader,
1643 IN ULONG NumberToFind,
1644 IN ULONG HintIndex);
1645
1646 NTSYSAPI
1647 ULONG
1648 NTAPI
1649 RtlFindFirstRunClear(
1650 IN PRTL_BITMAP BitMapHeader,
1651 OUT PULONG StartingIndex);
1652
1653 NTSYSAPI
1654 ULONG
1655 NTAPI
1656 RtlFindClearRuns(
1657 IN PRTL_BITMAP BitMapHeader,
1658 OUT PRTL_BITMAP_RUN RunArray,
1659 IN ULONG SizeOfRunArray,
1660 IN BOOLEAN LocateLongestRuns);
1661
1662 NTSYSAPI
1663 ULONG
1664 NTAPI
1665 RtlFindLastBackwardRunClear(
1666 IN PRTL_BITMAP BitMapHeader,
1667 IN ULONG FromIndex,
1668 OUT PULONG StartingRunIndex);
1669
1670 NTSYSAPI
1671 CCHAR
1672 NTAPI
1673 RtlFindLeastSignificantBit(
1674 IN ULONGLONG Set);
1675
1676 NTSYSAPI
1677 ULONG
1678 NTAPI
1679 RtlFindLongestRunClear(
1680 IN PRTL_BITMAP BitMapHeader,
1681 OUT PULONG StartingIndex);
1682
1683 NTSYSAPI
1684 CCHAR
1685 NTAPI
1686 RtlFindMostSignificantBit(
1687 IN ULONGLONG Set);
1688
1689 NTSYSAPI
1690 ULONG
1691 NTAPI
1692 RtlFindNextForwardRunClear(
1693 IN PRTL_BITMAP BitMapHeader,
1694 IN ULONG FromIndex,
1695 OUT PULONG StartingRunIndex);
1696
1697 NTSYSAPI
1698 ULONG
1699 NTAPI
1700 RtlFindSetBits(
1701 IN PRTL_BITMAP BitMapHeader,
1702 IN ULONG NumberToFind,
1703 IN ULONG HintIndex);
1704
1705 NTSYSAPI
1706 ULONG
1707 NTAPI
1708 RtlFindSetBitsAndClear(
1709 IN PRTL_BITMAP BitMapHeader,
1710 IN ULONG NumberToFind,
1711 IN ULONG HintIndex);
1712
1713 NTSYSAPI
1714 NTSTATUS
1715 NTAPI
1716 RtlHashUnicodeString(
1717 IN CONST UNICODE_STRING *String,
1718 IN BOOLEAN CaseInSensitive,
1719 IN ULONG HashAlgorithm,
1720 OUT PULONG HashValue);
1721
1722 NTSYSAPI
1723 VOID
1724 NTAPI
1725 RtlInitAnsiString(
1726 IN OUT PANSI_STRING DestinationString,
1727 IN PCSZ SourceString);
1728
1729 NTSYSAPI
1730 VOID
1731 NTAPI
1732 RtlInitializeBitMap(
1733 IN PRTL_BITMAP BitMapHeader,
1734 IN PULONG BitMapBuffer,
1735 IN ULONG SizeOfBitMap);
1736
1737 NTSYSAPI
1738 VOID
1739 NTAPI
1740 RtlInitString(
1741 IN OUT PSTRING DestinationString,
1742 IN PCSZ SourceString);
1743
1744 NTSYSAPI
1745 NTSTATUS
1746 NTAPI
1747 RtlIntegerToUnicodeString(
1748 IN ULONG Value,
1749 IN ULONG Base OPTIONAL,
1750 IN OUT PUNICODE_STRING String);
1751
1752 NTSYSAPI
1753 NTSTATUS
1754 NTAPI
1755 RtlInt64ToUnicodeString(
1756 IN ULONGLONG Value,
1757 IN ULONG Base OPTIONAL,
1758 IN OUT PUNICODE_STRING String);
1759
1760 #ifdef _WIN64
1761 #define RtlIntPtrToUnicodeString(Value, Base, String) \
1762 RtlInt64ToUnicodeString(Value, Base, String)
1763 #else
1764 #define RtlIntPtrToUnicodeString(Value, Base, String) \
1765 RtlIntegerToUnicodeString(Value, Base, String)
1766 #endif
1767
1768 /* BOOLEAN
1769 * RtlIsZeroLuid(
1770 * IN PLUID L1);
1771 */
1772 #define RtlIsZeroLuid(_L1) \
1773 ((BOOLEAN) ((!(_L1)->LowPart) && (!(_L1)->HighPart)))
1774
1775 NTSYSAPI
1776 ULONG
1777 NTAPI
1778 RtlLengthSecurityDescriptor(
1779 IN PSECURITY_DESCRIPTOR SecurityDescriptor);
1780
1781 NTSYSAPI
1782 ULONG
1783 NTAPI
1784 RtlNumberOfClearBits(
1785 IN PRTL_BITMAP BitMapHeader);
1786
1787 NTSYSAPI
1788 ULONG
1789 NTAPI
1790 RtlNumberOfSetBits(
1791 IN PRTL_BITMAP BitMapHeader);
1792
1793 NTSYSAPI
1794 NTSTATUS
1795 NTAPI
1796 RtlQueryRegistryValues(
1797 IN ULONG RelativeTo,
1798 IN PCWSTR Path,
1799 IN PRTL_QUERY_REGISTRY_TABLE QueryTable,
1800 IN PVOID Context,
1801 IN PVOID Environment OPTIONAL);
1802
1803 #define LONG_SIZE (sizeof(LONG))
1804 #define LONG_MASK (LONG_SIZE - 1)
1805
1806 /* VOID
1807 * RtlRetrieveUlong(
1808 * PULONG DestinationAddress,
1809 * PULONG SourceAddress);
1810 */
1811 #if defined(_AMD64_)
1812 #define RtlRetrieveUlong(DestAddress,SrcAddress) \
1813 *(ULONG UNALIGNED *)(DestAddress) = *(PULONG)(SrcAddress)
1814 #else
1815 #define RtlRetrieveUlong(DestAddress,SrcAddress) \
1816 if ((ULONG_PTR)(SrcAddress) & LONG_MASK) \
1817 { \
1818 ((PUCHAR)(DestAddress))[0]=((PUCHAR)(SrcAddress))[0]; \
1819 ((PUCHAR)(DestAddress))[1]=((PUCHAR)(SrcAddress))[1]; \
1820 ((PUCHAR)(DestAddress))[2]=((PUCHAR)(SrcAddress))[2]; \
1821 ((PUCHAR)(DestAddress))[3]=((PUCHAR)(SrcAddress))[3]; \
1822 } \
1823 else \
1824 { \
1825 *((PULONG)(DestAddress))=*((PULONG)(SrcAddress)); \
1826 }
1827 #endif
1828
1829 /* VOID
1830 * RtlRetrieveUshort(
1831 * PUSHORT DestinationAddress,
1832 * PUSHORT SourceAddress);
1833 */
1834 #if defined(_AMD64_)
1835 #define RtlRetrieveUshort(DestAddress,SrcAddress) \
1836 *(USHORT UNALIGNED *)(DestAddress) = *(USHORT)(SrcAddress)
1837 #else
1838 #define RtlRetrieveUshort(DestAddress,SrcAddress) \
1839 if ((ULONG_PTR)(SrcAddress) & LONG_MASK) \
1840 { \
1841 ((PUCHAR)(DestAddress))[0]=((PUCHAR)(SrcAddress))[0]; \
1842 ((PUCHAR)(DestAddress))[1]=((PUCHAR)(SrcAddress))[1]; \
1843 } \
1844 else \
1845 { \
1846 *((PUSHORT)(DestAddress))=*((PUSHORT)(SrcAddress)); \
1847 }
1848 #endif
1849
1850 NTSYSAPI
1851 VOID
1852 NTAPI
1853 RtlSetAllBits(
1854 IN PRTL_BITMAP BitMapHeader);
1855
1856 NTSYSAPI
1857 VOID
1858 NTAPI
1859 RtlSetBits(
1860 IN PRTL_BITMAP BitMapHeader,
1861 IN ULONG StartingIndex,
1862 IN ULONG NumberToSet);
1863
1864 NTSYSAPI
1865 NTSTATUS
1866 NTAPI
1867 RtlSetDaclSecurityDescriptor(
1868 IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
1869 IN BOOLEAN DaclPresent,
1870 IN PACL Dacl OPTIONAL,
1871 IN BOOLEAN DaclDefaulted OPTIONAL);
1872
1873 /* VOID
1874 * RtlStoreUlong(
1875 * IN PULONG Address,
1876 * IN ULONG Value);
1877 */
1878 #if defined(_AMD64_)
1879 #define RtlStoreUlong(Address,Value) \
1880 *(ULONG UNALIGNED *)(Address) = (Value)
1881 #else
1882 #define RtlStoreUlong(Address,Value) \
1883 if ((ULONG_PTR)(Address) & LONG_MASK) { \
1884 ((PUCHAR) (Address))[LONG_LEAST_SIGNIFICANT_BIT] = (UCHAR)(FIRSTBYTE(Value)); \
1885 ((PUCHAR) (Address))[LONG_3RD_MOST_SIGNIFICANT_BIT] = (UCHAR)(SECONDBYTE(Value)); \
1886 ((PUCHAR) (Address))[LONG_2ND_MOST_SIGNIFICANT_BIT] = (UCHAR)(THIRDBYTE(Value)); \
1887 ((PUCHAR) (Address))[LONG_MOST_SIGNIFICANT_BIT] = (UCHAR)(FOURTHBYTE(Value)); \
1888 } \
1889 else { \
1890 *((PULONG)(Address)) = (ULONG) (Value); \
1891 }
1892 #endif
1893
1894 /* VOID
1895 * RtlStoreUlonglong(
1896 * IN OUT PULONGLONG Address,
1897 * ULONGLONG Value);
1898 */
1899 #if defined(_AMD64_)
1900 #define RtlStoreUlonglong(Address,Value) \
1901 *(ULONGLONG UNALIGNED *)(Address) = (Value)
1902 #else
1903 #define RtlStoreUlonglong(Address,Value) \
1904 if ((ULONG_PTR)(Address) & LONGLONG_MASK) { \
1905 RtlStoreUlong((ULONG_PTR)(Address), \
1906 (ULONGLONG)(Value) & 0xFFFFFFFF); \
1907 RtlStoreUlong((ULONG_PTR)(Address)+sizeof(ULONG), \
1908 (ULONGLONG)(Value) >> 32); \
1909 } else { \
1910 *((PULONGLONG)(Address)) = (ULONGLONG)(Value); \
1911 }
1912 #endif
1913
1914 /* VOID
1915 * RtlStoreUlongPtr(
1916 * IN OUT PULONG_PTR Address,
1917 * IN ULONG_PTR Value);
1918 */
1919 #ifdef _WIN64
1920 #define RtlStoreUlongPtr(Address,Value) \
1921 RtlStoreUlonglong(Address,Value)
1922 #else
1923 #define RtlStoreUlongPtr(Address,Value) \
1924 RtlStoreUlong(Address,Value)
1925 #endif
1926
1927 /* VOID
1928 * RtlStoreUshort(
1929 * IN PUSHORT Address,
1930 * IN USHORT Value);
1931 */
1932 #if defined(_AMD64_)
1933 #define RtlStoreUshort(Address,Value) \
1934 *(USHORT UNALIGNED *)(Address) = (Value)
1935 #else
1936 #define RtlStoreUshort(Address,Value) \
1937 if ((ULONG_PTR)(Address) & SHORT_MASK) { \
1938 ((PUCHAR) (Address))[SHORT_LEAST_SIGNIFICANT_BIT] = (UCHAR)(FIRSTBYTE(Value)); \
1939 ((PUCHAR) (Address))[SHORT_MOST_SIGNIFICANT_BIT ] = (UCHAR)(SECONDBYTE(Value)); \
1940 } \
1941 else { \
1942 *((PUSHORT) (Address)) = (USHORT)Value; \
1943 }
1944 #endif
1945
1946 NTSYSAPI
1947 BOOLEAN
1948 NTAPI
1949 RtlTimeFieldsToTime(
1950 IN PTIME_FIELDS TimeFields,
1951 IN PLARGE_INTEGER Time);
1952
1953 NTSYSAPI
1954 VOID
1955 NTAPI
1956 RtlTimeToTimeFields(
1957 IN PLARGE_INTEGER Time,
1958 IN PTIME_FIELDS TimeFields);
1959
1960 NTSYSAPI
1961 ULONG
1962 FASTCALL
1963 RtlUlongByteSwap(
1964 IN ULONG Source);
1965
1966 NTSYSAPI
1967 ULONGLONG
1968 FASTCALL
1969 RtlUlonglongByteSwap(
1970 IN ULONGLONG Source);
1971
1972 NTSYSAPI
1973 NTSTATUS
1974 NTAPI
1975 RtlUnicodeStringToAnsiString(
1976 IN OUT PANSI_STRING DestinationString,
1977 IN PCUNICODE_STRING SourceString,
1978 IN BOOLEAN AllocateDestinationString);
1979
1980 NTSYSAPI
1981 ULONG
1982 NTAPI
1983 RtlxUnicodeStringToAnsiSize(
1984 IN PCUNICODE_STRING UnicodeString);
1985
1986 #define RtlUnicodeStringToAnsiSize(String) ( \
1987 NLS_MB_CODE_PAGE_TAG ? \
1988 RtlxUnicodeStringToAnsiSize(String) : \
1989 ((String)->Length + sizeof(UNICODE_NULL)) / sizeof(WCHAR) \
1990 )
1991
1992 NTSYSAPI
1993 NTSTATUS
1994 NTAPI
1995 RtlUnicodeStringToInteger(
1996 IN PCUNICODE_STRING String,
1997 IN ULONG Base OPTIONAL,
1998 OUT PULONG Value);
1999
2000 NTSYSAPI
2001 WCHAR
2002 NTAPI
2003 RtlUpcaseUnicodeChar(
2004 IN WCHAR SourceCharacter);
2005
2006 NTSYSAPI
2007 USHORT
2008 FASTCALL
2009 RtlUshortByteSwap(
2010 IN USHORT Source);
2011
2012 NTSYSAPI
2013 BOOLEAN
2014 NTAPI
2015 RtlValidRelativeSecurityDescriptor(
2016 IN PSECURITY_DESCRIPTOR SecurityDescriptorInput,
2017 IN ULONG SecurityDescriptorLength,
2018 IN SECURITY_INFORMATION RequiredInformation);
2019
2020 NTSYSAPI
2021 BOOLEAN
2022 NTAPI
2023 RtlValidSecurityDescriptor(
2024 IN PSECURITY_DESCRIPTOR SecurityDescriptor);
2025
2026 NTSYSAPI
2027 NTSTATUS
2028 NTAPI
2029 RtlWriteRegistryValue(
2030 IN ULONG RelativeTo,
2031 IN PCWSTR Path,
2032 IN PCWSTR ValueName,
2033 IN ULONG ValueType,
2034 IN PVOID ValueData,
2035 IN ULONG ValueLength);
2036
2037 #endif // (NTDDI_VERSION >= NTDDI_WIN2K)
2038
2039 #if (NTDDI_VERSION >= NTDDI_WIN2KSP3)
2040 NTSYSAPI
2041 VOID
2042 FASTCALL
2043 RtlPrefetchMemoryNonTemporal(
2044 IN PVOID Source,
2045 IN SIZE_T Length);
2046 #endif
2047
2048 #if (NTDDI_VERSION >= NTDDI_WINXP)
2049 NTSYSAPI
2050 VOID
2051 NTAPI
2052 RtlClearBit(
2053 PRTL_BITMAP BitMapHeader,
2054 ULONG BitNumber);
2055
2056 NTSYSAPI
2057 WCHAR
2058 NTAPI
2059 RtlDowncaseUnicodeChar(
2060 IN WCHAR SourceCharacter);
2061
2062 NTSYSAPI
2063 VOID
2064 NTAPI
2065 RtlSetBit(
2066 PRTL_BITMAP BitMapHeader,
2067 ULONG BitNumber);
2068
2069 NTSYSAPI
2070 BOOLEAN
2071 NTAPI
2072 RtlTestBit(
2073 IN PRTL_BITMAP BitMapHeader,
2074 IN ULONG BitNumber);
2075
2076 #endif // (NTDDI_VERSION >= NTDDI_WINXP)
2077
2078 #if (NTDDI_VERSION >= NTDDI_VISTA)
2079 NTSYSAPI
2080 ULONG
2081 NTAPI
2082 RtlNumberOfSetBitsUlongPtr(
2083 IN ULONG_PTR Target);
2084
2085 NTSYSAPI
2086 ULONGLONG
2087 NTAPI
2088 RtlIoDecodeMemIoResource (
2089 IN PIO_RESOURCE_DESCRIPTOR Descriptor,
2090 OUT PULONGLONG Alignment OPTIONAL,
2091 OUT PULONGLONG MinimumAddress OPTIONAL,
2092 OUT PULONGLONG MaximumAddress OPTIONAL);
2093
2094 NTSYSAPI
2095 NTSTATUS
2096 NTAPI
2097 RtlIoEncodeMemIoResource(
2098 IN PIO_RESOURCE_DESCRIPTOR Descriptor,
2099 IN UCHAR Type,
2100 IN ULONGLONG Length,
2101 IN ULONGLONG Alignment,
2102 IN ULONGLONG MinimumAddress,
2103 IN ULONGLONG MaximumAddress);
2104
2105 NTSYSAPI
2106 ULONGLONG
2107 NTAPI
2108 RtlCmDecodeMemIoResource(
2109 IN PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor,
2110 OUT PULONGLONG Start OPTIONAL);
2111
2112 NTSYSAPI
2113 NTSTATUS
2114 NTAPI
2115 RtlFindClosestEncodableLength(
2116 IN ULONGLONG SourceLength,
2117 OUT PULONGLONG TargetLength);
2118
2119 #endif
2120
2121 #if !defined(MIDL_PASS)
2122 /* inline funftions */
2123 //DECLSPEC_DEPRECATED_DDK_WINXP
2124 static __inline
2125 LARGE_INTEGER
2126 NTAPI_INLINE
2127 RtlConvertLongToLargeInteger(LONG SignedInteger)
2128 {
2129 LARGE_INTEGER ret;
2130 ret.QuadPart = SignedInteger;
2131 return ret;
2132 }
2133
2134 //DECLSPEC_DEPRECATED_DDK_WINXP
2135 static __inline
2136 LARGE_INTEGER
2137 NTAPI_INLINE
2138 RtlConvertUlongToLargeInteger(
2139 ULONG UnsignedInteger)
2140 {
2141 LARGE_INTEGER ret;
2142 ret.QuadPart = UnsignedInteger;
2143 return ret;
2144 }
2145
2146 //DECLSPEC_DEPRECATED_DDK
2147 static __inline
2148 ULONG
2149 NTAPI_INLINE
2150 RtlEnlargedUnsignedDivide(
2151 IN ULARGE_INTEGER Dividend,
2152 IN ULONG Divisor,
2153 IN OUT PULONG Remainder)
2154 {
2155 if (Remainder)
2156 *Remainder = (ULONG)(Dividend.QuadPart % Divisor);
2157 return (ULONG)(Dividend.QuadPart / Divisor);
2158 }
2159
2160 //DECLSPEC_DEPRECATED_DDK
2161 static __inline
2162 LARGE_INTEGER
2163 NTAPI_INLINE
2164 RtlEnlargedUnsignedMultiply(
2165 IN ULONG Multiplicand,
2166 IN ULONG Multiplier)
2167 {
2168 LARGE_INTEGER ret;
2169 ret.QuadPart = (ULONGLONG)Multiplicand * (ULONGLONG)Multiplier;
2170 return ret;
2171 }
2172
2173 //DECLSPEC_DEPRECATED_DDK
2174 static __inline
2175 LARGE_INTEGER
2176 NTAPI_INLINE
2177 RtlEnlargedIntegerMultiply(
2178 IN LONG Multiplicand,
2179 IN LONG Multiplier)
2180 {
2181 LARGE_INTEGER ret;
2182 ret.QuadPart = (LONGLONG)Multiplicand * (ULONGLONG)Multiplier;
2183 return ret;
2184 }
2185
2186 FORCEINLINE
2187 VOID
2188 RtlInitEmptyAnsiString(OUT PANSI_STRING AnsiString,
2189 IN PCHAR Buffer,
2190 IN USHORT BufferSize)
2191 {
2192 AnsiString->Length = 0;
2193 AnsiString->MaximumLength = BufferSize;
2194 AnsiString->Buffer = Buffer;
2195 }
2196
2197 FORCEINLINE
2198 VOID
2199 RtlInitEmptyUnicodeString(
2200 OUT PUNICODE_STRING UnicodeString,
2201 IN PWSTR Buffer,
2202 IN USHORT BufferSize)
2203 {
2204 UnicodeString->Length = 0;
2205 UnicodeString->MaximumLength = BufferSize;
2206 UnicodeString->Buffer = Buffer;
2207 }
2208
2209 #if defined(_AMD64_) || defined(_IA64_)
2210 static __inline
2211 LARGE_INTEGER
2212 NTAPI_INLINE
2213 RtlExtendedIntegerMultiply(
2214 LARGE_INTEGER Multiplicand,
2215 LONG Multiplier)
2216 {
2217 LARGE_INTEGER ret;
2218 ret.QuadPart = Multiplicand.QuadPart * Multiplier;
2219 return ret;
2220 }
2221
2222 static __inline
2223 LARGE_INTEGER
2224 NTAPI_INLINE
2225 RtlExtendedLargeIntegerDivide(
2226 LARGE_INTEGER Dividend,
2227 ULONG Divisor,
2228 PULONG Remainder)
2229 {
2230 LARGE_INTEGER ret;
2231 ret.QuadPart = (ULONG64)Dividend.QuadPart / Divisor;
2232 if (Remainder)
2233 *Remainder = (ULONG)(Dividend.QuadPart % Divisor);
2234 return ret;
2235 }
2236 #endif
2237
2238 #if defined(_AMD64_)
2239
2240 #define MultiplyHigh __mulh
2241 #define UnsignedMultiplyHigh __umulh
2242
2243 //DECLSPEC_DEPRECATED_DDK
2244 static __inline
2245 LARGE_INTEGER
2246 NTAPI_INLINE
2247 RtlExtendedMagicDivide(
2248 IN LARGE_INTEGER Dividend,
2249 IN LARGE_INTEGER MagicDivisor,
2250 IN CCHAR ShiftCount)
2251 {
2252 LARGE_INTEGER ret;
2253 ULONG64 ret64;
2254 BOOLEAN Pos;
2255 Pos = (Dividend.QuadPart >= 0);
2256 ret64 = UnsignedMultiplyHigh(Pos ? Dividend.QuadPart : -Dividend.QuadPart,
2257 MagicDivisor.QuadPart);
2258 ret64 >>= ShiftCount;
2259 ret.QuadPart = Pos ? ret64 : -ret64;
2260 return ret;
2261 }
2262 #endif
2263
2264 //DECLSPEC_DEPRECATED_DDK
2265 static __inline
2266 LARGE_INTEGER
2267 NTAPI_INLINE
2268 RtlLargeIntegerAdd(
2269 IN LARGE_INTEGER Addend1,
2270 IN LARGE_INTEGER Addend2)
2271 {
2272 LARGE_INTEGER ret;
2273 ret.QuadPart = Addend1.QuadPart + Addend2.QuadPart;
2274 return ret;
2275 }
2276
2277 /* VOID
2278 * RtlLargeIntegerAnd(
2279 * IN OUT LARGE_INTEGER Result,
2280 * IN LARGE_INTEGER Source,
2281 * IN LARGE_INTEGER Mask);
2282 */
2283 #define RtlLargeIntegerAnd(Result, Source, Mask) \
2284 Result.QuadPart = Source.QuadPart & Mask.QuadPart
2285
2286 //DECLSPEC_DEPRECATED_DDK
2287 static __inline
2288 LARGE_INTEGER
2289 NTAPI_INLINE
2290 RtlLargeIntegerArithmeticShift(
2291 IN LARGE_INTEGER LargeInteger,
2292 IN CCHAR ShiftCount)
2293 {
2294 LARGE_INTEGER ret;
2295 ret.QuadPart = LargeInteger.QuadPart >> ShiftCount;
2296 return ret;
2297 }
2298
2299 /* BOOLEAN
2300 * RtlLargeIntegerEqualTo(
2301 * IN LARGE_INTEGER Operand1,
2302 * IN LARGE_INTEGER Operand2);
2303 */
2304 #define RtlLargeIntegerEqualTo(X,Y) \
2305 (!(((X).LowPart ^ (Y).LowPart) | ((X).HighPart ^ (Y).HighPart)))
2306
2307 FORCEINLINE
2308 PVOID
2309 RtlSecureZeroMemory(
2310 OUT PVOID Pointer,
2311 IN SIZE_T Size)
2312 {
2313 volatile char* vptr = (volatile char*)Pointer;
2314 #if defined(_M_AMD64)
2315 __stosb((PUCHAR)vptr, 0, Size);
2316 #else
2317 char * endptr = (char *)vptr + Size;
2318 while (vptr < endptr)
2319 {
2320 *vptr = 0; vptr++;
2321 }
2322 #endif
2323 return Pointer;
2324 }
2325
2326 #if defined(_M_AMD64)
2327 FORCEINLINE
2328 ULONG
2329 RtlCheckBit(
2330 IN PRTL_BITMAP BitMapHeader,
2331 IN ULONG BitPosition)
2332 {
2333 return BitTest((LONG CONST*)BitMapHeader->Buffer, BitPosition);
2334 }
2335 #else
2336 #define RtlCheckBit(BMH,BP) (((((PLONG)(BMH)->Buffer)[(BP)/32]) >> ((BP)%32)) & 0x1)
2337 #endif // defined(_M_AMD64)
2338
2339 #endif // !defined(MIDL_PASS)
2340
2341 //
2342 // Byte Swap Functions
2343 //
2344 #if (defined(_M_IX86) && (_MSC_FULL_VER > 13009037 || defined(__GNUC__))) || \
2345 ((defined(_M_AMD64) || defined(_M_IA64)) \
2346 && (_MSC_FULL_VER > 13009175 || defined(__GNUC__)))
2347
2348 #define RtlUshortByteSwap(_x) _byteswap_ushort((USHORT)(_x))
2349 #define RtlUlongByteSwap(_x) _byteswap_ulong((_x))
2350 #define RtlUlonglongByteSwap(_x) _byteswap_uint64((_x))
2351
2352 #endif
2353
2354 /******************************************************************************
2355 * Memory manager Types *
2356 ******************************************************************************/
2357
2358 typedef struct _MDL {
2359 struct _MDL *Next;
2360 CSHORT Size;
2361 CSHORT MdlFlags;
2362 struct _EPROCESS *Process;
2363 PVOID MappedSystemVa;
2364 PVOID StartVa;
2365 ULONG ByteCount;
2366 ULONG ByteOffset;
2367 } MDL, *PMDL;
2368
2369
2370 /******************************************************************************
2371 * Memory manager Functions *
2372 ******************************************************************************/
2373
2374 /* PVOID MmGetSystemAddressForMdl(
2375 * IN PMDL Mdl);
2376 */
2377 #define MmGetSystemAddressForMdl(Mdl) \
2378 (((Mdl)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA | \
2379 MDL_SOURCE_IS_NONPAGED_POOL)) ? \
2380 ((Mdl)->MappedSystemVa) : \
2381 (MmMapLockedPages((Mdl), KernelMode)))
2382
2383 /* PVOID
2384 * MmGetSystemAddressForMdlSafe(
2385 * IN PMDL Mdl,
2386 * IN MM_PAGE_PRIORITY Priority)
2387 */
2388 #define MmGetSystemAddressForMdlSafe(_Mdl, _Priority) \
2389 (((_Mdl)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA \
2390 | MDL_SOURCE_IS_NONPAGED_POOL)) ? \
2391 (_Mdl)->MappedSystemVa : \
2392 (PVOID) MmMapLockedPagesSpecifyCache((_Mdl), \
2393 KernelMode, MmCached, NULL, FALSE, (_Priority)))
2394
2395 #if (NTDDI_VERSION >= NTDDI_WIN2K)
2396 NTKERNELAPI
2397 PMDL
2398 NTAPI
2399 MmCreateMdl(
2400 IN PMDL MemoryDescriptorList OPTIONAL,
2401 IN PVOID Base,
2402 IN SIZE_T Length);
2403
2404 #endif
2405
2406
2407 /******************************************************************************
2408 * I/O Manager Functions *
2409 ******************************************************************************/
2410
2411 #if defined(USE_DMA_MACROS) && !defined(_NTHAL_) && \
2412 (defined(_NTDDK_) || defined(_NTDRIVER_)) || defined(_WDM_INCLUDED_)
2413
2414 #define DMA_MACROS_DEFINED
2415
2416 FORCEINLINE
2417 NTSTATUS
2418 IoAllocateAdapterChannel(
2419 IN PADAPTER_OBJECT AdapterObject,
2420 IN PDEVICE_OBJECT DeviceObject,
2421 IN ULONG NumberOfMapRegisters,
2422 IN PDRIVER_CONTROL ExecutionRoutine,
2423 IN PVOID Context)
2424 {
2425 PALLOCATE_ADAPTER_CHANNEL AllocateAdapterChannel;
2426 AllocateAdapterChannel =
2427 *(DmaAdapter)->DmaOperations->AllocateAdapterChannel;
2428 ASSERT(AllocateAdapterChannel);
2429 return AllocateAdapterChannel(DmaAdapter,
2430 DeviceObject,
2431 NumberOfMapRegisters,
2432 ExecutionRoutine,
2433 Context );
2434 }
2435
2436 FORCEINLINE
2437 BOOLEAN
2438 IoFlushAdapterBuffers(
2439 IN PADAPTER_OBJECT AdapterObject,
2440 IN PMDL Mdl,
2441 IN PVOID MapRegisterBase,
2442 IN PVOID CurrentVa,
2443 IN ULONG Length,
2444 IN BOOLEAN WriteToDevice)
2445 {
2446 PFLUSH_ADAPTER_BUFFERS FlushAdapterBuffers;
2447 FlushAdapterBuffers = *(DmaAdapter)->DmaOperations->FlushAdapterBuffers;
2448 ASSERT(FlushAdapterBuffers);
2449 return FlushAdapterBuffers(DmaAdapter,
2450 Mdl,
2451 MapRegisterBase,
2452 CurrentVa,
2453 Length,
2454 WriteToDevice );
2455 }
2456
2457 FORCEINLINE
2458 VOID
2459 IoFreeAdapterChannel(
2460 IN PADAPTER_OBJECT AdapterObject)
2461 {
2462 PFREE_ADAPTER_CHANNEL FreeAdapterChannel;
2463 FreeAdapterChannel = *(DmaAdapter)->DmaOperations->FreeAdapterChannel;
2464 ASSERT(FreeAdapterChannel);
2465 FreeAdapterChannel(DmaAdapter);
2466 }
2467
2468 FORCEINLINE
2469 VOID
2470 IoFreeMapRegisters(
2471 IN PADAPTER_OBJECT AdapterObject,
2472 IN PVOID MapRegisterBase,
2473 IN ULONG NumberOfMapRegisters)
2474 {
2475 PFREE_MAP_REGISTERS FreeMapRegisters;
2476 FreeMapRegisters = *(DmaAdapter)->DmaOperations->FreeMapRegisters;
2477 ASSERT(FreeMapRegisters);
2478 FreeMapRegisters(DmaAdapter, MapRegisterBase, NumberOfMapRegisters);
2479 }
2480
2481 FORCEINLINE
2482 PHYSICAL_ADDRESS
2483 IoMapTransfer(
2484 IN PDMA_ADAPTER DmaAdapter,
2485 IN PMDL Mdl,
2486 IN PVOID MapRegisterBase,
2487 IN PVOID CurrentVa,
2488 IN OUT PULONG Length,
2489 IN BOOLEAN WriteToDevice)
2490 {
2491 PMAP_TRANSFER MapTransfer;
2492
2493 MapTransfer = *(DmaAdapter)->DmaOperations->MapTransfer;
2494 ASSERT(MapTransfer);
2495 return MapTransfer(DmaAdapter,
2496 Mdl,
2497 MapRegisterBase,
2498 CurrentVa,
2499 Length,
2500 WriteToDevice);
2501 }
2502 #endif
2503
2504
2505 /******************************************************************************
2506 * Executive Types *
2507 ******************************************************************************/
2508
2509 typedef enum _POOL_TYPE {
2510 NonPagedPool,
2511 PagedPool,
2512 NonPagedPoolMustSucceed,
2513 DontUseThisType,
2514 NonPagedPoolCacheAligned,
2515 PagedPoolCacheAligned,
2516 NonPagedPoolCacheAlignedMustS,
2517 MaxPoolType,
2518 NonPagedPoolSession = 32,
2519 PagedPoolSession,
2520 NonPagedPoolMustSucceedSession,
2521 DontUseThisTypeSession,
2522 NonPagedPoolCacheAlignedSession,
2523 PagedPoolCacheAlignedSession,
2524 NonPagedPoolCacheAlignedMustSSession
2525 } POOL_TYPE;
2526
2527 typedef enum _SUITE_TYPE {
2528 SmallBusiness,
2529 Enterprise,
2530 BackOffice,
2531 CommunicationServer,
2532 TerminalServer,
2533 SmallBusinessRestricted,
2534 EmbeddedNT,
2535 DataCenter,
2536 SingleUserTS,
2537 Personal,
2538 Blade,
2539 MaxSuiteType
2540 } SUITE_TYPE;
2541
2542 typedef enum _EX_POOL_PRIORITY {
2543 LowPoolPriority,
2544 LowPoolPrioritySpecialPoolOverrun = 8,
2545 LowPoolPrioritySpecialPoolUnderrun = 9,
2546 NormalPoolPriority = 16,
2547 NormalPoolPrioritySpecialPoolOverrun = 24,
2548 NormalPoolPrioritySpecialPoolUnderrun = 25,
2549 HighPoolPriority = 32,
2550 HighPoolPrioritySpecialPoolOverrun = 40,
2551 HighPoolPrioritySpecialPoolUnderrun = 41
2552 } EX_POOL_PRIORITY;
2553
2554 typedef struct _FAST_MUTEX
2555 {
2556 LONG Count;
2557 PKTHREAD Owner;
2558 ULONG Contention;
2559 KEVENT Gate;
2560 ULONG OldIrql;
2561 } FAST_MUTEX, *PFAST_MUTEX;
2562
2563 typedef ULONG_PTR ERESOURCE_THREAD, *PERESOURCE_THREAD;
2564
2565 typedef struct _OWNER_ENTRY {
2566 ERESOURCE_THREAD OwnerThread;
2567 _ANONYMOUS_UNION union {
2568 LONG OwnerCount;
2569 ULONG TableSize;
2570 } DUMMYUNIONNAME;
2571 } OWNER_ENTRY, *POWNER_ENTRY;
2572
2573 typedef struct _ERESOURCE
2574 {
2575 LIST_ENTRY SystemResourcesList;
2576 POWNER_ENTRY OwnerTable;
2577 SHORT ActiveCount;
2578 USHORT Flag;
2579 volatile PKSEMAPHORE SharedWaiters;
2580 volatile PKEVENT ExclusiveWaiters;
2581 OWNER_ENTRY OwnerEntry;
2582 ULONG ActiveEntries;
2583 ULONG ContentionCount;
2584 ULONG NumberOfSharedWaiters;
2585 ULONG NumberOfExclusiveWaiters;
2586 __GNU_EXTENSION union
2587 {
2588 PVOID Address;
2589 ULONG_PTR CreatorBackTraceIndex;
2590 };
2591 KSPIN_LOCK SpinLock;
2592 } ERESOURCE, *PERESOURCE;
2593
2594 #if !defined(_WIN64) && (defined(_NTDDK_) || defined(_NTIFS_) || defined(_NDIS_))
2595 #define LOOKASIDE_ALIGN
2596 #else
2597 #define LOOKASIDE_ALIGN /* FIXME: DECLSPEC_CACHEALIGN */
2598 #endif
2599
2600 typedef struct _LOOKASIDE_LIST_EX *PLOOKASIDE_LIST_EX;
2601
2602 typedef PVOID
2603 (DDKAPI *PALLOCATE_FUNCTION)(
2604 IN POOL_TYPE PoolType,
2605 IN SIZE_T NumberOfBytes,
2606 IN ULONG Tag);
2607
2608 typedef PVOID
2609 (DDKAPI *PALLOCATE_FUNCTION_EX)(
2610 IN POOL_TYPE PoolType,
2611 IN SIZE_T NumberOfBytes,
2612 IN ULONG Tag,
2613 IN OUT PLOOKASIDE_LIST_EX Lookaside);
2614
2615 typedef VOID
2616 (DDKAPI *PFREE_FUNCTION)(
2617 IN PVOID Buffer);
2618
2619 typedef VOID
2620 (DDKAPI *PFREE_FUNCTION_EX)(
2621 IN PVOID Buffer,
2622 IN OUT PLOOKASIDE_LIST_EX Lookaside);
2623
2624 typedef VOID
2625 (DDKAPI *PCALLBACK_FUNCTION)(
2626 IN PVOID CallbackContext,
2627 IN PVOID Argument1,
2628 IN PVOID Argument2);
2629
2630 typedef struct LOOKASIDE_ALIGN _GENERAL_LOOKASIDE {
2631 union {
2632 SLIST_HEADER ListHead;
2633 SINGLE_LIST_ENTRY SingleListHead;
2634 } DUMMYUNIONNAME;
2635 USHORT Depth;
2636 USHORT MaximumDepth;
2637 ULONG TotalAllocates;
2638 union {
2639 ULONG AllocateMisses;
2640 ULONG AllocateHits;
2641 } DUMMYUNIONNAME2;
2642 ULONG TotalFrees;
2643 union {
2644 ULONG FreeMisses;
2645 ULONG FreeHits;
2646 } DUMMYUNIONNAME3;
2647 POOL_TYPE Type;
2648 ULONG Tag;
2649 ULONG Size;
2650 union {
2651 PALLOCATE_FUNCTION_EX AllocateEx;
2652 PALLOCATE_FUNCTION Allocate;
2653 } DUMMYUNIONNAME4;
2654 union {
2655 PFREE_FUNCTION_EX FreeEx;
2656 PFREE_FUNCTION Free;
2657 } DUMMYUNIONNAME5;
2658 LIST_ENTRY ListEntry;
2659 ULONG LastTotalAllocates;
2660 union {
2661 ULONG LastAllocateMisses;
2662 ULONG LastAllocateHits;
2663 } DUMMYUNIONNAME6;
2664 ULONG Future[2];
2665 } GENERAL_LOOKASIDE, *PGENERAL_LOOKASIDE;
2666
2667 typedef struct _PAGED_LOOKASIDE_LIST {
2668 GENERAL_LOOKASIDE L;
2669 #if !defined(_AMD64_) && !defined(_IA64_)
2670 FAST_MUTEX Lock__ObsoleteButDoNotDelete;
2671 #endif
2672 } PAGED_LOOKASIDE_LIST, *PPAGED_LOOKASIDE_LIST;
2673
2674 typedef struct LOOKASIDE_ALIGN _NPAGED_LOOKASIDE_LIST {
2675 GENERAL_LOOKASIDE L;
2676 #if !defined(_AMD64_) && !defined(_IA64_)
2677 KSPIN_LOCK Lock__ObsoleteButDoNotDelete;
2678 #endif
2679 } NPAGED_LOOKASIDE_LIST, *PNPAGED_LOOKASIDE_LIST;
2680
2681 //typedef struct _LOOKASIDE_LIST_EX {
2682 // GENERAL_LOOKASIDE_POOL L;
2683 //} LOOKASIDE_LIST_EX, *PLOOKASIDE_LIST_EX;
2684
2685 typedef struct _EX_RUNDOWN_REF {
2686 __GNU_EXTENSION union {
2687 volatile ULONG_PTR Count;
2688 volatile PVOID Ptr;
2689 };
2690 } EX_RUNDOWN_REF, *PEX_RUNDOWN_REF;
2691
2692 typedef struct _EX_RUNDOWN_REF_CACHE_AWARE *PEX_RUNDOWN_REF_CACHE_AWARE;
2693
2694 typedef enum _WORK_QUEUE_TYPE {
2695 CriticalWorkQueue,
2696 DelayedWorkQueue,
2697 HyperCriticalWorkQueue,
2698 MaximumWorkQueue
2699 } WORK_QUEUE_TYPE;
2700
2701 typedef VOID
2702 (DDKAPI *PWORKER_THREAD_ROUTINE)(
2703 IN PVOID Parameter);
2704
2705 typedef struct _WORK_QUEUE_ITEM {
2706 LIST_ENTRY List;
2707 PWORKER_THREAD_ROUTINE WorkerRoutine;
2708 volatile PVOID Parameter;
2709 } WORK_QUEUE_ITEM, *PWORK_QUEUE_ITEM;
2710
2711
2712 /******************************************************************************
2713 * Executive Functions *
2714 ******************************************************************************/
2715
2716 #if defined(_X86_)
2717 #if defined(_NTHAL_)
2718 #define ExAcquireFastMutex ExiAcquireFastMutex
2719 #define ExReleaseFastMutex ExiReleaseFastMutex
2720 #define ExTryToAcquireFastMutex ExiTryToAcquireFastMutex
2721 #endif
2722 #define ExInterlockedAddUlong ExfInterlockedAddUlong
2723 #define ExInterlockedInsertHeadList ExfInterlockedInsertHeadList
2724 #define ExInterlockedInsertTailList ExfInterlockedInsertTailList
2725 #define ExInterlockedRemoveHeadList ExfInterlockedRemoveHeadList
2726 #define ExInterlockedPopEntryList ExfInterlockedPopEntryList
2727 #define ExInterlockedPushEntryList ExfInterlockedPushEntryList
2728 #endif
2729
2730 #if defined(_WIN64)
2731
2732 #if defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || \
2733 defined(_NTHAL_) || defined(_NTOSP_)
2734 NTKERNELAPI
2735 USHORT
2736 ExQueryDepthSList(IN PSLIST_HEADER ListHead);
2737 #else
2738 FORCEINLINE
2739 USHORT
2740 ExQueryDepthSList(IN PSLIST_HEADER ListHead)
2741 {
2742 return (USHORT)(ListHead->Alignment & 0xffff);
2743 }
2744 #endif
2745
2746 NTKERNELAPI
2747 PSLIST_ENTRY
2748 ExpInterlockedFlushSList(
2749 PSLIST_HEADER ListHead);
2750
2751 NTKERNELAPI
2752 PSLIST_ENTRY
2753 ExpInterlockedPopEntrySList(
2754 PSLIST_HEADER ListHead);
2755
2756 NTKERNELAPI
2757 PSLIST_ENTRY
2758 ExpInterlockedPushEntrySList(
2759 PSLIST_HEADER ListHead,
2760 PSLIST_ENTRY ListEntry);
2761
2762 #define ExInterlockedFlushSList(Head) \
2763 ExpInterlockedFlushSList(Head)
2764 #define ExInterlockedPopEntrySList(Head, Lock) \
2765 ExpInterlockedPopEntrySList(Head)
2766 #define ExInterlockedPushEntrySList(Head, Entry, Lock) \
2767 ExpInterlockedPushEntrySList(Head, Entry)
2768
2769 #else // !defined(_WIN64)
2770
2771 #define ExQueryDepthSList(listhead) (listhead)->Depth
2772
2773 NTKERNELAPI
2774 PSINGLE_LIST_ENTRY
2775 FASTCALL
2776 ExInterlockedFlushSList(
2777 IN PSLIST_HEADER ListHead);
2778
2779 #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
2780 NTKERNELAPI
2781 PSINGLE_LIST_ENTRY
2782 FASTCALL
2783 ExInterlockedPopEntrySList(
2784 IN PSLIST_HEADER ListHead,
2785 IN PKSPIN_LOCK Lock);
2786
2787 NTKERNELAPI
2788 PSINGLE_LIST_ENTRY
2789 FASTCALL
2790 ExInterlockedPushEntrySList(
2791 IN PSLIST_HEADER ListHead,
2792 IN PSINGLE_LIST_ENTRY ListEntry,
2793 IN PKSPIN_LOCK Lock);
2794 #else
2795 #define ExInterlockedPopEntrySList(_ListHead, _Lock) \
2796 InterlockedPopEntrySList(_ListHead)
2797 #define ExInterlockedPushEntrySList(_ListHead, _ListEntry, _Lock) \
2798 InterlockedPushEntrySList(_ListHead, _ListEntry)
2799 #endif // _WIN2K_COMPAT_SLIST_USAGE
2800
2801 #endif // !defined(_WIN64)
2802
2803 /* ERESOURCE_THREAD
2804 * ExGetCurrentResourceThread(
2805 * VOID);
2806 */
2807 #define ExGetCurrentResourceThread() ((ERESOURCE_THREAD)PsGetCurrentThread())
2808
2809 #define ExReleaseResource(R) (ExReleaseResourceLite(R))
2810
2811 /* VOID
2812 * ExInitializeWorkItem(
2813 * IN PWORK_QUEUE_ITEM Item,
2814 * IN PWORKER_THREAD_ROUTINE Routine,
2815 * IN PVOID Context)
2816 */
2817 #define ExInitializeWorkItem(Item, Routine, Context) \
2818 { \
2819 (Item)->WorkerRoutine = Routine; \
2820 (Item)->Parameter = Context; \
2821 (Item)->List.Flink = NULL; \
2822 }
2823
2824 #if (NTDDI_VERSION >= NTDDI_WIN2K)
2825
2826 NTKERNELAPI
2827 VOID
2828 FASTCALL
2829 ExAcquireFastMutex(
2830 IN OUT PFAST_MUTEX FastMutex);
2831
2832 NTKERNELAPI
2833 VOID
2834 FASTCALL
2835 ExReleaseFastMutex(
2836 IN OUT PFAST_MUTEX FastMutex);
2837
2838 NTKERNELAPI
2839 BOOLEAN
2840 FASTCALL
2841 ExTryToAcquireFastMutex(
2842 IN OUT PFAST_MUTEX FastMutex);
2843
2844 NTKERNELAPI
2845 VOID
2846 FASTCALL
2847 ExAcquireFastMutexUnsafe(
2848 IN OUT PFAST_MUTEX FastMutex);
2849
2850 NTKERNELAPI
2851 VOID
2852 FASTCALL
2853 ExReleaseFastMutexUnsafe(
2854 IN OUT PFAST_MUTEX FastMutex);
2855
2856 NTKERNELAPI
2857 BOOLEAN
2858 NTAPI
2859 ExAcquireResourceExclusiveLite(
2860 IN PERESOURCE Resource,
2861 IN BOOLEAN Wait);
2862
2863 NTKERNELAPI
2864 BOOLEAN
2865 NTAPI
2866 ExAcquireResourceSharedLite(
2867 IN PERESOURCE Resource,
2868 IN BOOLEAN Wait);
2869
2870 NTKERNELAPI
2871 BOOLEAN
2872 NTAPI
2873 ExAcquireSharedStarveExclusive(
2874 IN PERESOURCE Resource,
2875 IN BOOLEAN Wait);
2876
2877 NTKERNELAPI
2878 BOOLEAN
2879 NTAPI
2880 ExAcquireSharedWaitForExclusive(
2881 IN PERESOURCE Resource,
2882 IN BOOLEAN Wait);
2883
2884 NTKERNELAPI
2885 PVOID
2886 NTAPI
2887 ExAllocatePool(
2888 IN POOL_TYPE PoolType,
2889 IN SIZE_T NumberOfBytes);
2890
2891 #ifdef POOL_TAGGING
2892 #define ExAllocatePool(p,n) ExAllocatePoolWithTag(p,n,' kdD')
2893 #endif /* POOL_TAGGING */
2894
2895 NTKERNELAPI
2896 PVOID
2897 NTAPI
2898 ExAllocatePoolWithQuota(
2899 IN POOL_TYPE PoolType,
2900 IN SIZE_T NumberOfBytes);
2901
2902 #ifdef POOL_TAGGING
2903 #define ExAllocatePoolWithQuota(p,n) ExAllocatePoolWithQuotaTag(p,n,' kdD')
2904 #endif /* POOL_TAGGING */
2905
2906 NTKERNELAPI
2907 PVOID
2908 NTAPI
2909 ExAllocatePoolWithQuotaTag(
2910 IN POOL_TYPE PoolType,
2911 IN SIZE_T NumberOfBytes,
2912 IN ULONG Tag);
2913
2914 #ifndef POOL_TAGGING
2915 #define ExAllocatePoolWithQuotaTag(a,b,c) ExAllocatePoolWithQuota(a,b)
2916 #endif /* POOL_TAGGING */
2917
2918 NTKERNELAPI
2919 PVOID
2920 NTAPI
2921 ExAllocatePoolWithTag(
2922 IN POOL_TYPE PoolType,
2923 IN SIZE_T NumberOfBytes,
2924 IN ULONG Tag);
2925
2926 NTKERNELAPI
2927 PVOID
2928 NTAPI
2929 ExAllocatePoolWithTagPriority(
2930 IN POOL_TYPE PoolType,
2931 IN SIZE_T NumberOfBytes,
2932 IN ULONG Tag,
2933 IN EX_POOL_PRIORITY Priority);
2934
2935 NTKERNELAPI
2936 VOID
2937 NTAPI
2938 ExConvertExclusiveToSharedLite(
2939 IN PERESOURCE Resource);
2940
2941 NTKERNELAPI
2942 NTSTATUS
2943 NTAPI
2944 ExCreateCallback(
2945 OUT PCALLBACK_OBJECT *CallbackObject,
2946 IN POBJECT_ATTRIBUTES ObjectAttributes,
2947 IN BOOLEAN Create,
2948 IN BOOLEAN AllowMultipleCallbacks);
2949
2950 NTKERNELAPI
2951 VOID
2952 NTAPI
2953 ExDeleteNPagedLookasideList(
2954 IN PNPAGED_LOOKASIDE_LIST Lookaside);
2955
2956 NTKERNELAPI
2957 VOID
2958 NTAPI
2959 ExDeletePagedLookasideList(
2960 IN PPAGED_LOOKASIDE_LIST Lookaside);
2961
2962 NTKERNELAPI
2963 NTSTATUS
2964 NTAPI
2965 ExDeleteResourceLite(
2966 IN PERESOURCE Resource);
2967
2968 NTKERNELAPI
2969 VOID
2970 NTAPI
2971 ExFreePool(
2972 IN PVOID P);
2973
2974 #ifdef POOL_TAGGING
2975 #define ExFreePool(P) ExFreePoolWithTag(P, 0)
2976 #endif
2977
2978 NTKERNELAPI
2979 VOID
2980 NTAPI
2981 ExFreePoolWithTag(
2982 IN PVOID P,
2983 IN ULONG Tag);
2984
2985 NTKERNELAPI
2986 ULONG
2987 NTAPI
2988 ExGetExclusiveWaiterCount(
2989 IN PERESOURCE Resource);
2990
2991 NTKERNELAPI
2992 KPROCESSOR_MODE
2993 NTAPI
2994 ExGetPreviousMode(
2995 VOID);
2996
2997 NTKERNELAPI
2998 ULONG
2999 NTAPI
3000 ExGetSharedWaiterCount(
3001 IN PERESOURCE Resource);
3002
3003 NTKERNELAPI
3004 VOID
3005 NTAPI
3006 ExInitializeNPagedLookasideList(
3007 IN PNPAGED_LOOKASIDE_LIST Lookaside,
3008 IN PALLOCATE_FUNCTION Allocate OPTIONAL,
3009 IN PFREE_FUNCTION Free OPTIONAL,
3010 IN ULONG Flags,
3011 IN SIZE_T Size,
3012 IN ULONG Tag,
3013 IN USHORT Depth);
3014
3015 NTKERNELAPI
3016 VOID
3017 NTAPI
3018 ExInitializePagedLookasideList(
3019 IN PPAGED_LOOKASIDE_LIST Lookaside,
3020 IN PALLOCATE_FUNCTION Allocate OPTIONAL,
3021 IN PFREE_FUNCTION Free OPTIONAL,
3022 IN ULONG Flags,
3023 IN SIZE_T Size,
3024 IN ULONG Tag,
3025 IN USHORT Depth);
3026
3027 NTKERNELAPI
3028 NTSTATUS
3029 NTAPI
3030 ExInitializeResourceLite(
3031 IN PERESOURCE Resource);
3032
3033 NTKERNELAPI
3034 LARGE_INTEGER
3035 NTAPI
3036 ExInterlockedAddLargeInteger(
3037 IN PLARGE_INTEGER Addend,
3038 IN LARGE_INTEGER Increment,
3039 IN PKSPIN_LOCK Lock);
3040
3041 #if defined(_WIN64)
3042 #define ExInterlockedAddLargeStatistic(Addend, Increment) \
3043 (VOID)InterlockedAdd64(&(Addend)->QuadPart, Increment)
3044 #else
3045 #define ExInterlockedAddLargeStatistic(Addend, Increment) \
3046 _InterlockedAddLargeStatistic((PLONGLONG)&(Addend)->QuadPart, Increment)
3047 #endif
3048
3049 NTKERNELAPI
3050 ULONG
3051 FASTCALL
3052 ExInterlockedAddUlong(
3053 IN PULONG Addend,
3054 IN ULONG Increment,
3055 PKSPIN_LOCK Lock);
3056
3057 #if defined(_AMD64_) || defined(_IA64_)
3058 #define ExInterlockedCompareExchange64(Destination, Exchange, Comperand, Lock) \
3059 InterlockedCompareExchange64(Destination, *(Exchange), *(Comperand))
3060 #elif defined(_X86_)
3061 NTKERNELAPI
3062 LONGLONG
3063 FASTCALL
3064 ExfInterlockedCompareExchange64(
3065 IN OUT LONGLONG volatile *Destination,
3066 IN PLONGLONG Exchange,
3067 IN PLONGLONG Comperand);
3068 #define ExInterlockedCompareExchange64(Destination, Exchange, Comperand, Lock) \
3069 ExfInterlockedCompareExchange64(Destination, Exchange, Comperand)
3070 #else
3071 NTKERNELAPI
3072 LONGLONG
3073 FASTCALL
3074 ExInterlockedCompareExchange64(
3075 IN OUT LONGLONG volatile *Destination,
3076 IN PLONGLONG Exchange,
3077 IN PLONGLONG Comparand,
3078 IN PKSPIN_LOCK Lock);
3079 #endif
3080
3081 NTKERNELAPI
3082 PLIST_ENTRY
3083 FASTCALL
3084 ExInterlockedInsertHeadList(
3085 IN PLIST_ENTRY ListHead,
3086 IN PLIST_ENTRY ListEntry,
3087 IN PKSPIN_LOCK Lock);
3088
3089 NTKERNELAPI
3090 PLIST_ENTRY
3091 FASTCALL
3092 ExInterlockedInsertTailList(
3093 IN PLIST_ENTRY ListHead,
3094 IN PLIST_ENTRY ListEntry,
3095 IN PKSPIN_LOCK Lock);
3096
3097 NTKERNELAPI
3098 PSINGLE_LIST_ENTRY
3099 FASTCALL
3100 ExInterlockedPopEntryList(
3101 IN PSINGLE_LIST_ENTRY ListHead,
3102 IN PKSPIN_LOCK Lock);
3103
3104 NTKERNELAPI
3105 PSINGLE_LIST_ENTRY
3106 FASTCALL
3107 ExInterlockedPushEntryList(
3108 IN PSINGLE_LIST_ENTRY ListHead,
3109 IN PSINGLE_LIST_ENTRY ListEntry,
3110 IN PKSPIN_LOCK Lock);
3111
3112 NTKERNELAPI
3113 PLIST_ENTRY
3114 FASTCALL
3115 ExInterlockedRemoveHeadList(
3116 IN PLIST_ENTRY ListHead,
3117 IN PKSPIN_LOCK Lock);
3118
3119 NTKERNELAPI
3120 BOOLEAN
3121 NTAPI
3122 ExIsProcessorFeaturePresent(
3123 IN ULONG ProcessorFeature);
3124
3125 NTKERNELAPI
3126 BOOLEAN
3127 NTAPI
3128 ExIsResourceAcquiredExclusiveLite(
3129 IN PERESOURCE Resource);
3130
3131 NTKERNELAPI
3132 ULONG
3133 NTAPI
3134 ExIsResourceAcquiredSharedLite(
3135 IN PERESOURCE Resource);
3136
3137 #define ExIsResourceAcquiredLite ExIsResourceAcquiredSharedLite
3138
3139 NTKERNELAPI
3140 VOID
3141 NTAPI
3142 ExLocalTimeToSystemTime(
3143 IN PLARGE_INTEGER LocalTime,
3144 OUT PLARGE_INTEGER SystemTime);
3145
3146 NTKERNELAPI
3147 VOID
3148 NTAPI
3149 ExNotifyCallback(
3150 IN PCALLBACK_OBJECT CallbackObject,
3151 IN PVOID Argument1,
3152 IN PVOID Argument2);
3153
3154 NTKERNELAPI
3155 VOID
3156 NTAPI
3157 ExQueueWorkItem(
3158 IN PWORK_QUEUE_ITEM WorkItem,
3159 IN WORK_QUEUE_TYPE QueueType);
3160
3161 NTKERNELAPI
3162 DECLSPEC_NORETURN
3163 VOID
3164 NTAPI
3165 ExRaiseStatus(
3166 IN NTSTATUS Status);
3167
3168 NTKERNELAPI
3169 PVOID
3170 NTAPI
3171 ExRegisterCallback(
3172 IN PCALLBACK_OBJECT CallbackObject,
3173 IN PCALLBACK_FUNCTION CallbackFunction,
3174 IN PVOID CallbackContext);
3175
3176 NTKERNELAPI
3177 NTSTATUS
3178 NTAPI
3179 ExReinitializeResourceLite(
3180 IN PERESOURCE Resource);
3181
3182 NTKERNELAPI
3183 VOID
3184 NTAPI
3185 ExReleaseResourceForThreadLite(
3186 IN PERESOURCE Resource,
3187 IN ERESOURCE_THREAD ResourceThreadId);
3188
3189 NTKERNELAPI
3190 VOID
3191 FASTCALL
3192 ExReleaseResourceLite(
3193 IN PERESOURCE Resource);
3194
3195 NTKERNELAPI
3196 VOID
3197 NTAPI
3198 ExSetResourceOwnerPointer(
3199 IN PERESOURCE Resource,
3200 IN PVOID OwnerPointer);
3201
3202 NTKERNELAPI
3203 ULONG
3204 NTAPI
3205 ExSetTimerResolution(
3206 IN ULONG DesiredTime,
3207 IN BOOLEAN SetResolution);
3208
3209 NTKERNELAPI
3210 VOID
3211 NTAPI
3212 ExSystemTimeToLocalTime(
3213 IN PLARGE_INTEGER SystemTime,
3214 OUT PLARGE_INTEGER LocalTime);
3215
3216 NTKERNELAPI
3217 VOID
3218 NTAPI
3219 ExUnregisterCallback(
3220 IN PVOID CbRegistration);
3221
3222
3223 #endif // (NTDDI_VERSION >= NTDDI_WIN2K)
3224
3225 #if (NTDDI_VERSION >= NTDDI_WINXP)
3226 NTKERNELAPI
3227 BOOLEAN
3228 FASTCALL
3229 ExAcquireRundownProtection(
3230 IN OUT PEX_RUNDOWN_REF RunRef);
3231
3232 NTKERNELAPI
3233 VOID
3234 FASTCALL
3235 ExInitializeRundownProtection(
3236 OUT PEX_RUNDOWN_REF RunRef);
3237
3238 NTKERNELAPI
3239 VOID
3240 FASTCALL
3241 ExReInitializeRundownProtection(
3242 OUT PEX_RUNDOWN_REF RunRef);
3243
3244 NTKERNELAPI
3245 VOID
3246 FASTCALL
3247 ExReleaseRundownProtection(
3248 IN OUT PEX_RUNDOWN_REF RunRef);
3249
3250 NTKERNELAPI
3251 VOID
3252 FASTCALL
3253 ExRundownCompleted(
3254 OUT PEX_RUNDOWN_REF RunRef);
3255
3256 NTKERNELAPI
3257 BOOLEAN
3258 NTAPI
3259 ExVerifySuite(
3260 IN SUITE_TYPE SuiteType);
3261
3262 NTKERNELAPI
3263 VOID
3264 FASTCALL
3265 ExWaitForRundownProtectionRelease(
3266 IN OUT PEX_RUNDOWN_REF RunRef);
3267
3268 #endif // (NTDDI_VERSION >= NTDDI_WINXP)
3269
3270 #if (NTDDI_VERSION >= NTDDI_WINXPSP2)
3271 NTKERNELAPI
3272 BOOLEAN
3273 FASTCALL
3274 ExAcquireRundownProtectionEx(
3275 IN OUT PEX_RUNDOWN_REF RunRef,
3276 IN ULONG Count);
3277
3278 NTKERNELAPI
3279 VOID
3280 FASTCALL
3281 ExReleaseRundownProtectionEx(
3282 IN OUT PEX_RUNDOWN_REF RunRef,
3283 IN ULONG Count);
3284 #endif // (NTDDI_VERSION >= NTDDI_WINXPSP2)
3285
3286 #if (NTDDI_VERSION >= NTDDI_WS03)
3287
3288 #endif // (NTDDI_VERSION >= NTDDI_WS03)
3289
3290 #if (NTDDI_VERSION >= NTDDI_WS03SP1)
3291 NTKERNELAPI
3292 PEX_RUNDOWN_REF_CACHE_AWARE
3293 ExAllocateCacheAwareRundownProtection(
3294 IN POOL_TYPE PoolType,
3295 IN ULONG PoolTag);
3296
3297 NTKERNELAPI
3298 SIZE_T
3299 ExSizeOfRundownProtectionCacheAware(VOID);
3300
3301 #endif // (NTDDI_VERSION >= NTDDI_WS03SP1)
3302
3303 #if (NTDDI_VERSION >= NTDDI_VISTA)
3304 NTKERNELAPI
3305 NTSTATUS
3306 ExInitializeLookasideListEx(
3307 OUT PLOOKASIDE_LIST_EX Lookaside,
3308 IN PALLOCATE_FUNCTION_EX Allocate OPTIONAL,
3309 IN PFREE_FUNCTION_EX Free OPTIONAL,
3310 IN POOL_TYPE PoolType,
3311 IN ULONG Flags,
3312 IN SIZE_T Size,
3313 IN ULONG Tag,
3314 IN USHORT Depth);
3315 #endif
3316
3317
3318 #if !defined(MIDL_PASS)
3319
3320 static __inline PVOID
3321 ExAllocateFromNPagedLookasideList(
3322 IN PNPAGED_LOOKASIDE_LIST Lookaside)
3323 {
3324 PVOID Entry;
3325
3326 Lookaside->L.TotalAllocates++;
3327 Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
3328 if (Entry == NULL) {
3329 Lookaside->L.AllocateMisses++;
3330 Entry = (Lookaside->L.Allocate)(Lookaside->L.Type,
3331 Lookaside->L.Size,
3332 Lookaside->L.Tag);
3333 }
3334 return Entry;
3335 }
3336
3337 static __inline PVOID
3338 ExAllocateFromPagedLookasideList(
3339 IN PPAGED_LOOKASIDE_LIST Lookaside)
3340 {
3341 PVOID Entry;
3342
3343 Lookaside->L.TotalAllocates++;
3344 Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
3345 if (Entry == NULL) {
3346 Lookaside->L.AllocateMisses++;
3347 Entry = (Lookaside->L.Allocate)(Lookaside->L.Type,
3348 Lookaside->L.Size,
3349 Lookaside->L.Tag);
3350 }
3351 return Entry;
3352 }
3353
3354 static __inline VOID
3355 ExFreeToNPagedLookasideList(
3356 IN PNPAGED_LOOKASIDE_LIST Lookaside,
3357 IN PVOID Entry)
3358 {
3359 Lookaside->L.TotalFrees++;
3360 if (ExQueryDepthSList(&Lookaside->L.ListHead) >= Lookaside->L.Depth) {
3361 Lookaside->L.FreeMisses++;
3362 (Lookaside->L.Free)(Entry);
3363 } else {
3364 InterlockedPushEntrySList(&Lookaside->L.ListHead, (PSLIST_ENTRY)Entry);
3365 }
3366 }
3367
3368 static __inline VOID
3369 ExFreeToPagedLookasideList(
3370 IN PPAGED_LOOKASIDE_LIST Lookaside,
3371 IN PVOID Entry)
3372 {
3373 Lookaside->L.TotalFrees++;
3374 if (ExQueryDepthSList(&Lookaside->L.ListHead) >= Lookaside->L.Depth) {
3375 Lookaside->L.FreeMisses++;
3376 (Lookaside->L.Free)(Entry);
3377 } else {
3378 InterlockedPushEntrySList(&Lookaside->L.ListHead, (PSLIST_ENTRY)Entry);
3379 }
3380 }
3381
3382
3383 #endif // !defined(MIDL_PASS)
3384
3385
3386 #ifdef __cplusplus
3387 }
3388 #endif
3389
3390 #endif // _WDMDDK_