2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: ntoskrnl/ex/sysinfo.c
5 * PURPOSE: System information functions
7 * PROGRAMMERS: David Welch (welch@mcmail.com)
8 * Aleksey Bragin (aleksey@reactos.org)
11 /* INCLUDES *****************************************************************/
17 /* The maximum size of an environment value (in bytes) */
18 #define MAX_ENVVAL_SIZE 1024
20 extern LIST_ENTRY HandleTableListHead
;
21 extern EX_PUSH_LOCK HandleTableListLock
;
23 FAST_MUTEX ExpEnvironmentLock
;
24 ERESOURCE ExpFirmwareTableResource
;
25 LIST_ENTRY ExpFirmwareTableProviderListHead
;
29 ExpConvertLdrModuleToRtlModule(IN ULONG ModuleCount
,
30 IN PLDR_DATA_TABLE_ENTRY LdrEntry
,
31 OUT PRTL_PROCESS_MODULE_INFORMATION ModuleInfo
)
35 ANSI_STRING ModuleName
;
38 ModuleInfo
->MappedBase
= NULL
;
39 ModuleInfo
->ImageBase
= LdrEntry
->DllBase
;
40 ModuleInfo
->ImageSize
= LdrEntry
->SizeOfImage
;
41 ModuleInfo
->Flags
= LdrEntry
->Flags
;
42 ModuleInfo
->LoadCount
= LdrEntry
->LoadCount
;
43 ModuleInfo
->LoadOrderIndex
= (USHORT
)ModuleCount
;
44 ModuleInfo
->InitOrderIndex
= 0;
47 RtlInitEmptyAnsiString(&ModuleName
,
48 ModuleInfo
->FullPathName
,
49 sizeof(ModuleInfo
->FullPathName
));
52 Status
= RtlUnicodeStringToAnsiString(&ModuleName
,
53 &LdrEntry
->FullDllName
,
55 if ((NT_SUCCESS(Status
)) || (Status
== STATUS_BUFFER_OVERFLOW
))
57 /* Calculate offset to name */
58 p
= ModuleName
.Buffer
+ ModuleName
.Length
;
59 while ((p
> ModuleName
.Buffer
) && (*--p
))
61 /* Check if we found the separator */
62 if (*p
== OBJ_NAME_PATH_SEPARATOR
)
64 /* We did, break out */
71 ModuleInfo
->OffsetToFileName
= (USHORT
)(p
- ModuleName
.Buffer
);
75 /* Return empty name */
76 ModuleInfo
->FullPathName
[0] = ANSI_NULL
;
77 ModuleInfo
->OffsetToFileName
= 0;
85 ExpQueryModuleInformation(IN PLIST_ENTRY KernelModeList
,
86 IN PLIST_ENTRY UserModeList
,
87 OUT PRTL_PROCESS_MODULES Modules
,
89 OUT PULONG ReturnLength
)
91 NTSTATUS Status
= STATUS_SUCCESS
;
93 PRTL_PROCESS_MODULE_INFORMATION ModuleInfo
;
94 PLDR_DATA_TABLE_ENTRY LdrEntry
;
95 ULONG ModuleCount
= 0;
96 PLIST_ENTRY NextEntry
;
99 RequiredLength
= FIELD_OFFSET(RTL_PROCESS_MODULES
, Modules
);
100 ModuleInfo
= &Modules
->Modules
[0];
102 /* Loop the kernel list */
103 NextEntry
= KernelModeList
->Flink
;
104 while (NextEntry
!= KernelModeList
)
107 LdrEntry
= CONTAINING_RECORD(NextEntry
,
108 LDR_DATA_TABLE_ENTRY
,
111 /* Update size and check if we can manage one more entry */
112 RequiredLength
+= sizeof(RTL_PROCESS_MODULE_INFORMATION
);
113 if (Length
>= RequiredLength
)
115 Status
= ExpConvertLdrModuleToRtlModule(ModuleCount
,
119 /* Go to the next module */
125 Status
= STATUS_INFO_LENGTH_MISMATCH
;
128 /* Update count and move to next entry */
130 NextEntry
= NextEntry
->Flink
;
133 /* Check if caller also wanted user modules */
136 NextEntry
= UserModeList
->Flink
;
137 while (NextEntry
!= UserModeList
)
140 LdrEntry
= CONTAINING_RECORD(NextEntry
,
141 LDR_DATA_TABLE_ENTRY
,
144 /* Update size and check if we can manage one more entry */
145 RequiredLength
+= sizeof(RTL_PROCESS_MODULE_INFORMATION
);
146 if (Length
>= RequiredLength
)
148 Status
= ExpConvertLdrModuleToRtlModule(ModuleCount
,
152 /* Go to the next module */
158 Status
= STATUS_INFO_LENGTH_MISMATCH
;
161 /* Update count and move to next entry */
163 NextEntry
= NextEntry
->Flink
;
167 /* Update return length */
168 if (ReturnLength
) *ReturnLength
= RequiredLength
;
170 /* Validate the length again */
171 if (Length
>= FIELD_OFFSET(RTL_PROCESS_MODULES
, Modules
))
173 /* Set the final count */
174 Modules
->NumberOfModules
= ModuleCount
;
178 /* Otherwise, we failed */
179 Status
= STATUS_INFO_LENGTH_MISMATCH
;
188 ExUnlockUserBuffer(PMDL Mdl
)
191 ExFreePoolWithTag(Mdl
, TAG_MDL
);
199 KPROCESSOR_MODE AccessMode
,
200 LOCK_OPERATION Operation
,
201 PVOID
*MappedSystemVa
,
207 *MappedSystemVa
= NULL
;
210 /* Allocate an MDL for the buffer */
211 Mdl
= IoAllocateMdl(BaseAddress
, Length
, FALSE
, TRUE
, NULL
);
214 return STATUS_INSUFFICIENT_RESOURCES
;
217 /* Enter SEH for probing */
220 MmProbeAndLockPages(Mdl
, AccessMode
, Operation
);
222 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
224 ExFreePoolWithTag(Mdl
, TAG_MDL
);
225 return _SEH2_GetExceptionCode();
229 /* Return the safe kernel mode buffer */
230 *MappedSystemVa
= MmGetSystemAddressForMdlSafe(Mdl
, NormalPagePriority
);
231 if (*MappedSystemVa
== NULL
)
233 ExUnlockUserBuffer(Mdl
);
234 return STATUS_INSUFFICIENT_RESOURCES
;
239 return STATUS_SUCCESS
;
242 /* FUNCTIONS *****************************************************************/
249 ExGetCurrentProcessorCpuUsage(PULONG CpuUsage
)
253 ULONGLONG ScaledIdle
;
255 Prcb
= KeGetCurrentPrcb();
257 ScaledIdle
= (ULONGLONG
)Prcb
->IdleThread
->KernelTime
* 100;
258 TotalTime
= Prcb
->KernelTime
+ Prcb
->UserTime
;
260 *CpuUsage
= (ULONG
)(100 - (ScaledIdle
/ TotalTime
));
270 ExGetCurrentProcessorCounts(PULONG ThreadKernelTime
,
272 PULONG ProcessorNumber
)
276 Prcb
= KeGetCurrentPrcb();
278 *ThreadKernelTime
= Prcb
->KernelTime
+ Prcb
->UserTime
;
279 *TotalCpuTime
= Prcb
->CurrentThread
->KernelTime
;
280 *ProcessorNumber
= KeGetCurrentProcessorNumber();
288 ExIsProcessorFeaturePresent(IN ULONG ProcessorFeature
)
290 /* Quick check to see if it exists at all */
291 if (ProcessorFeature
>= PROCESSOR_FEATURE_MAX
) return(FALSE
);
293 /* Return our support for it */
294 return(SharedUserData
->ProcessorFeatures
[ProcessorFeature
]);
302 ExVerifySuite(SUITE_TYPE SuiteType
)
304 if (SuiteType
== Personal
) return TRUE
;
310 NtQuerySystemEnvironmentValue(IN PUNICODE_STRING VariableName
,
311 OUT PWSTR ValueBuffer
,
312 IN ULONG ValueBufferLength
,
313 IN OUT PULONG ReturnLength OPTIONAL
)
316 UNICODE_STRING WName
;
320 UNICODE_STRING WValue
;
321 KPROCESSOR_MODE PreviousMode
;
325 /* Check if the call came from user mode */
326 PreviousMode
= ExGetPreviousMode();
327 if (PreviousMode
!= KernelMode
)
331 /* Probe the input and output buffers */
332 ProbeForRead(VariableName
, sizeof(UNICODE_STRING
), sizeof(ULONG
));
333 ProbeForWrite(ValueBuffer
, ValueBufferLength
, sizeof(WCHAR
));
334 if (ReturnLength
!= NULL
) ProbeForWriteUlong(ReturnLength
);
336 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
338 /* Return the exception code */
339 _SEH2_YIELD(return _SEH2_GetExceptionCode());
344 /* According to NTInternals the SeSystemEnvironmentName privilege is required! */
345 if (!SeSinglePrivilegeCheck(SeSystemEnvironmentPrivilege
, PreviousMode
))
347 DPRINT1("NtQuerySystemEnvironmentValue: Caller requires the SeSystemEnvironmentPrivilege privilege!\n");
348 return STATUS_PRIVILEGE_NOT_HELD
;
351 /* Copy the name to kernel space if necessary */
352 Status
= ProbeAndCaptureUnicodeString(&WName
, PreviousMode
, VariableName
);
353 if (!NT_SUCCESS(Status
)) return Status
;
355 /* Convert the name to ANSI and release the captured UNICODE string */
356 Status
= RtlUnicodeStringToAnsiString(&AName
, &WName
, TRUE
);
357 ReleaseCapturedUnicodeString(&WName
, PreviousMode
);
358 if (!NT_SUCCESS(Status
)) return Status
;
360 /* Allocate a buffer for the ANSI environment variable */
361 AnsiValueBuffer
= ExAllocatePoolWithTag(NonPagedPool
, MAX_ENVVAL_SIZE
, 'rvnE');
362 if (AnsiValueBuffer
== NULL
)
364 RtlFreeAnsiString(&AName
);
365 return STATUS_INSUFFICIENT_RESOURCES
;
368 /* Get the environment variable and free the ANSI name */
369 Result
= HalGetEnvironmentVariable(AName
.Buffer
,
372 RtlFreeAnsiString(&AName
);
374 /* Check if we had success */
375 if (Result
== ESUCCESS
)
377 /* Copy the result back to the caller. */
380 /* Initialize ANSI string from the result */
381 RtlInitAnsiString(&AValue
, AnsiValueBuffer
);
383 /* Initialize a UNICODE string from the callers buffer */
384 RtlInitEmptyUnicodeString(&WValue
, ValueBuffer
, (USHORT
)ValueBufferLength
);
386 /* Convert the result to UNICODE */
387 Status
= RtlAnsiStringToUnicodeString(&WValue
, &AValue
, FALSE
);
389 if (ReturnLength
!= NULL
)
390 *ReturnLength
= WValue
.Length
;
392 _SEH2_EXCEPT(ExSystemExceptionFilter())
394 Status
= _SEH2_GetExceptionCode();
400 Status
= STATUS_UNSUCCESSFUL
;
403 /* Free the allocated ANSI value buffer */
404 ExFreePoolWithTag(AnsiValueBuffer
, 'rvnE');
412 NtSetSystemEnvironmentValue(IN PUNICODE_STRING VariableName
,
413 IN PUNICODE_STRING Value
)
415 UNICODE_STRING CapturedName
, CapturedValue
;
416 ANSI_STRING AName
, AValue
;
417 KPROCESSOR_MODE PreviousMode
;
422 PreviousMode
= ExGetPreviousMode();
425 * Copy the strings to kernel space if necessary
427 Status
= ProbeAndCaptureUnicodeString(&CapturedName
,
430 if (NT_SUCCESS(Status
))
432 Status
= ProbeAndCaptureUnicodeString(&CapturedValue
,
435 if (NT_SUCCESS(Status
))
438 * according to ntinternals the SeSystemEnvironmentName privilege is required!
440 if (SeSinglePrivilegeCheck(SeSystemEnvironmentPrivilege
,
444 * convert the strings to ANSI
446 Status
= RtlUnicodeStringToAnsiString(&AName
,
449 if (NT_SUCCESS(Status
))
451 Status
= RtlUnicodeStringToAnsiString(&AValue
,
454 if (NT_SUCCESS(Status
))
456 ARC_STATUS Result
= HalSetEnvironmentVariable(AName
.Buffer
,
459 Status
= (Result
? STATUS_SUCCESS
: STATUS_UNSUCCESSFUL
);
465 DPRINT1("NtSetSystemEnvironmentValue: Caller requires the SeSystemEnvironmentPrivilege privilege!\n");
466 Status
= STATUS_PRIVILEGE_NOT_HELD
;
469 ReleaseCapturedUnicodeString(&CapturedValue
,
473 ReleaseCapturedUnicodeString(&CapturedName
,
482 NtEnumerateSystemEnvironmentValuesEx(IN ULONG InformationClass
,
484 IN ULONG BufferLength
)
487 return STATUS_NOT_IMPLEMENTED
;
492 NtQuerySystemEnvironmentValueEx(IN PUNICODE_STRING VariableName
,
493 IN LPGUID VendorGuid
,
495 IN OUT PULONG ReturnLength
,
496 IN OUT PULONG Attributes
)
499 return STATUS_NOT_IMPLEMENTED
;
504 NtSetSystemEnvironmentValueEx(IN PUNICODE_STRING VariableName
,
505 IN LPGUID VendorGuid
,
507 IN OUT PULONG ReturnLength
,
508 IN OUT PULONG Attributes
)
511 return STATUS_NOT_IMPLEMENTED
;
514 /* --- Query/Set System Information --- */
517 * NOTE: QSI_DEF(n) and SSI_DEF(n) define _cdecl function symbols
518 * so the stack is popped only in one place on x86 platform.
520 #define QSI_USE(n) QSI##n
522 static NTSTATUS QSI_USE(n) (PVOID Buffer, ULONG Size, PULONG ReqSize)
524 #define SSI_USE(n) SSI##n
526 static NTSTATUS SSI_USE(n) (PVOID Buffer, ULONG Size)
530 ExQueryPoolUsage(OUT PULONG PagedPoolPages
,
531 OUT PULONG NonPagedPoolPages
,
532 OUT PULONG PagedPoolAllocs
,
533 OUT PULONG PagedPoolFrees
,
534 OUT PULONG PagedPoolLookasideHits
,
535 OUT PULONG NonPagedPoolAllocs
,
536 OUT PULONG NonPagedPoolFrees
,
537 OUT PULONG NonPagedPoolLookasideHits
);
539 /* Class 0 - Basic Information */
540 QSI_DEF(SystemBasicInformation
)
542 PSYSTEM_BASIC_INFORMATION Sbi
543 = (PSYSTEM_BASIC_INFORMATION
) Buffer
;
545 *ReqSize
= sizeof(SYSTEM_BASIC_INFORMATION
);
547 /* Check user buffer's size */
548 if (Size
!= sizeof(SYSTEM_BASIC_INFORMATION
))
550 return STATUS_INFO_LENGTH_MISMATCH
;
553 RtlZeroMemory(Sbi
, Size
);
555 Sbi
->TimerResolution
= KeMaximumIncrement
;
556 Sbi
->PageSize
= PAGE_SIZE
;
557 Sbi
->NumberOfPhysicalPages
= MmNumberOfPhysicalPages
;
558 Sbi
->LowestPhysicalPageNumber
= (ULONG
)MmLowestPhysicalPage
;
559 Sbi
->HighestPhysicalPageNumber
= (ULONG
)MmHighestPhysicalPage
;
560 Sbi
->AllocationGranularity
= MM_VIRTMEM_GRANULARITY
; /* hard coded on Intel? */
561 Sbi
->MinimumUserModeAddress
= 0x10000; /* Top of 64k */
562 Sbi
->MaximumUserModeAddress
= (ULONG_PTR
)MmHighestUserAddress
;
563 Sbi
->ActiveProcessorsAffinityMask
= KeActiveProcessors
;
564 Sbi
->NumberOfProcessors
= KeNumberProcessors
;
566 return STATUS_SUCCESS
;
569 /* Class 1 - Processor Information */
570 QSI_DEF(SystemProcessorInformation
)
572 PSYSTEM_PROCESSOR_INFORMATION Spi
573 = (PSYSTEM_PROCESSOR_INFORMATION
) Buffer
;
575 *ReqSize
= sizeof(SYSTEM_PROCESSOR_INFORMATION
);
577 /* Check user buffer's size */
578 if (Size
< sizeof(SYSTEM_PROCESSOR_INFORMATION
))
580 return STATUS_INFO_LENGTH_MISMATCH
;
582 Spi
->ProcessorArchitecture
= KeProcessorArchitecture
;
583 Spi
->ProcessorLevel
= KeProcessorLevel
;
584 Spi
->ProcessorRevision
= KeProcessorRevision
;
586 Spi
->ProcessorFeatureBits
= KeFeatureBits
;
588 DPRINT("Arch %u Level %u Rev 0x%x\n", Spi
->ProcessorArchitecture
,
589 Spi
->ProcessorLevel
, Spi
->ProcessorRevision
);
591 return STATUS_SUCCESS
;
594 /* Class 2 - Performance Information */
595 QSI_DEF(SystemPerformanceInformation
)
597 ULONG IdleUser
, IdleKernel
;
598 PSYSTEM_PERFORMANCE_INFORMATION Spi
599 = (PSYSTEM_PERFORMANCE_INFORMATION
) Buffer
;
601 PEPROCESS TheIdleProcess
;
603 *ReqSize
= sizeof(SYSTEM_PERFORMANCE_INFORMATION
);
605 /* Check user buffer's size */
606 if (Size
< sizeof(SYSTEM_PERFORMANCE_INFORMATION
))
608 return STATUS_INFO_LENGTH_MISMATCH
;
611 TheIdleProcess
= PsIdleProcess
;
613 IdleKernel
= KeQueryRuntimeProcess(&TheIdleProcess
->Pcb
, &IdleUser
);
614 Spi
->IdleProcessTime
.QuadPart
= UInt32x32To64(IdleKernel
, KeMaximumIncrement
);
615 Spi
->IoReadTransferCount
= IoReadTransferCount
;
616 Spi
->IoWriteTransferCount
= IoWriteTransferCount
;
617 Spi
->IoOtherTransferCount
= IoOtherTransferCount
;
618 Spi
->IoReadOperationCount
= IoReadOperationCount
;
619 Spi
->IoWriteOperationCount
= IoWriteOperationCount
;
620 Spi
->IoOtherOperationCount
= IoOtherOperationCount
;
622 Spi
->AvailablePages
= (ULONG
)MmAvailablePages
;
624 * Add up all the used "Committed" memory + pagefile.
625 * Not sure this is right. 8^\
627 Spi
->CommittedPages
= MiMemoryConsumers
[MC_SYSTEM
].PagesUsed
+
628 MiMemoryConsumers
[MC_CACHE
].PagesUsed
+
629 MiMemoryConsumers
[MC_USER
].PagesUsed
+
632 * Add up the full system total + pagefile.
633 * All this make Taskmgr happy but not sure it is the right numbers.
634 * This too, fixes some of GlobalMemoryStatusEx numbers.
636 Spi
->CommitLimit
= MmNumberOfPhysicalPages
+ MiFreeSwapPages
+ MiUsedSwapPages
;
638 Spi
->PeakCommitment
= 0; /* FIXME */
639 Spi
->PageFaultCount
= 0; /* FIXME */
640 Spi
->CopyOnWriteCount
= 0; /* FIXME */
641 Spi
->TransitionCount
= 0; /* FIXME */
642 Spi
->CacheTransitionCount
= 0; /* FIXME */
643 Spi
->DemandZeroCount
= 0; /* FIXME */
644 Spi
->PageReadCount
= 0; /* FIXME */
645 Spi
->PageReadIoCount
= 0; /* FIXME */
646 Spi
->CacheReadCount
= 0; /* FIXME */
647 Spi
->CacheIoCount
= 0; /* FIXME */
648 Spi
->DirtyPagesWriteCount
= 0; /* FIXME */
649 Spi
->DirtyWriteIoCount
= 0; /* FIXME */
650 Spi
->MappedPagesWriteCount
= 0; /* FIXME */
651 Spi
->MappedWriteIoCount
= 0; /* FIXME */
653 Spi
->PagedPoolPages
= 0;
654 Spi
->NonPagedPoolPages
= 0;
655 Spi
->PagedPoolAllocs
= 0;
656 Spi
->PagedPoolFrees
= 0;
657 Spi
->PagedPoolLookasideHits
= 0;
658 Spi
->NonPagedPoolAllocs
= 0;
659 Spi
->NonPagedPoolFrees
= 0;
660 Spi
->NonPagedPoolLookasideHits
= 0;
661 ExQueryPoolUsage(&Spi
->PagedPoolPages
,
662 &Spi
->NonPagedPoolPages
,
663 &Spi
->PagedPoolAllocs
,
664 &Spi
->PagedPoolFrees
,
665 &Spi
->PagedPoolLookasideHits
,
666 &Spi
->NonPagedPoolAllocs
,
667 &Spi
->NonPagedPoolFrees
,
668 &Spi
->NonPagedPoolLookasideHits
);
669 Spi
->FreeSystemPtes
= 0; /* FIXME */
671 Spi
->ResidentSystemCodePage
= 0; /* FIXME */
673 Spi
->TotalSystemDriverPages
= 0; /* FIXME */
674 Spi
->Spare3Count
= 0; /* FIXME */
676 Spi
->ResidentSystemCachePage
= MiMemoryConsumers
[MC_CACHE
].PagesUsed
;
677 Spi
->ResidentPagedPoolPage
= 0; /* FIXME */
679 Spi
->ResidentSystemDriverPage
= 0; /* FIXME */
680 Spi
->CcFastReadNoWait
= 0; /* FIXME */
681 Spi
->CcFastReadWait
= 0; /* FIXME */
682 Spi
->CcFastReadResourceMiss
= 0; /* FIXME */
683 Spi
->CcFastReadNotPossible
= 0; /* FIXME */
685 Spi
->CcFastMdlReadNoWait
= 0; /* FIXME */
686 Spi
->CcFastMdlReadWait
= 0; /* FIXME */
687 Spi
->CcFastMdlReadResourceMiss
= 0; /* FIXME */
688 Spi
->CcFastMdlReadNotPossible
= 0; /* FIXME */
690 Spi
->CcMapDataNoWait
= 0; /* FIXME */
691 Spi
->CcMapDataWait
= 0; /* FIXME */
692 Spi
->CcMapDataNoWaitMiss
= 0; /* FIXME */
693 Spi
->CcMapDataWaitMiss
= 0; /* FIXME */
695 Spi
->CcPinMappedDataCount
= 0; /* FIXME */
696 Spi
->CcPinReadNoWait
= 0; /* FIXME */
697 Spi
->CcPinReadWait
= 0; /* FIXME */
698 Spi
->CcPinReadNoWaitMiss
= 0; /* FIXME */
699 Spi
->CcPinReadWaitMiss
= 0; /* FIXME */
700 Spi
->CcCopyReadNoWait
= 0; /* FIXME */
701 Spi
->CcCopyReadWait
= 0; /* FIXME */
702 Spi
->CcCopyReadNoWaitMiss
= 0; /* FIXME */
703 Spi
->CcCopyReadWaitMiss
= 0; /* FIXME */
705 Spi
->CcMdlReadNoWait
= 0; /* FIXME */
706 Spi
->CcMdlReadWait
= 0; /* FIXME */
707 Spi
->CcMdlReadNoWaitMiss
= 0; /* FIXME */
708 Spi
->CcMdlReadWaitMiss
= 0; /* FIXME */
709 Spi
->CcReadAheadIos
= 0; /* FIXME */
710 Spi
->CcLazyWriteIos
= 0; /* FIXME */
711 Spi
->CcLazyWritePages
= 0; /* FIXME */
712 Spi
->CcDataFlushes
= 0; /* FIXME */
713 Spi
->CcDataPages
= 0; /* FIXME */
714 Spi
->ContextSwitches
= 0; /* FIXME */
715 Spi
->FirstLevelTbFills
= 0; /* FIXME */
716 Spi
->SecondLevelTbFills
= 0; /* FIXME */
717 Spi
->SystemCalls
= 0; /* FIXME */
719 return STATUS_SUCCESS
;
722 /* Class 3 - Time Of Day Information */
723 QSI_DEF(SystemTimeOfDayInformation
)
725 SYSTEM_TIMEOFDAY_INFORMATION Sti
;
726 LARGE_INTEGER CurrentTime
;
728 /* Set amount of written information to 0 */
731 /* Check user buffer's size */
732 if (Size
> sizeof(SYSTEM_TIMEOFDAY_INFORMATION
))
734 return STATUS_INFO_LENGTH_MISMATCH
;
737 /* Get current time */
738 KeQuerySystemTime(&CurrentTime
);
740 /* Zero local buffer */
741 RtlZeroMemory(&Sti
, sizeof(SYSTEM_TIMEOFDAY_INFORMATION
));
743 /* Fill local time structure */
744 Sti
.BootTime
= KeBootTime
;
745 Sti
.CurrentTime
= CurrentTime
;
746 Sti
.TimeZoneBias
.QuadPart
= ExpTimeZoneBias
.QuadPart
;
747 Sti
.TimeZoneId
= ExpTimeZoneId
;
750 /* Copy as much as requested by caller */
751 RtlCopyMemory(Buffer
, &Sti
, Size
);
753 /* Set amount of information we copied */
756 return STATUS_SUCCESS
;
759 /* Class 4 - Path Information */
760 QSI_DEF(SystemPathInformation
)
762 /* FIXME: QSI returns STATUS_BREAKPOINT. Why? */
763 DPRINT1("NtQuerySystemInformation - SystemPathInformation not implemented\n");
765 return STATUS_BREAKPOINT
;
768 /* Class 5 - Process Information */
769 QSI_DEF(SystemProcessInformation
)
771 PSYSTEM_PROCESS_INFORMATION SpiCurrent
;
772 PSYSTEM_THREAD_INFORMATION ThreadInfo
;
773 PEPROCESS Process
= NULL
, SystemProcess
;
774 PETHREAD CurrentThread
;
775 ANSI_STRING ImageName
;
777 USHORT ImageNameMaximumLength
; // image name length in bytes
778 USHORT ImageNameLength
;
779 PLIST_ENTRY CurrentEntry
;
780 ULONG TotalSize
= 0, ThreadsCount
;
781 ULONG TotalUser
, TotalKernel
;
783 NTSTATUS Status
= STATUS_SUCCESS
;
784 PUNICODE_STRING TempProcessImageName
;
785 _SEH2_VOLATILE PUNICODE_STRING ProcessImageName
= NULL
;
787 BOOLEAN Overflow
= FALSE
;
791 /* scan the process list */
793 PSYSTEM_PROCESS_INFORMATION Spi
794 = (PSYSTEM_PROCESS_INFORMATION
) Buffer
;
796 *ReqSize
= sizeof(SYSTEM_PROCESS_INFORMATION
);
798 /* Check for overflow */
799 if (Size
< sizeof(SYSTEM_PROCESS_INFORMATION
))
804 /* Zero user's buffer */
805 if (!Overflow
) RtlZeroMemory(Spi
, Size
);
807 SystemProcess
= PsIdleProcess
;
808 Process
= SystemProcess
;
809 Current
= (PUCHAR
) Spi
;
813 SpiCurrent
= (PSYSTEM_PROCESS_INFORMATION
) Current
;
815 if ((Process
->ProcessExiting
) &&
816 (Process
->Pcb
.Header
.SignalState
) &&
817 !(Process
->ActiveThreads
) &&
818 (IsListEmpty(&Process
->Pcb
.ThreadListHead
)))
820 DPRINT1("Process %p (%s:%p) is a zombie\n",
821 Process
, Process
->ImageFileName
, Process
->UniqueProcessId
);
823 ImageNameMaximumLength
= 0;
828 CurrentEntry
= Process
->Pcb
.ThreadListHead
.Flink
;
829 while (CurrentEntry
!= &Process
->Pcb
.ThreadListHead
)
832 CurrentEntry
= CurrentEntry
->Flink
;
835 // size of the structure for every process
836 CurrentSize
= sizeof(SYSTEM_PROCESS_INFORMATION
) + sizeof(SYSTEM_THREAD_INFORMATION
) * ThreadsCount
;
838 Status
= SeLocateProcessImageName(Process
, &TempProcessImageName
);
839 ProcessImageName
= TempProcessImageName
;
841 if (NT_SUCCESS(Status
) && (ProcessImageName
->Length
> 0))
843 szSrc
= (PWCHAR
)((PCHAR
)ProcessImageName
->Buffer
+ ProcessImageName
->Length
);
844 /* Loop the file name*/
845 while (szSrc
> ProcessImageName
->Buffer
)
847 /* Make sure this isn't a backslash */
848 if (*--szSrc
== OBJ_NAME_PATH_SEPARATOR
)
855 ImageNameLength
+= sizeof(WCHAR
);
859 if (!ImageNameLength
&& Process
!= PsIdleProcess
)
861 ImageNameLength
= (USHORT
)strlen(Process
->ImageFileName
) * sizeof(WCHAR
);
864 /* Round up the image name length as NT does */
865 if (ImageNameLength
> 0)
866 ImageNameMaximumLength
= ROUND_UP(ImageNameLength
+ sizeof(WCHAR
), 8);
868 ImageNameMaximumLength
= 0;
870 TotalSize
+= CurrentSize
+ ImageNameMaximumLength
;
872 /* Check for overflow */
873 if (TotalSize
> Size
)
878 /* Fill system information */
881 SpiCurrent
->NextEntryOffset
= CurrentSize
+ ImageNameMaximumLength
; // relative offset to the beginning of the next structure
882 SpiCurrent
->NumberOfThreads
= ThreadsCount
;
883 SpiCurrent
->CreateTime
= Process
->CreateTime
;
884 SpiCurrent
->ImageName
.Length
= ImageNameLength
;
885 SpiCurrent
->ImageName
.MaximumLength
= ImageNameMaximumLength
;
886 SpiCurrent
->ImageName
.Buffer
= (void*)(Current
+ CurrentSize
);
888 /* Copy name to the end of the struct */
889 if(Process
!= PsIdleProcess
)
893 RtlCopyMemory(SpiCurrent
->ImageName
.Buffer
, szSrc
, SpiCurrent
->ImageName
.Length
);
897 RtlInitAnsiString(&ImageName
, Process
->ImageFileName
);
898 RtlAnsiStringToUnicodeString(&SpiCurrent
->ImageName
, &ImageName
, FALSE
);
903 RtlInitUnicodeString(&SpiCurrent
->ImageName
, NULL
);
906 SpiCurrent
->BasePriority
= Process
->Pcb
.BasePriority
;
907 SpiCurrent
->UniqueProcessId
= Process
->UniqueProcessId
;
908 SpiCurrent
->InheritedFromUniqueProcessId
= Process
->InheritedFromUniqueProcessId
;
909 SpiCurrent
->HandleCount
= ObGetProcessHandleCount(Process
);
910 SpiCurrent
->PeakVirtualSize
= Process
->PeakVirtualSize
;
911 SpiCurrent
->VirtualSize
= Process
->VirtualSize
;
912 SpiCurrent
->PageFaultCount
= Process
->Vm
.PageFaultCount
;
913 SpiCurrent
->PeakWorkingSetSize
= Process
->Vm
.PeakWorkingSetSize
;
914 SpiCurrent
->WorkingSetSize
= Process
->Vm
.WorkingSetSize
;
915 SpiCurrent
->QuotaPeakPagedPoolUsage
= Process
->QuotaPeak
[0];
916 SpiCurrent
->QuotaPagedPoolUsage
= Process
->QuotaUsage
[0];
917 SpiCurrent
->QuotaPeakNonPagedPoolUsage
= Process
->QuotaPeak
[1];
918 SpiCurrent
->QuotaNonPagedPoolUsage
= Process
->QuotaUsage
[1];
919 SpiCurrent
->PagefileUsage
= Process
->QuotaUsage
[2];
920 SpiCurrent
->PeakPagefileUsage
= Process
->QuotaPeak
[2];
921 SpiCurrent
->PrivatePageCount
= Process
->CommitCharge
;
922 ThreadInfo
= (PSYSTEM_THREAD_INFORMATION
)(SpiCurrent
+ 1);
924 CurrentEntry
= Process
->Pcb
.ThreadListHead
.Flink
;
925 while (CurrentEntry
!= &Process
->Pcb
.ThreadListHead
)
927 CurrentThread
= CONTAINING_RECORD(CurrentEntry
, ETHREAD
, Tcb
.ThreadListEntry
);
929 ThreadInfo
->KernelTime
.QuadPart
= UInt32x32To64(CurrentThread
->Tcb
.KernelTime
, KeMaximumIncrement
);
930 ThreadInfo
->UserTime
.QuadPart
= UInt32x32To64(CurrentThread
->Tcb
.UserTime
, KeMaximumIncrement
);
931 ThreadInfo
->CreateTime
.QuadPart
= CurrentThread
->CreateTime
.QuadPart
;
932 ThreadInfo
->WaitTime
= CurrentThread
->Tcb
.WaitTime
;
933 ThreadInfo
->StartAddress
= (PVOID
) CurrentThread
->StartAddress
;
934 ThreadInfo
->ClientId
= CurrentThread
->Cid
;
935 ThreadInfo
->Priority
= CurrentThread
->Tcb
.Priority
;
936 ThreadInfo
->BasePriority
= CurrentThread
->Tcb
.BasePriority
;
937 ThreadInfo
->ContextSwitches
= CurrentThread
->Tcb
.ContextSwitches
;
938 ThreadInfo
->ThreadState
= CurrentThread
->Tcb
.State
;
939 ThreadInfo
->WaitReason
= CurrentThread
->Tcb
.WaitReason
;
942 CurrentEntry
= CurrentEntry
->Flink
;
945 /* Query total user/kernel times of a process */
946 TotalKernel
= KeQueryRuntimeProcess(&Process
->Pcb
, &TotalUser
);
947 SpiCurrent
->UserTime
.QuadPart
= UInt32x32To64(TotalUser
, KeMaximumIncrement
);
948 SpiCurrent
->KernelTime
.QuadPart
= UInt32x32To64(TotalKernel
, KeMaximumIncrement
);
951 if (ProcessImageName
)
953 /* Release the memory allocated by SeLocateProcessImageName */
954 ExFreePoolWithTag(ProcessImageName
, TAG_SEPA
);
955 ProcessImageName
= NULL
;
958 /* Handle idle process entry */
960 if (Process
== PsIdleProcess
) Process
= NULL
;
962 Process
= PsGetNextProcess(Process
);
964 if ((Process
== SystemProcess
) || (Process
== NULL
))
967 SpiCurrent
->NextEntryOffset
= 0;
971 Current
+= CurrentSize
+ ImageNameMaximumLength
;
972 } while ((Process
!= SystemProcess
) && (Process
!= NULL
));
975 ObDereferenceObject(Process
);
976 Status
= STATUS_SUCCESS
;
978 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
981 ObDereferenceObject(Process
);
982 if (ProcessImageName
)
984 /* Release the memory allocated by SeLocateProcessImageName */
985 ExFreePoolWithTag(ProcessImageName
, TAG_SEPA
);
988 Status
= _SEH2_GetExceptionCode();
993 Status
= STATUS_INFO_LENGTH_MISMATCH
;
995 *ReqSize
= TotalSize
;
999 /* Class 6 - Call Count Information */
1000 QSI_DEF(SystemCallCountInformation
)
1003 DPRINT1("NtQuerySystemInformation - SystemCallCountInformation not implemented\n");
1004 return STATUS_NOT_IMPLEMENTED
;
1007 /* Class 7 - Device Information */
1008 QSI_DEF(SystemDeviceInformation
)
1010 PSYSTEM_DEVICE_INFORMATION Sdi
1011 = (PSYSTEM_DEVICE_INFORMATION
) Buffer
;
1012 PCONFIGURATION_INFORMATION ConfigInfo
;
1014 *ReqSize
= sizeof(SYSTEM_DEVICE_INFORMATION
);
1016 /* Check user buffer's size */
1017 if (Size
< sizeof(SYSTEM_DEVICE_INFORMATION
))
1019 return STATUS_INFO_LENGTH_MISMATCH
;
1022 ConfigInfo
= IoGetConfigurationInformation();
1024 Sdi
->NumberOfDisks
= ConfigInfo
->DiskCount
;
1025 Sdi
->NumberOfFloppies
= ConfigInfo
->FloppyCount
;
1026 Sdi
->NumberOfCdRoms
= ConfigInfo
->CdRomCount
;
1027 Sdi
->NumberOfTapes
= ConfigInfo
->TapeCount
;
1028 Sdi
->NumberOfSerialPorts
= ConfigInfo
->SerialCount
;
1029 Sdi
->NumberOfParallelPorts
= ConfigInfo
->ParallelCount
;
1031 return STATUS_SUCCESS
;
1034 /* Class 8 - Processor Performance Information */
1035 QSI_DEF(SystemProcessorPerformanceInformation
)
1037 PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION Spi
1038 = (PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
) Buffer
;
1044 *ReqSize
= KeNumberProcessors
* sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
);
1046 /* Check user buffer's size */
1047 if (Size
< *ReqSize
)
1049 return STATUS_INFO_LENGTH_MISMATCH
;
1052 for (i
= 0; i
< KeNumberProcessors
; i
++)
1054 /* Get the PRCB on this processor */
1055 Prcb
= KiProcessorBlock
[i
];
1057 /* Calculate total user and kernel times */
1058 TotalTime
= Prcb
->IdleThread
->KernelTime
+ Prcb
->IdleThread
->UserTime
;
1059 Spi
->IdleTime
.QuadPart
= UInt32x32To64(TotalTime
, KeMaximumIncrement
);
1060 Spi
->KernelTime
.QuadPart
= UInt32x32To64(Prcb
->KernelTime
, KeMaximumIncrement
);
1061 Spi
->UserTime
.QuadPart
= UInt32x32To64(Prcb
->UserTime
, KeMaximumIncrement
);
1062 Spi
->DpcTime
.QuadPart
= UInt32x32To64(Prcb
->DpcTime
, KeMaximumIncrement
);
1063 Spi
->InterruptTime
.QuadPart
= UInt32x32To64(Prcb
->InterruptTime
, KeMaximumIncrement
);
1064 Spi
->InterruptCount
= Prcb
->InterruptCount
;
1068 return STATUS_SUCCESS
;
1071 /* Class 9 - Flags Information */
1072 QSI_DEF(SystemFlagsInformation
)
1074 #if (NTDDI_VERSION >= NTDDI_VISTA)
1075 *ReqSize
= sizeof(SYSTEM_FLAGS_INFORMATION
);
1078 if (sizeof(SYSTEM_FLAGS_INFORMATION
) != Size
)
1080 return STATUS_INFO_LENGTH_MISMATCH
;
1083 ((PSYSTEM_FLAGS_INFORMATION
) Buffer
)->Flags
= NtGlobalFlag
;
1084 #if (NTDDI_VERSION < NTDDI_VISTA)
1085 *ReqSize
= sizeof(SYSTEM_FLAGS_INFORMATION
);
1088 return STATUS_SUCCESS
;
1091 SSI_DEF(SystemFlagsInformation
)
1093 if (sizeof(SYSTEM_FLAGS_INFORMATION
) != Size
)
1095 return STATUS_INFO_LENGTH_MISMATCH
;
1098 if (!SeSinglePrivilegeCheck(SeDebugPrivilege
, ExGetPreviousMode()))
1100 return STATUS_ACCESS_DENIED
;
1103 NtGlobalFlag
= ((PSYSTEM_FLAGS_INFORMATION
) Buffer
)->Flags
;
1104 return STATUS_SUCCESS
;
1107 /* Class 10 - Call Time Information */
1108 QSI_DEF(SystemCallTimeInformation
)
1111 DPRINT1("NtQuerySystemInformation - SystemCallTimeInformation not implemented\n");
1112 return STATUS_NOT_IMPLEMENTED
;
1115 /* Class 11 - Module Information */
1116 QSI_DEF(SystemModuleInformation
)
1120 /* Acquire system module list lock */
1121 KeEnterCriticalRegion();
1122 ExAcquireResourceExclusiveLite(&PsLoadedModuleResource
, TRUE
);
1124 /* Call the generic handler with the system module list */
1125 Status
= ExpQueryModuleInformation(&PsLoadedModuleList
,
1126 &MmLoadedUserImageList
,
1127 (PRTL_PROCESS_MODULES
)Buffer
,
1131 /* Release list lock and return status */
1132 ExReleaseResourceLite(&PsLoadedModuleResource
);
1133 KeLeaveCriticalRegion();
1137 /* Class 12 - Locks Information */
1138 QSI_DEF(SystemLocksInformation
)
1141 DPRINT1("NtQuerySystemInformation - SystemLocksInformation not implemented\n");
1142 return STATUS_NOT_IMPLEMENTED
;
1145 /* Class 13 - Stack Trace Information */
1146 QSI_DEF(SystemStackTraceInformation
)
1149 DPRINT1("NtQuerySystemInformation - SystemStackTraceInformation not implemented\n");
1150 return STATUS_NOT_IMPLEMENTED
;
1153 /* Class 14 - Paged Pool Information */
1154 QSI_DEF(SystemPagedPoolInformation
)
1157 DPRINT1("NtQuerySystemInformation - SystemPagedPoolInformation not implemented\n");
1158 return STATUS_NOT_IMPLEMENTED
;
1161 /* Class 15 - Non Paged Pool Information */
1162 QSI_DEF(SystemNonPagedPoolInformation
)
1165 DPRINT1("NtQuerySystemInformation - SystemNonPagedPoolInformation not implemented\n");
1166 return STATUS_NOT_IMPLEMENTED
;
1170 /* Class 16 - Handle Information */
1171 QSI_DEF(SystemHandleInformation
)
1173 PSYSTEM_HANDLE_INFORMATION HandleInformation
;
1178 DPRINT("NtQuerySystemInformation - SystemHandleInformation\n");
1180 /* Set initial required buffer size */
1181 *ReqSize
= sizeof(SYSTEM_HANDLE_INFORMATION
);
1183 /* Check user's buffer size */
1184 if (Size
< *ReqSize
)
1186 return STATUS_INFO_LENGTH_MISMATCH
;
1189 /* We need to lock down the memory */
1190 Status
= ExLockUserBuffer(Buffer
,
1192 ExGetPreviousMode(),
1194 (PVOID
*)&HandleInformation
,
1196 if (!NT_SUCCESS(Status
))
1198 DPRINT1("Failed to lock the user buffer: 0x%lx\n", Status
);
1204 PLIST_ENTRY NextTableEntry
;
1206 /* Enumerate all system handles */
1207 for (NextTableEntry
= HandleTableListHead
.Flink
;
1208 NextTableEntry
!= &HandleTableListHead
;
1209 NextTableEntry
= NextTableEntry
->Flink
)
1211 PHANDLE_TABLE HandleTable
;
1213 /* Enter a critical region */
1214 KeEnterCriticalRegion();
1216 /* Acquire the handle table lock */
1217 ExAcquirePushLockExclusive(&HandleTableListLock
);
1219 /* Get current handle table */
1220 HandleTable
= CONTAINING_RECORD(NextTableEntry
, HANDLE_TABLE
, HandleTableList
);
1224 PHANDLE_TABLE_ENTRY HandleTableEntry
;
1227 /* Set the initial value and loop the entries */
1229 while ((HandleTableEntry
= ExpLookupHandleTableEntry(HandleTable
, Handle
)))
1231 /* Validate the entry */
1232 if ((HandleTableEntry
->Object
) &&
1233 (HandleTableEntry
->NextFreeTableEntry
!= -2))
1235 /* Increase of count of handles */
1236 ++HandleInformation
->NumberOfHandles
;
1238 /* Increase required buffer size */
1239 *ReqSize
+= sizeof(SYSTEM_HANDLE_TABLE_ENTRY_INFO
);
1241 /* Check user's buffer size */
1242 if (*ReqSize
> Size
)
1244 Status
= STATUS_INFO_LENGTH_MISMATCH
;
1248 /* Lock the entry */
1249 if (ExpLockHandleTableEntry(HandleTable
, HandleTableEntry
))
1253 POBJECT_HEADER ObjectHeader
= ObpGetHandleObject(HandleTableEntry
);
1255 /* Filling handle information */
1256 HandleInformation
->Handles
[Index
].UniqueProcessId
=
1257 (USHORT
)(ULONG_PTR
) HandleTable
->UniqueProcessId
;
1259 HandleInformation
->Handles
[Index
].CreatorBackTraceIndex
= 0;
1261 HandleInformation
->Handles
[Index
].ObjectTypeIndex
=
1262 (UCHAR
) ObjectHeader
->Type
->Index
;
1264 HandleInformation
->Handles
[Index
].HandleAttributes
=
1265 HandleTableEntry
->ObAttributes
& OBJ_HANDLE_ATTRIBUTES
;
1267 HandleInformation
->Handles
[Index
].HandleValue
=
1268 (USHORT
)(ULONG_PTR
) Handle
.GenericHandleOverlay
;
1270 HandleInformation
->Handles
[Index
].Object
= &ObjectHeader
->Body
;
1272 HandleInformation
->Handles
[Index
].GrantedAccess
=
1273 HandleTableEntry
->GrantedAccess
;
1280 ExUnlockHandleTableEntry(HandleTable
, HandleTableEntry
);
1286 /* Go to the next entry */
1287 Handle
.Value
+= sizeof(HANDLE
);
1292 /* Release the lock */
1293 ExReleasePushLockExclusive(&HandleTableListLock
);
1295 /* Leave the critical region */
1296 KeLeaveCriticalRegion();
1300 if (!NT_SUCCESS(Status
)) break;
1305 /* Release the locked user buffer */
1306 ExUnlockUserBuffer(Mdl
);
1313 /* Class 17 - Information */
1314 QSI_DEF(SystemObjectInformation
)
1317 DPRINT1("NtQuerySystemInformation - SystemObjectInformation not implemented\n");
1318 return STATUS_NOT_IMPLEMENTED
;
1321 /* Class 18 - Information */
1322 QSI_DEF(SystemPageFileInformation
)
1324 UNICODE_STRING FileName
; /* FIXME */
1325 SYSTEM_PAGEFILE_INFORMATION
*Spfi
= (SYSTEM_PAGEFILE_INFORMATION
*) Buffer
;
1327 if (Size
< sizeof(SYSTEM_PAGEFILE_INFORMATION
))
1329 * ReqSize
= sizeof(SYSTEM_PAGEFILE_INFORMATION
);
1330 return STATUS_INFO_LENGTH_MISMATCH
;
1333 RtlInitUnicodeString(&FileName
, NULL
); /* FIXME */
1336 Spfi
->NextEntryOffset
= 0;
1338 Spfi
->TotalSize
= MiFreeSwapPages
+ MiUsedSwapPages
;
1339 Spfi
->TotalInUse
= MiUsedSwapPages
;
1340 Spfi
->PeakUsage
= MiUsedSwapPages
; /* FIXME */
1341 Spfi
->PageFileName
= FileName
;
1342 return STATUS_SUCCESS
;
1345 /* Class 19 - Vdm Instemul Information */
1346 QSI_DEF(SystemVdmInstemulInformation
)
1349 DPRINT1("NtQuerySystemInformation - SystemVdmInstemulInformation not implemented\n");
1350 return STATUS_NOT_IMPLEMENTED
;
1353 /* Class 20 - Vdm Bop Information */
1354 QSI_DEF(SystemVdmBopInformation
)
1357 DPRINT1("NtQuerySystemInformation - SystemVdmBopInformation not implemented\n");
1358 return STATUS_NOT_IMPLEMENTED
;
1361 /* Class 21 - File Cache Information */
1362 QSI_DEF(SystemFileCacheInformation
)
1364 SYSTEM_FILECACHE_INFORMATION
*Sci
= (SYSTEM_FILECACHE_INFORMATION
*) Buffer
;
1366 *ReqSize
= sizeof(SYSTEM_FILECACHE_INFORMATION
);
1368 if (Size
< *ReqSize
)
1370 return STATUS_INFO_LENGTH_MISMATCH
;
1373 RtlZeroMemory(Sci
, sizeof(SYSTEM_FILECACHE_INFORMATION
));
1375 /* Return the Byte size not the page size. */
1377 MiMemoryConsumers
[MC_CACHE
].PagesUsed
* PAGE_SIZE
;
1379 MiMemoryConsumers
[MC_CACHE
].PagesUsed
* PAGE_SIZE
; /* FIXME */
1380 /* Taskmgr multiplies this one by page size right away */
1381 Sci
->CurrentSizeIncludingTransitionInPages
=
1382 MiMemoryConsumers
[MC_CACHE
].PagesUsed
; /* FIXME: Should be */
1383 /* system working set and standby pages. */
1384 Sci
->PageFaultCount
= 0; /* FIXME */
1385 Sci
->MinimumWorkingSet
= 0; /* FIXME */
1386 Sci
->MaximumWorkingSet
= 0; /* FIXME */
1388 return STATUS_SUCCESS
;
1391 SSI_DEF(SystemFileCacheInformation
)
1393 if (Size
< sizeof(SYSTEM_FILECACHE_INFORMATION
))
1395 return STATUS_INFO_LENGTH_MISMATCH
;
1398 DPRINT1("NtSetSystemInformation - SystemFileCacheInformation not implemented\n");
1399 return STATUS_NOT_IMPLEMENTED
;
1402 /* Class 22 - Pool Tag Information */
1403 QSI_DEF(SystemPoolTagInformation
)
1405 if (Size
< sizeof(SYSTEM_POOLTAG_INFORMATION
)) return STATUS_INFO_LENGTH_MISMATCH
;
1406 return ExGetPoolTagInfo(Buffer
, Size
, ReqSize
);
1409 /* Class 23 - Interrupt Information for all processors */
1410 QSI_DEF(SystemInterruptInformation
)
1415 PSYSTEM_INTERRUPT_INFORMATION sii
= (PSYSTEM_INTERRUPT_INFORMATION
)Buffer
;
1417 if(Size
< KeNumberProcessors
* sizeof(SYSTEM_INTERRUPT_INFORMATION
))
1419 return STATUS_INFO_LENGTH_MISMATCH
;
1422 ti
= KeQueryTimeIncrement();
1424 for (i
= 0; i
< KeNumberProcessors
; i
++)
1426 Prcb
= KiProcessorBlock
[i
];
1427 sii
->ContextSwitches
= KeGetContextSwitches(Prcb
);
1428 sii
->DpcCount
= Prcb
->DpcData
[0].DpcCount
;
1429 sii
->DpcRate
= Prcb
->DpcRequestRate
;
1430 sii
->TimeIncrement
= ti
;
1431 sii
->DpcBypassCount
= 0;
1432 sii
->ApcBypassCount
= 0;
1436 return STATUS_SUCCESS
;
1439 /* Class 24 - DPC Behaviour Information */
1440 QSI_DEF(SystemDpcBehaviourInformation
)
1443 DPRINT1("NtQuerySystemInformation - SystemDpcBehaviourInformation not implemented\n");
1444 return STATUS_NOT_IMPLEMENTED
;
1447 SSI_DEF(SystemDpcBehaviourInformation
)
1450 DPRINT1("NtSetSystemInformation - SystemDpcBehaviourInformation not implemented\n");
1451 return STATUS_NOT_IMPLEMENTED
;
1454 /* Class 25 - Full Memory Information */
1455 QSI_DEF(SystemFullMemoryInformation
)
1457 PULONG Spi
= (PULONG
) Buffer
;
1459 PEPROCESS TheIdleProcess
;
1461 *ReqSize
= sizeof(ULONG
);
1463 if (sizeof(ULONG
) != Size
)
1465 return STATUS_INFO_LENGTH_MISMATCH
;
1468 DPRINT("SystemFullMemoryInformation\n");
1470 TheIdleProcess
= PsIdleProcess
;
1472 DPRINT("PID: %p, KernelTime: %u PFFree: %lu PFUsed: %lu\n",
1473 TheIdleProcess
->UniqueProcessId
,
1474 TheIdleProcess
->Pcb
.KernelTime
,
1478 *Spi
= MiMemoryConsumers
[MC_USER
].PagesUsed
;
1480 return STATUS_SUCCESS
;
1483 /* Class 26 - Load Image */
1484 SSI_DEF(SystemLoadGdiDriverInformation
)
1486 PSYSTEM_GDI_DRIVER_INFORMATION DriverInfo
= (PVOID
)Buffer
;
1487 UNICODE_STRING ImageName
;
1489 PVOID SectionPointer
;
1490 ULONG_PTR EntryPoint
;
1493 PIMAGE_NT_HEADERS NtHeader
;
1496 if (Size
!= sizeof(SYSTEM_GDI_DRIVER_INFORMATION
))
1498 /* Incorrect buffer length, fail */
1499 return STATUS_INFO_LENGTH_MISMATCH
;
1502 /* Only kernel mode can call this function */
1503 if (ExGetPreviousMode() != KernelMode
) return STATUS_PRIVILEGE_NOT_HELD
;
1505 /* Load the driver */
1506 ImageName
= DriverInfo
->DriverName
;
1507 Status
= MmLoadSystemImage(&ImageName
,
1513 if (!NT_SUCCESS(Status
)) return Status
;
1515 /* Return the export pointer */
1516 DriverInfo
->ExportSectionPointer
=
1517 RtlImageDirectoryEntryToData(ImageBase
,
1519 IMAGE_DIRECTORY_ENTRY_EXPORT
,
1522 /* Get the entrypoint */
1523 NtHeader
= RtlImageNtHeader(ImageBase
);
1524 EntryPoint
= NtHeader
->OptionalHeader
.AddressOfEntryPoint
;
1525 EntryPoint
+= (ULONG_PTR
)ImageBase
;
1527 /* Save other data */
1528 DriverInfo
->ImageAddress
= ImageBase
;
1529 DriverInfo
->SectionPointer
= SectionPointer
;
1530 DriverInfo
->EntryPoint
= (PVOID
)EntryPoint
;
1531 DriverInfo
->ImageLength
= NtHeader
->OptionalHeader
.SizeOfImage
;
1534 return STATUS_SUCCESS
;
1537 /* Class 27 - Unload Image */
1538 SSI_DEF(SystemUnloadGdiDriverInformation
)
1540 PVOID
*SectionPointer
= Buffer
;
1543 if (Size
!= sizeof(PVOID
))
1545 /* Incorrect length, fail */
1546 return STATUS_INFO_LENGTH_MISMATCH
;
1549 /* Only kernel mode can call this function */
1550 if (ExGetPreviousMode() != KernelMode
) return STATUS_PRIVILEGE_NOT_HELD
;
1552 /* Unload the image */
1553 MmUnloadSystemImage(*SectionPointer
);
1554 return STATUS_SUCCESS
;
1557 /* Class 28 - Time Adjustment Information */
1558 QSI_DEF(SystemTimeAdjustmentInformation
)
1560 PSYSTEM_QUERY_TIME_ADJUST_INFORMATION TimeInfo
=
1561 (PSYSTEM_QUERY_TIME_ADJUST_INFORMATION
)Buffer
;
1563 /* Check if enough storage was provided */
1564 if (sizeof(SYSTEM_QUERY_TIME_ADJUST_INFORMATION
) > Size
)
1566 * ReqSize
= sizeof(SYSTEM_QUERY_TIME_ADJUST_INFORMATION
);
1567 return STATUS_INFO_LENGTH_MISMATCH
;
1570 /* Give time values to our caller */
1571 TimeInfo
->TimeIncrement
= KeMaximumIncrement
;
1572 TimeInfo
->TimeAdjustment
= KeTimeAdjustment
;
1573 TimeInfo
->Enable
= !KiTimeAdjustmentEnabled
;
1575 return STATUS_SUCCESS
;
1578 SSI_DEF(SystemTimeAdjustmentInformation
)
1580 KPROCESSOR_MODE PreviousMode
= KeGetPreviousMode();
1581 PSYSTEM_SET_TIME_ADJUST_INFORMATION TimeInfo
=
1582 (PSYSTEM_SET_TIME_ADJUST_INFORMATION
)Buffer
;
1584 /* Check size of a buffer, it must match our expectations */
1585 if (sizeof(SYSTEM_SET_TIME_ADJUST_INFORMATION
) != Size
)
1586 return STATUS_INFO_LENGTH_MISMATCH
;
1588 /* Check who is calling */
1589 if (PreviousMode
!= KernelMode
)
1591 /* Check access rights */
1592 if (!SeSinglePrivilegeCheck(SeSystemtimePrivilege
, PreviousMode
))
1594 return STATUS_PRIVILEGE_NOT_HELD
;
1598 /* FIXME: behaviour suggests the member be named 'Disable' */
1599 if (TimeInfo
->Enable
)
1601 /* Disable time adjustment and set default value */
1602 KiTimeAdjustmentEnabled
= FALSE
;
1603 KeTimeAdjustment
= KeMaximumIncrement
;
1607 /* Check if a valid time adjustment value is given */
1608 if (TimeInfo
->TimeAdjustment
== 0) return STATUS_INVALID_PARAMETER_2
;
1610 /* Enable time adjustment and set the adjustment value */
1611 KiTimeAdjustmentEnabled
= TRUE
;
1612 KeTimeAdjustment
= TimeInfo
->TimeAdjustment
;
1615 return STATUS_SUCCESS
;
1618 /* Class 29 - Summary Memory Information */
1619 QSI_DEF(SystemSummaryMemoryInformation
)
1622 DPRINT1("NtQuerySystemInformation - SystemSummaryMemoryInformation not implemented\n");
1623 return STATUS_NOT_IMPLEMENTED
;
1626 /* Class 30 - Next Event Id Information */
1627 QSI_DEF(SystemNextEventIdInformation
)
1630 DPRINT1("NtQuerySystemInformation - SystemNextEventIdInformation not implemented\n");
1631 return STATUS_NOT_IMPLEMENTED
;
1635 QSI_DEF(SystemPerformanceTraceInformation
)
1638 DPRINT1("NtQuerySystemInformation - SystemPerformanceTraceInformation not implemented\n");
1639 return STATUS_NOT_IMPLEMENTED
;
1642 /* Class 32 - Crash Dump Information */
1643 QSI_DEF(SystemCrashDumpInformation
)
1646 DPRINT1("NtQuerySystemInformation - SystemCrashDumpInformation not implemented\n");
1647 return STATUS_NOT_IMPLEMENTED
;
1650 /* Class 33 - Exception Information */
1651 QSI_DEF(SystemExceptionInformation
)
1653 PSYSTEM_EXCEPTION_INFORMATION ExceptionInformation
=
1654 (PSYSTEM_EXCEPTION_INFORMATION
)Buffer
;
1656 ULONG AlignmentFixupCount
= 0, ExceptionDispatchCount
= 0;
1657 ULONG FloatingEmulationCount
= 0, ByteWordEmulationCount
= 0;
1660 /* Check size of a buffer, it must match our expectations */
1661 if (sizeof(SYSTEM_EXCEPTION_INFORMATION
) != Size
)
1662 return STATUS_INFO_LENGTH_MISMATCH
;
1664 /* Sum up exception count information from all processors */
1665 for (i
= 0; i
< KeNumberProcessors
; i
++)
1667 Prcb
= KiProcessorBlock
[i
];
1670 AlignmentFixupCount
+= Prcb
->KeAlignmentFixupCount
;
1671 ExceptionDispatchCount
+= Prcb
->KeExceptionDispatchCount
;
1673 FloatingEmulationCount
+= Prcb
->KeFloatingEmulationCount
;
1678 /* Save information in user's buffer */
1679 ExceptionInformation
->AlignmentFixupCount
= AlignmentFixupCount
;
1680 ExceptionInformation
->ExceptionDispatchCount
= ExceptionDispatchCount
;
1681 ExceptionInformation
->FloatingEmulationCount
= FloatingEmulationCount
;
1682 ExceptionInformation
->ByteWordEmulationCount
= ByteWordEmulationCount
;
1684 return STATUS_SUCCESS
;
1687 /* Class 34 - Crash Dump State Information */
1688 QSI_DEF(SystemCrashDumpStateInformation
)
1691 DPRINT1("NtQuerySystemInformation - SystemCrashDumpStateInformation not implemented\n");
1692 return STATUS_NOT_IMPLEMENTED
;
1695 /* Class 35 - Kernel Debugger Information */
1696 QSI_DEF(SystemKernelDebuggerInformation
)
1698 PSYSTEM_KERNEL_DEBUGGER_INFORMATION skdi
= (PSYSTEM_KERNEL_DEBUGGER_INFORMATION
) Buffer
;
1700 #if (NTDDI_VERSION >= NTDDI_VISTA)
1701 *ReqSize
= sizeof(SYSTEM_KERNEL_DEBUGGER_INFORMATION
);
1704 if (Size
< sizeof(SYSTEM_KERNEL_DEBUGGER_INFORMATION
))
1706 return STATUS_INFO_LENGTH_MISMATCH
;
1709 skdi
->KernelDebuggerEnabled
= KD_DEBUGGER_ENABLED
;
1710 skdi
->KernelDebuggerNotPresent
= KD_DEBUGGER_NOT_PRESENT
;
1712 #if (NTDDI_VERSION < NTDDI_VISTA)
1713 *ReqSize
= sizeof(SYSTEM_KERNEL_DEBUGGER_INFORMATION
);
1716 return STATUS_SUCCESS
;
1719 /* Class 36 - Context Switch Information */
1720 QSI_DEF(SystemContextSwitchInformation
)
1722 PSYSTEM_CONTEXT_SWITCH_INFORMATION ContextSwitchInformation
=
1723 (PSYSTEM_CONTEXT_SWITCH_INFORMATION
)Buffer
;
1724 ULONG ContextSwitches
;
1728 /* Check size of a buffer, it must match our expectations */
1729 if (sizeof(SYSTEM_CONTEXT_SWITCH_INFORMATION
) != Size
)
1730 return STATUS_INFO_LENGTH_MISMATCH
;
1732 /* Calculate total value of context switches across all processors */
1733 ContextSwitches
= 0;
1734 for (i
= 0; i
< KeNumberProcessors
; i
++)
1736 Prcb
= KiProcessorBlock
[i
];
1739 ContextSwitches
+= KeGetContextSwitches(Prcb
);
1743 ContextSwitchInformation
->ContextSwitches
= ContextSwitches
;
1746 ContextSwitchInformation
->FindAny
= 0;
1747 ContextSwitchInformation
->FindLast
= 0;
1748 ContextSwitchInformation
->FindIdeal
= 0;
1749 ContextSwitchInformation
->IdleAny
= 0;
1750 ContextSwitchInformation
->IdleCurrent
= 0;
1751 ContextSwitchInformation
->IdleLast
= 0;
1752 ContextSwitchInformation
->IdleIdeal
= 0;
1753 ContextSwitchInformation
->PreemptAny
= 0;
1754 ContextSwitchInformation
->PreemptCurrent
= 0;
1755 ContextSwitchInformation
->PreemptLast
= 0;
1756 ContextSwitchInformation
->SwitchToIdle
= 0;
1758 return STATUS_SUCCESS
;
1761 /* Class 37 - Registry Quota Information */
1762 QSI_DEF(SystemRegistryQuotaInformation
)
1764 PSYSTEM_REGISTRY_QUOTA_INFORMATION srqi
= (PSYSTEM_REGISTRY_QUOTA_INFORMATION
) Buffer
;
1766 *ReqSize
= sizeof(SYSTEM_REGISTRY_QUOTA_INFORMATION
);
1767 if (Size
< sizeof(SYSTEM_REGISTRY_QUOTA_INFORMATION
))
1769 return STATUS_INFO_LENGTH_MISMATCH
;
1772 DPRINT1("Faking max registry size of 32 MB\n");
1773 srqi
->RegistryQuotaAllowed
= 0x2000000;
1774 srqi
->RegistryQuotaUsed
= 0x200000;
1775 srqi
->PagedPoolSize
= 0x200000;
1777 return STATUS_SUCCESS
;
1780 SSI_DEF(SystemRegistryQuotaInformation
)
1783 DPRINT1("NtSetSystemInformation - SystemRegistryQuotaInformation not implemented\n");
1784 return STATUS_NOT_IMPLEMENTED
;
1787 /* Class 38 - Load And Call Image */
1788 SSI_DEF(SystemExtendServiceTableInformation
)
1790 UNICODE_STRING ImageName
;
1791 KPROCESSOR_MODE PreviousMode
= KeGetPreviousMode();
1792 PLDR_DATA_TABLE_ENTRY ModuleObject
;
1794 PIMAGE_NT_HEADERS NtHeader
;
1795 DRIVER_OBJECT Win32k
;
1796 PDRIVER_INITIALIZE DriverInit
;
1798 ULONG_PTR EntryPoint
;
1800 /* Validate the size */
1801 if (Size
!= sizeof(UNICODE_STRING
)) return STATUS_INFO_LENGTH_MISMATCH
;
1803 /* Check who is calling */
1804 if (PreviousMode
!= KernelMode
)
1806 static const UNICODE_STRING Win32kName
=
1807 RTL_CONSTANT_STRING(L
"\\SystemRoot\\System32\\win32k.sys");
1809 /* Make sure we can load drivers */
1810 if (!SeSinglePrivilegeCheck(SeLoadDriverPrivilege
, UserMode
))
1812 /* FIXME: We can't, fail */
1813 return STATUS_PRIVILEGE_NOT_HELD
;
1818 /* Probe and copy the unicode string */
1819 ProbeForRead(Buffer
, sizeof(ImageName
), 1);
1820 ImageName
= *(PUNICODE_STRING
)Buffer
;
1822 /* Probe the string buffer */
1823 ProbeForRead(ImageName
.Buffer
, ImageName
.Length
, sizeof(WCHAR
));
1825 /* Check if we have the correct name (nothing else is allowed!) */
1826 if (!RtlEqualUnicodeString(&ImageName
, &Win32kName
, FALSE
))
1828 _SEH2_YIELD(return STATUS_PRIVILEGE_NOT_HELD
);
1831 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1833 _SEH2_YIELD(return _SEH2_GetExceptionCode());
1837 /* Recursively call the function, so that we are from kernel mode */
1838 return ZwSetSystemInformation(SystemExtendServiceTableInformation
,
1840 sizeof(Win32kName
));
1843 /* Load the image */
1844 Status
= MmLoadSystemImage((PUNICODE_STRING
)Buffer
,
1848 (PVOID
)&ModuleObject
,
1851 if (!NT_SUCCESS(Status
)) return Status
;
1853 /* Get the headers */
1854 NtHeader
= RtlImageNtHeader(ImageBase
);
1858 MmUnloadSystemImage(ModuleObject
);
1859 return STATUS_INVALID_IMAGE_FORMAT
;
1862 /* Get the entrypoint */
1863 EntryPoint
= NtHeader
->OptionalHeader
.AddressOfEntryPoint
;
1864 EntryPoint
+= (ULONG_PTR
)ImageBase
;
1865 DriverInit
= (PDRIVER_INITIALIZE
)EntryPoint
;
1867 /* Create a dummy device */
1868 RtlZeroMemory(&Win32k
, sizeof(Win32k
));
1869 ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL
);
1870 Win32k
.DriverStart
= ImageBase
;
1873 Status
= (DriverInit
)(&Win32k
, NULL
);
1874 ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL
);
1876 /* Unload if we failed */
1877 if (!NT_SUCCESS(Status
)) MmUnloadSystemImage(ModuleObject
);
1881 /* Class 39 - Priority Separation */
1882 SSI_DEF(SystemPrioritySeperation
)
1884 /* Check if the size is correct */
1885 if (Size
!= sizeof(ULONG
))
1887 return STATUS_INFO_LENGTH_MISMATCH
;
1890 /* We need the TCB privilege */
1891 if (!SeSinglePrivilegeCheck(SeTcbPrivilege
, ExGetPreviousMode()))
1893 return STATUS_PRIVILEGE_NOT_HELD
;
1896 /* Modify the quantum table */
1897 PsChangeQuantumTable(TRUE
, *(PULONG
)Buffer
);
1899 return STATUS_SUCCESS
;
1903 QSI_DEF(SystemVerifierAddDriverInformation
)
1906 DPRINT1("NtQuerySystemInformation - SystemVerifierAddDriverInformation not implemented\n");
1907 return STATUS_NOT_IMPLEMENTED
;
1911 QSI_DEF(SystemVerifierRemoveDriverInformation
)
1914 DPRINT1("NtQuerySystemInformation - SystemVerifierRemoveDriverInformation not implemented\n");
1915 return STATUS_NOT_IMPLEMENTED
;
1918 /* Class 42 - Power Information */
1919 QSI_DEF(SystemProcessorIdleInformation
)
1921 *ReqSize
= sizeof(PROCESSOR_POWER_INFORMATION
) * KeNumberProcessors
;
1923 if (sizeof(PROCESSOR_POWER_INFORMATION
) * KeNumberProcessors
> Size
)
1925 return STATUS_INFO_LENGTH_MISMATCH
;
1929 DPRINT1("NtQuerySystemInformation - SystemPowerInformation not implemented\n");
1930 return STATUS_NOT_IMPLEMENTED
;
1934 QSI_DEF(SystemLegacyDriverInformation
)
1937 DPRINT1("NtQuerySystemInformation - SystemLegacyDriverInformation not implemented\n");
1938 return STATUS_NOT_IMPLEMENTED
;
1941 /* Class 44 - Current Time Zone Information */
1942 QSI_DEF(SystemCurrentTimeZoneInformation
)
1944 *ReqSize
= sizeof(TIME_ZONE_INFORMATION
);
1946 if (sizeof(TIME_ZONE_INFORMATION
) != Size
)
1948 return STATUS_INFO_LENGTH_MISMATCH
;
1951 /* Copy the time zone information struct */
1954 sizeof(TIME_ZONE_INFORMATION
));
1956 return STATUS_SUCCESS
;
1960 SSI_DEF(SystemCurrentTimeZoneInformation
)
1962 /* Check user buffer's size */
1963 if (Size
< sizeof(TIME_ZONE_INFORMATION
))
1965 return STATUS_INFO_LENGTH_MISMATCH
;
1968 return ExpSetTimeZoneInformation((PTIME_ZONE_INFORMATION
)Buffer
);
1973 ExpCopyLookasideInformation(
1974 PSYSTEM_LOOKASIDE_INFORMATION
*InfoPointer
,
1975 PULONG RemainingPointer
,
1976 PLIST_ENTRY ListHead
,
1977 BOOLEAN ListUsesMisses
)
1980 PSYSTEM_LOOKASIDE_INFORMATION Info
;
1981 PGENERAL_LOOKASIDE LookasideList
;
1982 PLIST_ENTRY ListEntry
;
1985 /* Get info pointer and remaining count of free array element */
1986 Info
= *InfoPointer
;
1987 Remaining
= *RemainingPointer
;
1989 /* Loop as long as we have lookaside lists and free array elements */
1990 for (ListEntry
= ListHead
->Flink
;
1991 (ListEntry
!= ListHead
) && (Remaining
> 0);
1992 ListEntry
= ListEntry
->Flink
, Remaining
--)
1994 LookasideList
= CONTAINING_RECORD(ListEntry
, GENERAL_LOOKASIDE
, ListEntry
);
1996 /* Fill the next array element */
1997 Info
->CurrentDepth
= LookasideList
->Depth
;
1998 Info
->MaximumDepth
= LookasideList
->MaximumDepth
;
1999 Info
->TotalAllocates
= LookasideList
->TotalAllocates
;
2000 Info
->TotalFrees
= LookasideList
->TotalFrees
;
2001 Info
->Type
= LookasideList
->Type
;
2002 Info
->Tag
= LookasideList
->Tag
;
2003 Info
->Size
= LookasideList
->Size
;
2005 /* Check how the lists track misses/hits */
2009 Info
->AllocateMisses
= LookasideList
->AllocateMisses
;
2010 Info
->FreeMisses
= LookasideList
->FreeMisses
;
2014 /* Calculate misses */
2015 Info
->AllocateMisses
= LookasideList
->TotalAllocates
2016 - LookasideList
->AllocateHits
;
2017 Info
->FreeMisses
= LookasideList
->TotalFrees
2018 - LookasideList
->FreeHits
;
2022 /* Return the updated pointer and remaining count */
2023 *InfoPointer
= Info
;
2024 *RemainingPointer
= Remaining
;
2027 /* Class 45 - Lookaside Information */
2028 QSI_DEF(SystemLookasideInformation
)
2030 KPROCESSOR_MODE PreviousMode
;
2031 PSYSTEM_LOOKASIDE_INFORMATION Info
;
2033 ULONG MaxCount
, Remaining
;
2037 /* First we need to lock down the memory, since we are going to access it
2039 PreviousMode
= ExGetPreviousMode();
2040 Status
= ExLockUserBuffer(Buffer
,
2046 if (!NT_SUCCESS(Status
))
2048 DPRINT1("Failed to lock the user buffer: 0x%lx\n", Status
);
2052 /* Calculate how many items we can store */
2053 Remaining
= MaxCount
= Size
/ sizeof(SYSTEM_LOOKASIDE_INFORMATION
);
2059 /* Copy info from pool lookaside lists */
2060 ExpCopyLookasideInformation(&Info
,
2062 &ExPoolLookasideListHead
,
2069 /* Copy info from system lookaside lists */
2070 ExpCopyLookasideInformation(&Info
,
2072 &ExSystemLookasideListHead
,
2079 /* Acquire spinlock for ExpNonPagedLookasideListHead */
2080 KeAcquireSpinLock(&ExpNonPagedLookasideListLock
, &OldIrql
);
2082 /* Copy info from non-paged lookaside lists */
2083 ExpCopyLookasideInformation(&Info
,
2085 &ExpNonPagedLookasideListHead
,
2088 /* Release spinlock for ExpNonPagedLookasideListHead */
2089 KeReleaseSpinLock(&ExpNonPagedLookasideListLock
, OldIrql
);
2096 /* Acquire spinlock for ExpPagedLookasideListHead */
2097 KeAcquireSpinLock(&ExpPagedLookasideListLock
, &OldIrql
);
2099 /* Copy info from paged lookaside lists */
2100 ExpCopyLookasideInformation(&Info
,
2102 &ExpPagedLookasideListHead
,
2105 /* Release spinlock for ExpPagedLookasideListHead */
2106 KeReleaseSpinLock(&ExpPagedLookasideListLock
, OldIrql
);
2110 /* Release the locked user buffer */
2111 ExUnlockUserBuffer(Mdl
);
2113 /* Return the size of the actually written data */
2114 *ReqSize
= (MaxCount
- Remaining
) * sizeof(SYSTEM_LOOKASIDE_INFORMATION
);
2115 return STATUS_SUCCESS
;
2119 /* Class 46 - Set time slip event */
2120 SSI_DEF(SystemTimeSlipNotification
)
2123 DPRINT1("NtSetSystemInformation - SystemTimeSlipNotification not implemented\n");
2124 return STATUS_NOT_IMPLEMENTED
;
2129 MmSessionCreate(OUT PULONG SessionId
);
2133 MmSessionDelete(IN ULONG SessionId
);
2135 /* Class 47 - Create a new session (TSE) */
2136 SSI_DEF(SystemSessionCreate
)
2139 KPROCESSOR_MODE PreviousMode
= KeGetPreviousMode();
2142 if (Size
!= sizeof(ULONG
)) return STATUS_INFO_LENGTH_MISMATCH
;
2144 if (PreviousMode
!= KernelMode
)
2146 if (!SeSinglePrivilegeCheck(SeLoadDriverPrivilege
, PreviousMode
))
2148 return STATUS_PRIVILEGE_NOT_HELD
;
2151 ProbeForWriteUlong(Buffer
);
2154 Status
= MmSessionCreate(&SessionId
);
2155 if (NT_SUCCESS(Status
)) *(PULONG
)Buffer
= SessionId
;
2161 /* Class 48 - Delete an existing session (TSE) */
2162 SSI_DEF(SystemSessionDetach
)
2165 KPROCESSOR_MODE PreviousMode
= KeGetPreviousMode();
2167 if (Size
!= sizeof(ULONG
)) return STATUS_INFO_LENGTH_MISMATCH
;
2169 if (PreviousMode
!= KernelMode
)
2171 if (!SeSinglePrivilegeCheck(SeLoadDriverPrivilege
, PreviousMode
))
2173 return STATUS_PRIVILEGE_NOT_HELD
;
2177 SessionId
= *(PULONG
)Buffer
;
2179 return MmSessionDelete(SessionId
);
2183 /* Class 49 - UNKNOWN */
2184 QSI_DEF(SystemSessionInformation
)
2187 DPRINT1("NtQuerySystemInformation - SystemSessionInformation not implemented\n");
2188 return STATUS_NOT_IMPLEMENTED
;
2192 /* Class 50 - System range start address */
2193 QSI_DEF(SystemRangeStartInformation
)
2195 /* Check user buffer's size */
2196 if (Size
!= sizeof(ULONG_PTR
)) return STATUS_INFO_LENGTH_MISMATCH
;
2198 *(PULONG_PTR
)Buffer
= (ULONG_PTR
)MmSystemRangeStart
;
2200 if (ReqSize
) *ReqSize
= sizeof(ULONG_PTR
);
2202 return STATUS_SUCCESS
;
2205 /* Class 51 - Driver verifier information */
2206 QSI_DEF(SystemVerifierInformation
)
2209 DPRINT1("NtQuerySystemInformation - SystemVerifierInformation not implemented\n");
2210 return STATUS_NOT_IMPLEMENTED
;
2214 SSI_DEF(SystemVerifierInformation
)
2217 DPRINT1("NtSetSystemInformation - SystemVerifierInformation not implemented\n");
2218 return STATUS_NOT_IMPLEMENTED
;
2223 SSI_DEF(SystemVerifierThunkExtend
)
2226 DPRINT1("NtSetSystemInformation - SystemVerifierThunkExtend not implemented\n");
2227 return STATUS_NOT_IMPLEMENTED
;
2231 /* Class 53 - A session's processes */
2232 QSI_DEF(SystemSessionProcessesInformation
)
2235 DPRINT1("NtQuerySystemInformation - SystemSessionProcessInformation not implemented\n");
2236 return STATUS_NOT_IMPLEMENTED
;
2240 /* Class 54 - Load & map in system space */
2241 SSI_DEF(SystemLoadGdiDriverInSystemSpaceInformation
)
2244 DPRINT1("NtSetSystemInformation - SystemLoadGdiDriverInSystemSpaceInformation not implemented\n");
2245 return STATUS_NOT_IMPLEMENTED
;
2249 /* Class 55 - NUMA processor information */
2250 QSI_DEF(SystemNumaProcessorMap
)
2252 ULONG MaxEntries
, Node
;
2253 PSYSTEM_NUMA_INFORMATION NumaInformation
= (PSYSTEM_NUMA_INFORMATION
)Buffer
;
2255 /* Validate input size */
2256 if (Size
< sizeof(ULONG
))
2258 return STATUS_INFO_LENGTH_MISMATCH
;
2261 /* Return highest node */
2262 NumaInformation
->HighestNodeNumber
= KeNumberNodes
- 1;
2264 /* Compute how much entries we will be able to put in output structure */
2265 MaxEntries
= (Size
- FIELD_OFFSET(SYSTEM_NUMA_INFORMATION
, ActiveProcessorsAffinityMask
)) / sizeof(ULONGLONG
);
2266 /* Make sure we don't overflow KeNodeBlock */
2267 if (MaxEntries
> KeNumberNodes
)
2269 MaxEntries
= KeNumberNodes
;
2272 /* If we have entries to write, and room for it */
2273 if (Size
>= FIELD_OFFSET(SYSTEM_NUMA_INFORMATION
, ActiveProcessorsAffinityMask
) &&
2276 /* Already set size we return */
2277 *ReqSize
= FIELD_OFFSET(SYSTEM_NUMA_INFORMATION
, ActiveProcessorsAffinityMask
) +
2278 MaxEntries
* sizeof(ULONGLONG
);
2280 /* For each node, return processor mask */
2281 for (Node
= 0; Node
< MaxEntries
; ++Node
)
2283 NumaInformation
->ActiveProcessorsAffinityMask
[Node
] = KeNodeBlock
[Node
]->ProcessorMask
;
2288 /* We only returned highest node number */
2289 *ReqSize
= sizeof(ULONG
);
2292 return STATUS_SUCCESS
;
2296 /* Class 56 - Prefetcher information */
2297 QSI_DEF(SystemPrefetcherInformation
)
2300 DPRINT1("NtQuerySystemInformation - SystemPrefetcherInformation not implemented\n");
2301 return STATUS_NOT_IMPLEMENTED
;
2305 /* Class 57 - Extended process information */
2306 QSI_DEF(SystemExtendedProcessInformation
)
2309 DPRINT1("NtQuerySystemInformation - SystemExtendedProcessInformation not implemented\n");
2310 return STATUS_NOT_IMPLEMENTED
;
2314 /* Class 58 - Recommended shared ata alignment */
2315 QSI_DEF(SystemRecommendedSharedDataAlignment
)
2318 DPRINT1("NtQuerySystemInformation - SystemRecommendedSharedDataAlignment not implemented\n");
2319 return STATUS_NOT_IMPLEMENTED
;
2323 /* Class 60 - NUMA memory information */
2324 QSI_DEF(SystemNumaAvailableMemory
)
2326 ULONG MaxEntries
, Node
;
2327 PSYSTEM_NUMA_INFORMATION NumaInformation
= (PSYSTEM_NUMA_INFORMATION
)Buffer
;
2329 /* Validate input size */
2330 if (Size
< sizeof(ULONG
))
2332 return STATUS_INFO_LENGTH_MISMATCH
;
2335 /* Return highest node */
2336 NumaInformation
->HighestNodeNumber
= KeNumberNodes
- 1;
2338 /* Compute how much entries we will be able to put in output structure */
2339 MaxEntries
= (Size
- FIELD_OFFSET(SYSTEM_NUMA_INFORMATION
, AvailableMemory
)) / sizeof(ULONGLONG
);
2340 /* Make sure we don't overflow KeNodeBlock */
2341 if (MaxEntries
> KeNumberNodes
)
2343 MaxEntries
= KeNumberNodes
;
2346 /* If we have entries to write, and room for it */
2347 if (Size
>= FIELD_OFFSET(SYSTEM_NUMA_INFORMATION
, AvailableMemory
) &&
2350 /* Already set size we return */
2351 *ReqSize
= FIELD_OFFSET(SYSTEM_NUMA_INFORMATION
, AvailableMemory
) +
2352 MaxEntries
* sizeof(ULONGLONG
);
2354 /* If we have a single entry (us), directly return MM information */
2355 if (MaxEntries
== 1)
2357 NumaInformation
->AvailableMemory
[0] = MmAvailablePages
<< PAGE_SHIFT
;
2361 /* Otherwise, for each node, return available bytes */
2362 for (Node
= 0; Node
< MaxEntries
; ++Node
)
2364 NumaInformation
->AvailableMemory
[Node
] = (KeNodeBlock
[Node
]->FreeCount
[0] + KeNodeBlock
[Node
]->FreeCount
[1]) << PAGE_SHIFT
;
2370 /* We only returned highest node number */
2371 *ReqSize
= sizeof(ULONG
);
2374 return STATUS_SUCCESS
;
2378 /* Query/Set Calls Table */
2382 NTSTATUS (* Query
) (PVOID
,ULONG
,PULONG
);
2383 NTSTATUS (* Set
) (PVOID
,ULONG
);
2389 // XX unknown behaviour
2391 #define SI_QS(n) {QSI_USE(n),SSI_USE(n)}
2392 #define SI_QX(n) {QSI_USE(n),NULL}
2393 #define SI_XS(n) {NULL,SSI_USE(n)}
2394 #define SI_XX(n) {NULL,NULL}
2400 SI_QX(SystemBasicInformation
),
2401 SI_QX(SystemProcessorInformation
),
2402 SI_QX(SystemPerformanceInformation
),
2403 SI_QX(SystemTimeOfDayInformation
),
2404 SI_QX(SystemPathInformation
), /* should be SI_XX */
2405 SI_QX(SystemProcessInformation
),
2406 SI_QX(SystemCallCountInformation
),
2407 SI_QX(SystemDeviceInformation
),
2408 SI_QX(SystemProcessorPerformanceInformation
),
2409 SI_QS(SystemFlagsInformation
),
2410 SI_QX(SystemCallTimeInformation
), /* should be SI_XX */
2411 SI_QX(SystemModuleInformation
),
2412 SI_QX(SystemLocksInformation
),
2413 SI_QX(SystemStackTraceInformation
), /* should be SI_XX */
2414 SI_QX(SystemPagedPoolInformation
), /* should be SI_XX */
2415 SI_QX(SystemNonPagedPoolInformation
), /* should be SI_XX */
2416 SI_QX(SystemHandleInformation
),
2417 SI_QX(SystemObjectInformation
),
2418 SI_QX(SystemPageFileInformation
),
2419 SI_QX(SystemVdmInstemulInformation
),
2420 SI_QX(SystemVdmBopInformation
), /* it should be SI_XX */
2421 SI_QS(SystemFileCacheInformation
),
2422 SI_QX(SystemPoolTagInformation
),
2423 SI_QX(SystemInterruptInformation
),
2424 SI_QS(SystemDpcBehaviourInformation
),
2425 SI_QX(SystemFullMemoryInformation
), /* it should be SI_XX */
2426 SI_XS(SystemLoadGdiDriverInformation
),
2427 SI_XS(SystemUnloadGdiDriverInformation
),
2428 SI_QS(SystemTimeAdjustmentInformation
),
2429 SI_QX(SystemSummaryMemoryInformation
), /* it should be SI_XX */
2430 SI_QX(SystemNextEventIdInformation
), /* it should be SI_XX */
2431 SI_QX(SystemPerformanceTraceInformation
), /* it should be SI_XX */
2432 SI_QX(SystemCrashDumpInformation
),
2433 SI_QX(SystemExceptionInformation
),
2434 SI_QX(SystemCrashDumpStateInformation
),
2435 SI_QX(SystemKernelDebuggerInformation
),
2436 SI_QX(SystemContextSwitchInformation
),
2437 SI_QS(SystemRegistryQuotaInformation
),
2438 SI_XS(SystemExtendServiceTableInformation
),
2439 SI_XS(SystemPrioritySeperation
),
2440 SI_QX(SystemVerifierAddDriverInformation
), /* it should be SI_XX */
2441 SI_QX(SystemVerifierRemoveDriverInformation
), /* it should be SI_XX */
2442 SI_QX(SystemProcessorIdleInformation
), /* it should be SI_XX */
2443 SI_QX(SystemLegacyDriverInformation
), /* it should be SI_XX */
2444 SI_QS(SystemCurrentTimeZoneInformation
), /* it should be SI_QX */
2445 SI_QX(SystemLookasideInformation
),
2446 SI_XS(SystemTimeSlipNotification
),
2447 SI_XS(SystemSessionCreate
),
2448 SI_XS(SystemSessionDetach
),
2449 SI_QX(SystemSessionInformation
), /* it should be SI_XX */
2450 SI_QX(SystemRangeStartInformation
),
2451 SI_QS(SystemVerifierInformation
),
2452 SI_XS(SystemVerifierThunkExtend
),
2453 SI_QX(SystemSessionProcessesInformation
),
2454 SI_XS(SystemLoadGdiDriverInSystemSpaceInformation
),
2455 SI_QX(SystemNumaProcessorMap
),
2456 SI_QX(SystemPrefetcherInformation
),
2457 SI_QX(SystemExtendedProcessInformation
),
2458 SI_QX(SystemRecommendedSharedDataAlignment
),
2459 SI_XX(SystemComPlusPackage
),
2460 SI_QX(SystemNumaAvailableMemory
)
2463 C_ASSERT(SystemBasicInformation
== 0);
2464 #define MIN_SYSTEM_INFO_CLASS (SystemBasicInformation)
2465 #define MAX_SYSTEM_INFO_CLASS (sizeof(CallQS) / sizeof(CallQS[0]))
2471 NtQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInformationClass
,
2472 OUT PVOID SystemInformation
,
2474 OUT PULONG UnsafeResultLength
)
2476 KPROCESSOR_MODE PreviousMode
;
2477 ULONG ResultLength
= 0;
2478 ULONG Alignment
= TYPE_ALIGNMENT(ULONG
);
2479 NTSTATUS FStatus
= STATUS_NOT_IMPLEMENTED
;
2483 PreviousMode
= ExGetPreviousMode();
2487 #if (NTDDI_VERSION >= NTDDI_VISTA)
2489 * Check if the request is valid.
2491 if (SystemInformationClass
>= MAX_SYSTEM_INFO_CLASS
)
2493 _SEH2_YIELD(return STATUS_INVALID_INFO_CLASS
);
2497 if (PreviousMode
!= KernelMode
)
2499 /* SystemKernelDebuggerInformation needs only BOOLEAN alignment */
2500 if (SystemInformationClass
== SystemKernelDebuggerInformation
)
2501 Alignment
= TYPE_ALIGNMENT(BOOLEAN
);
2503 ProbeForWrite(SystemInformation
, Length
, Alignment
);
2504 if (UnsafeResultLength
!= NULL
)
2505 ProbeForWriteUlong(UnsafeResultLength
);
2508 if (UnsafeResultLength
)
2509 *UnsafeResultLength
= 0;
2511 #if (NTDDI_VERSION < NTDDI_VISTA)
2513 * Check if the request is valid.
2515 if (SystemInformationClass
>= MAX_SYSTEM_INFO_CLASS
)
2517 _SEH2_YIELD(return STATUS_INVALID_INFO_CLASS
);
2521 if (NULL
!= CallQS
[SystemInformationClass
].Query
)
2524 * Hand the request to a subhandler.
2526 FStatus
= CallQS
[SystemInformationClass
].Query(SystemInformation
,
2530 /* Save the result length to the caller */
2531 if (UnsafeResultLength
)
2532 *UnsafeResultLength
= ResultLength
;
2535 _SEH2_EXCEPT(ExSystemExceptionFilter())
2537 FStatus
= _SEH2_GetExceptionCode();
2547 NtSetSystemInformation (IN SYSTEM_INFORMATION_CLASS SystemInformationClass
,
2548 IN PVOID SystemInformation
,
2549 IN ULONG SystemInformationLength
)
2551 NTSTATUS Status
= STATUS_INVALID_INFO_CLASS
;
2552 KPROCESSOR_MODE PreviousMode
;
2556 PreviousMode
= ExGetPreviousMode();
2561 * If called from user mode, check
2562 * possible unsafe arguments.
2564 if (PreviousMode
!= KernelMode
)
2566 ProbeForRead(SystemInformation
, SystemInformationLength
, sizeof(ULONG
));
2570 * Check the request is valid.
2572 if ((SystemInformationClass
>= MIN_SYSTEM_INFO_CLASS
) &&
2573 (SystemInformationClass
< MAX_SYSTEM_INFO_CLASS
))
2575 if (NULL
!= CallQS
[SystemInformationClass
].Set
)
2578 * Hand the request to a subhandler.
2580 Status
= CallQS
[SystemInformationClass
].Set(SystemInformation
,
2581 SystemInformationLength
);
2585 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2587 Status
= _SEH2_GetExceptionCode();
2596 NtGetCurrentProcessorNumber(VOID
)
2599 return KeGetCurrentProcessorNumber();
2602 #undef ExGetPreviousMode
2605 ExGetPreviousMode(VOID
)
2608 return KeGetPreviousMode();