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 FAST_MUTEX ExpEnvironmentLock
;
18 ERESOURCE ExpFirmwareTableResource
;
19 LIST_ENTRY ExpFirmwareTableProviderListHead
;
23 ExpQueryModuleInformation(IN PLIST_ENTRY KernelModeList
,
24 IN PLIST_ENTRY UserModeList
,
25 OUT PRTL_PROCESS_MODULES Modules
,
27 OUT PULONG ReturnLength
)
29 NTSTATUS Status
= STATUS_SUCCESS
;
31 PRTL_PROCESS_MODULE_INFORMATION ModuleInfo
;
32 PLDR_DATA_TABLE_ENTRY LdrEntry
;
33 ANSI_STRING ModuleName
;
34 ULONG ModuleCount
= 0;
35 PLIST_ENTRY NextEntry
;
39 RequiredLength
= FIELD_OFFSET(RTL_PROCESS_MODULES
, Modules
);
40 ModuleInfo
= &Modules
->Modules
[0];
42 /* Loop the kernel list */
43 NextEntry
= KernelModeList
->Flink
;
44 while (NextEntry
!= KernelModeList
)
47 LdrEntry
= CONTAINING_RECORD(NextEntry
,
51 /* Update size and check if we can manage one more entry */
52 RequiredLength
+= sizeof(RTL_PROCESS_MODULE_INFORMATION
);
53 if (Length
>= RequiredLength
)
56 ModuleInfo
->MappedBase
= NULL
;
57 ModuleInfo
->ImageBase
= LdrEntry
->DllBase
;
58 ModuleInfo
->ImageSize
= LdrEntry
->SizeOfImage
;
59 ModuleInfo
->Flags
= LdrEntry
->Flags
;
60 ModuleInfo
->LoadCount
= LdrEntry
->LoadCount
;
61 ModuleInfo
->LoadOrderIndex
= (USHORT
)ModuleCount
;
62 ModuleInfo
->InitOrderIndex
= 0;
65 RtlInitEmptyAnsiString(&ModuleName
,
66 ModuleInfo
->FullPathName
,
67 sizeof(ModuleInfo
->FullPathName
));
70 Status
= RtlUnicodeStringToAnsiString(&ModuleName
,
71 &LdrEntry
->FullDllName
,
73 if ((NT_SUCCESS(Status
)) || (Status
== STATUS_BUFFER_OVERFLOW
))
75 /* Calculate offset to name */
76 p
= ModuleName
.Buffer
+ ModuleName
.Length
;
77 while ((p
> ModuleName
.Buffer
) && (*--p
))
79 /* Check if we found the separator */
80 if (*p
== OBJ_NAME_PATH_SEPARATOR
)
82 /* We did, break out */
89 ModuleInfo
->OffsetToFileName
= (USHORT
)(p
- ModuleName
.Buffer
);
93 /* Return empty name */
94 ModuleInfo
->FullPathName
[0] = ANSI_NULL
;
95 ModuleInfo
->OffsetToFileName
= 0;
98 /* Go to the next module */
104 Status
= STATUS_INFO_LENGTH_MISMATCH
;
107 /* Update count and move to next entry */
109 NextEntry
= NextEntry
->Flink
;
112 /* Check if caller also wanted user modules */
116 DPRINT1("User-mode list not yet supported in ReactOS!\n");
119 /* Update return length */
120 if (ReturnLength
) *ReturnLength
= RequiredLength
;
122 /* Validate the length again */
123 if (Length
>= FIELD_OFFSET(RTL_PROCESS_MODULES
, Modules
))
125 /* Set the final count */
126 Modules
->NumberOfModules
= ModuleCount
;
130 /* Otherwise, we failed */
131 Status
= STATUS_INFO_LENGTH_MISMATCH
;
138 /* FUNCTIONS *****************************************************************/
145 ExGetCurrentProcessorCpuUsage(PULONG CpuUsage
)
149 ULONGLONG ScaledIdle
;
151 Prcb
= KeGetCurrentPrcb();
153 ScaledIdle
= Prcb
->IdleThread
->KernelTime
* 100;
154 TotalTime
= Prcb
->KernelTime
+ Prcb
->UserTime
;
156 *CpuUsage
= (ULONG
)(100 - (ScaledIdle
/ TotalTime
));
166 ExGetCurrentProcessorCounts(PULONG ThreadKernelTime
,
168 PULONG ProcessorNumber
)
172 Prcb
= KeGetCurrentPrcb();
174 *ThreadKernelTime
= Prcb
->KernelTime
+ Prcb
->UserTime
;
175 *TotalCpuTime
= Prcb
->CurrentThread
->KernelTime
;
176 *ProcessorNumber
= KeGetCurrentProcessorNumber();
184 ExIsProcessorFeaturePresent(IN ULONG ProcessorFeature
)
186 /* Quick check to see if it exists at all */
187 if (ProcessorFeature
>= PROCESSOR_FEATURE_MAX
) return(FALSE
);
189 /* Return our support for it */
190 return(SharedUserData
->ProcessorFeatures
[ProcessorFeature
]);
198 ExVerifySuite(SUITE_TYPE SuiteType
)
200 if (SuiteType
== Personal
) return TRUE
;
206 NtQuerySystemEnvironmentValue(IN PUNICODE_STRING VariableName
,
207 OUT PWSTR ValueBuffer
,
208 IN ULONG ValueBufferLength
,
209 IN OUT PULONG ReturnLength OPTIONAL
)
212 UNICODE_STRING WName
;
216 UNICODE_STRING WValue
;
217 KPROCESSOR_MODE PreviousMode
;
221 PreviousMode
= ExGetPreviousMode();
223 if (PreviousMode
!= KernelMode
)
227 ProbeForRead(VariableName
,
228 sizeof(UNICODE_STRING
),
231 ProbeForWrite(ValueBuffer
,
235 if (ReturnLength
!= NULL
) ProbeForWriteUlong(ReturnLength
);
237 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
239 /* Return the exception code */
240 _SEH2_YIELD(return _SEH2_GetExceptionCode());
246 * Copy the name to kernel space if necessary and convert it to ANSI.
248 Status
= ProbeAndCaptureUnicodeString(&WName
,
251 if (NT_SUCCESS(Status
))
254 * according to ntinternals the SeSystemEnvironmentName privilege is required!
256 if (!SeSinglePrivilegeCheck(SeSystemEnvironmentPrivilege
,
259 ReleaseCapturedUnicodeString(&WName
, PreviousMode
);
260 DPRINT1("NtQuerySystemEnvironmentValue: Caller requires the SeSystemEnvironmentPrivilege privilege!\n");
261 return STATUS_PRIVILEGE_NOT_HELD
;
265 * convert the value name to ansi
267 Status
= RtlUnicodeStringToAnsiString(&AName
, &WName
, TRUE
);
268 ReleaseCapturedUnicodeString(&WName
, PreviousMode
);
270 if (!NT_SUCCESS(Status
)) return Status
;
273 * Create a temporary buffer for the value
275 Value
= ExAllocatePool(NonPagedPool
, ValueBufferLength
);
278 RtlFreeAnsiString(&AName
);
279 return STATUS_INSUFFICIENT_RESOURCES
;
283 * Get the environment variable
285 Result
= HalGetEnvironmentVariable(AName
.Buffer
,
286 (USHORT
)ValueBufferLength
,
290 RtlFreeAnsiString(&AName
);
292 return STATUS_UNSUCCESSFUL
;
296 * Convert the result to UNICODE, protect with SEH in case the value buffer
297 * isn't NULL-terminated!
301 RtlInitAnsiString(&AValue
, Value
);
302 Status
= RtlAnsiStringToUnicodeString(&WValue
, &AValue
, TRUE
);
304 _SEH2_EXCEPT(ExSystemExceptionFilter())
306 Status
= _SEH2_GetExceptionCode();
310 if (NT_SUCCESS(Status
))
313 * Copy the result back to the caller.
317 RtlCopyMemory(ValueBuffer
, WValue
.Buffer
, WValue
.Length
);
318 ValueBuffer
[WValue
.Length
/ sizeof(WCHAR
)] = L
'\0';
319 if (ReturnLength
!= NULL
)
321 *ReturnLength
= WValue
.Length
+ sizeof(WCHAR
);
324 Status
= STATUS_SUCCESS
;
326 _SEH2_EXCEPT(ExSystemExceptionFilter())
328 Status
= _SEH2_GetExceptionCode();
334 * Cleanup allocated resources.
336 RtlFreeAnsiString(&AName
);
346 NtSetSystemEnvironmentValue(IN PUNICODE_STRING VariableName
,
347 IN PUNICODE_STRING Value
)
349 UNICODE_STRING CapturedName
, CapturedValue
;
350 ANSI_STRING AName
, AValue
;
351 KPROCESSOR_MODE PreviousMode
;
356 PreviousMode
= ExGetPreviousMode();
359 * Copy the strings to kernel space if necessary
361 Status
= ProbeAndCaptureUnicodeString(&CapturedName
,
364 if (NT_SUCCESS(Status
))
366 Status
= ProbeAndCaptureUnicodeString(&CapturedValue
,
369 if (NT_SUCCESS(Status
))
372 * according to ntinternals the SeSystemEnvironmentName privilege is required!
374 if (SeSinglePrivilegeCheck(SeSystemEnvironmentPrivilege
,
378 * convert the strings to ANSI
380 Status
= RtlUnicodeStringToAnsiString(&AName
,
383 if (NT_SUCCESS(Status
))
385 Status
= RtlUnicodeStringToAnsiString(&AValue
,
388 if (NT_SUCCESS(Status
))
390 ARC_STATUS Result
= HalSetEnvironmentVariable(AName
.Buffer
,
393 Status
= (Result
? STATUS_SUCCESS
: STATUS_UNSUCCESSFUL
);
399 DPRINT1("NtSetSystemEnvironmentValue: Caller requires the SeSystemEnvironmentPrivilege privilege!\n");
400 Status
= STATUS_PRIVILEGE_NOT_HELD
;
403 ReleaseCapturedUnicodeString(&CapturedValue
,
407 ReleaseCapturedUnicodeString(&CapturedName
,
416 NtEnumerateSystemEnvironmentValuesEx(IN ULONG InformationClass
,
418 IN ULONG BufferLength
)
421 return STATUS_NOT_IMPLEMENTED
;
426 NtQuerySystemEnvironmentValueEx(IN PUNICODE_STRING VariableName
,
427 IN LPGUID VendorGuid
,
429 IN OUT PULONG ReturnLength
,
430 IN OUT PULONG Attributes
)
433 return STATUS_NOT_IMPLEMENTED
;
438 NtSetSystemEnvironmentValueEx(IN PUNICODE_STRING VariableName
,
439 IN LPGUID VendorGuid
)
442 return STATUS_NOT_IMPLEMENTED
;
445 /* --- Query/Set System Information --- */
448 * NOTE: QSI_DEF(n) and SSI_DEF(n) define _cdecl function symbols
449 * so the stack is popped only in one place on x86 platform.
451 #define QSI_USE(n) QSI##n
453 static NTSTATUS QSI_USE(n) (PVOID Buffer, ULONG Size, PULONG ReqSize)
455 #define SSI_USE(n) SSI##n
457 static NTSTATUS SSI_USE(n) (PVOID Buffer, ULONG Size)
460 /* Class 0 - Basic Information */
461 QSI_DEF(SystemBasicInformation
)
463 PSYSTEM_BASIC_INFORMATION Sbi
464 = (PSYSTEM_BASIC_INFORMATION
) Buffer
;
466 *ReqSize
= sizeof(SYSTEM_BASIC_INFORMATION
);
468 /* Check user buffer's size */
469 if (Size
!= sizeof(SYSTEM_BASIC_INFORMATION
))
471 return STATUS_INFO_LENGTH_MISMATCH
;
474 RtlZeroMemory(Sbi
, Size
);
476 Sbi
->TimerResolution
= KeMaximumIncrement
;
477 Sbi
->PageSize
= PAGE_SIZE
;
478 Sbi
->NumberOfPhysicalPages
= MmNumberOfPhysicalPages
;
479 Sbi
->LowestPhysicalPageNumber
= (ULONG
)MmLowestPhysicalPage
;
480 Sbi
->HighestPhysicalPageNumber
= (ULONG
)MmHighestPhysicalPage
;
481 Sbi
->AllocationGranularity
= MM_VIRTMEM_GRANULARITY
; /* hard coded on Intel? */
482 Sbi
->MinimumUserModeAddress
= 0x10000; /* Top of 64k */
483 Sbi
->MaximumUserModeAddress
= (ULONG_PTR
)MmHighestUserAddress
;
484 Sbi
->ActiveProcessorsAffinityMask
= KeActiveProcessors
;
485 Sbi
->NumberOfProcessors
= KeNumberProcessors
;
487 return STATUS_SUCCESS
;
490 /* Class 1 - Processor Information */
491 QSI_DEF(SystemProcessorInformation
)
493 PSYSTEM_PROCESSOR_INFORMATION Spi
494 = (PSYSTEM_PROCESSOR_INFORMATION
) Buffer
;
496 *ReqSize
= sizeof(SYSTEM_PROCESSOR_INFORMATION
);
498 /* Check user buffer's size */
499 if (Size
< sizeof(SYSTEM_PROCESSOR_INFORMATION
))
501 return STATUS_INFO_LENGTH_MISMATCH
;
503 Spi
->ProcessorArchitecture
= KeProcessorArchitecture
;
504 Spi
->ProcessorLevel
= KeProcessorLevel
;
505 Spi
->ProcessorRevision
= KeProcessorRevision
;
507 Spi
->ProcessorFeatureBits
= KeFeatureBits
;
509 DPRINT("Arch %d Level %d Rev 0x%x\n", Spi
->ProcessorArchitecture
,
510 Spi
->ProcessorLevel
, Spi
->ProcessorRevision
);
512 return STATUS_SUCCESS
;
515 /* Class 2 - Performance Information */
516 QSI_DEF(SystemPerformanceInformation
)
518 ULONG IdleUser
, IdleKernel
;
519 PSYSTEM_PERFORMANCE_INFORMATION Spi
520 = (PSYSTEM_PERFORMANCE_INFORMATION
) Buffer
;
522 PEPROCESS TheIdleProcess
;
524 *ReqSize
= sizeof(SYSTEM_PERFORMANCE_INFORMATION
);
526 /* Check user buffer's size */
527 if (Size
< sizeof(SYSTEM_PERFORMANCE_INFORMATION
))
529 return STATUS_INFO_LENGTH_MISMATCH
;
532 TheIdleProcess
= PsIdleProcess
;
534 IdleKernel
= KeQueryRuntimeProcess(&TheIdleProcess
->Pcb
, &IdleUser
);
535 Spi
->IdleProcessTime
.QuadPart
= UInt32x32To64(IdleKernel
, KeMaximumIncrement
);
536 Spi
->IoReadTransferCount
= IoReadTransferCount
;
537 Spi
->IoWriteTransferCount
= IoWriteTransferCount
;
538 Spi
->IoOtherTransferCount
= IoOtherTransferCount
;
539 Spi
->IoReadOperationCount
= IoReadOperationCount
;
540 Spi
->IoWriteOperationCount
= IoWriteOperationCount
;
541 Spi
->IoOtherOperationCount
= IoOtherOperationCount
;
543 Spi
->AvailablePages
= (ULONG
)MmAvailablePages
;
545 * Add up all the used "Committed" memory + pagefile.
546 * Not sure this is right. 8^\
548 Spi
->CommittedPages
= MiMemoryConsumers
[MC_SYSTEM
].PagesUsed
+
549 MiMemoryConsumers
[MC_CACHE
].PagesUsed
+
550 MiMemoryConsumers
[MC_USER
].PagesUsed
+
553 * Add up the full system total + pagefile.
554 * All this make Taskmgr happy but not sure it is the right numbers.
555 * This too, fixes some of GlobalMemoryStatusEx numbers.
557 Spi
->CommitLimit
= MmNumberOfPhysicalPages
+ MiFreeSwapPages
+ MiUsedSwapPages
;
559 Spi
->PeakCommitment
= 0; /* FIXME */
560 Spi
->PageFaultCount
= 0; /* FIXME */
561 Spi
->CopyOnWriteCount
= 0; /* FIXME */
562 Spi
->TransitionCount
= 0; /* FIXME */
563 Spi
->CacheTransitionCount
= 0; /* FIXME */
564 Spi
->DemandZeroCount
= 0; /* FIXME */
565 Spi
->PageReadCount
= 0; /* FIXME */
566 Spi
->PageReadIoCount
= 0; /* FIXME */
567 Spi
->CacheReadCount
= 0; /* FIXME */
568 Spi
->CacheIoCount
= 0; /* FIXME */
569 Spi
->DirtyPagesWriteCount
= 0; /* FIXME */
570 Spi
->DirtyWriteIoCount
= 0; /* FIXME */
571 Spi
->MappedPagesWriteCount
= 0; /* FIXME */
572 Spi
->MappedWriteIoCount
= 0; /* FIXME */
574 Spi
->PagedPoolPages
= 0; /* FIXME */
575 Spi
->PagedPoolAllocs
= 0; /* FIXME */
576 Spi
->PagedPoolFrees
= 0; /* FIXME */
577 Spi
->NonPagedPoolPages
= 0; /* FIXME */
578 Spi
->NonPagedPoolAllocs
= 0; /* FIXME */
579 Spi
->NonPagedPoolFrees
= 0; /* FIXME */
581 Spi
->FreeSystemPtes
= 0; /* FIXME */
583 Spi
->ResidentSystemCodePage
= 0; /* FIXME */
585 Spi
->TotalSystemDriverPages
= 0; /* FIXME */
586 Spi
->TotalSystemCodePages
= 0; /* FIXME */
587 Spi
->NonPagedPoolLookasideHits
= 0; /* FIXME */
588 Spi
->PagedPoolLookasideHits
= 0; /* FIXME */
589 Spi
->Spare3Count
= 0; /* FIXME */
591 Spi
->ResidentSystemCachePage
= MiMemoryConsumers
[MC_CACHE
].PagesUsed
;
592 Spi
->ResidentPagedPoolPage
= 0; /* FIXME */
594 Spi
->ResidentSystemDriverPage
= 0; /* FIXME */
595 Spi
->CcFastReadNoWait
= 0; /* FIXME */
596 Spi
->CcFastReadWait
= 0; /* FIXME */
597 Spi
->CcFastReadResourceMiss
= 0; /* FIXME */
598 Spi
->CcFastReadNotPossible
= 0; /* FIXME */
600 Spi
->CcFastMdlReadNoWait
= 0; /* FIXME */
601 Spi
->CcFastMdlReadWait
= 0; /* FIXME */
602 Spi
->CcFastMdlReadResourceMiss
= 0; /* FIXME */
603 Spi
->CcFastMdlReadNotPossible
= 0; /* FIXME */
605 Spi
->CcMapDataNoWait
= 0; /* FIXME */
606 Spi
->CcMapDataWait
= 0; /* FIXME */
607 Spi
->CcMapDataNoWaitMiss
= 0; /* FIXME */
608 Spi
->CcMapDataWaitMiss
= 0; /* FIXME */
610 Spi
->CcPinMappedDataCount
= 0; /* FIXME */
611 Spi
->CcPinReadNoWait
= 0; /* FIXME */
612 Spi
->CcPinReadWait
= 0; /* FIXME */
613 Spi
->CcPinReadNoWaitMiss
= 0; /* FIXME */
614 Spi
->CcPinReadWaitMiss
= 0; /* FIXME */
615 Spi
->CcCopyReadNoWait
= 0; /* FIXME */
616 Spi
->CcCopyReadWait
= 0; /* FIXME */
617 Spi
->CcCopyReadNoWaitMiss
= 0; /* FIXME */
618 Spi
->CcCopyReadWaitMiss
= 0; /* FIXME */
620 Spi
->CcMdlReadNoWait
= 0; /* FIXME */
621 Spi
->CcMdlReadWait
= 0; /* FIXME */
622 Spi
->CcMdlReadNoWaitMiss
= 0; /* FIXME */
623 Spi
->CcMdlReadWaitMiss
= 0; /* FIXME */
624 Spi
->CcReadAheadIos
= 0; /* FIXME */
625 Spi
->CcLazyWriteIos
= 0; /* FIXME */
626 Spi
->CcLazyWritePages
= 0; /* FIXME */
627 Spi
->CcDataFlushes
= 0; /* FIXME */
628 Spi
->CcDataPages
= 0; /* FIXME */
629 Spi
->ContextSwitches
= 0; /* FIXME */
630 Spi
->FirstLevelTbFills
= 0; /* FIXME */
631 Spi
->SecondLevelTbFills
= 0; /* FIXME */
632 Spi
->SystemCalls
= 0; /* FIXME */
634 return STATUS_SUCCESS
;
637 /* Class 3 - Time Of Day Information */
638 QSI_DEF(SystemTimeOfDayInformation
)
640 SYSTEM_TIMEOFDAY_INFORMATION Sti
;
641 LARGE_INTEGER CurrentTime
;
643 /* Set amount of written information to 0 */
646 /* Check user buffer's size */
647 if (Size
> sizeof(SYSTEM_TIMEOFDAY_INFORMATION
))
649 return STATUS_INFO_LENGTH_MISMATCH
;
652 /* Get current time */
653 KeQuerySystemTime(&CurrentTime
);
655 /* Zero local buffer */
656 RtlZeroMemory(&Sti
, sizeof(SYSTEM_TIMEOFDAY_INFORMATION
));
658 /* Fill local time structure */
659 Sti
.BootTime
= KeBootTime
;
660 Sti
.CurrentTime
= CurrentTime
;
661 Sti
.TimeZoneBias
.QuadPart
= ExpTimeZoneBias
.QuadPart
;
662 Sti
.TimeZoneId
= ExpTimeZoneId
;
665 /* Copy as much as requested by caller */
666 RtlCopyMemory(Buffer
, &Sti
, Size
);
668 /* Set amount of information we copied */
671 return STATUS_SUCCESS
;
674 /* Class 4 - Path Information */
675 QSI_DEF(SystemPathInformation
)
677 /* FIXME: QSI returns STATUS_BREAKPOINT. Why? */
678 DPRINT1("NtQuerySystemInformation - SystemPathInformation not implemented\n");
680 return STATUS_BREAKPOINT
;
683 /* Class 5 - Process Information */
684 QSI_DEF(SystemProcessInformation
)
686 PSYSTEM_PROCESS_INFORMATION SpiCurrent
;
687 PSYSTEM_THREAD_INFORMATION ThreadInfo
;
688 PEPROCESS Process
= NULL
, SystemProcess
;
689 PETHREAD CurrentThread
;
690 ANSI_STRING ImageName
;
692 USHORT ImageNameMaximumLength
; // image name len in bytes
693 USHORT ImageNameLength
;
694 PLIST_ENTRY CurrentEntry
;
695 ULONG TotalSize
= 0, ThreadsCount
;
696 ULONG TotalUser
, TotalKernel
;
698 NTSTATUS Status
= STATUS_SUCCESS
;
699 PUNICODE_STRING ProcessImageName
;
701 BOOLEAN Overflow
= FALSE
;
705 /* scan the process list */
707 PSYSTEM_PROCESS_INFORMATION Spi
708 = (PSYSTEM_PROCESS_INFORMATION
) Buffer
;
710 *ReqSize
= sizeof(SYSTEM_PROCESS_INFORMATION
);
712 /* Check for overflow */
713 if (Size
< sizeof(SYSTEM_PROCESS_INFORMATION
))
716 /* Zero user's buffer */
717 if (!Overflow
) RtlZeroMemory(Spi
, Size
);
719 SystemProcess
= PsIdleProcess
;
720 Process
= SystemProcess
;
721 Current
= (PUCHAR
) Spi
;
725 SpiCurrent
= (PSYSTEM_PROCESS_INFORMATION
) Current
;
728 CurrentEntry
= Process
->ThreadListHead
.Flink
;
729 while (CurrentEntry
!= &Process
->ThreadListHead
)
732 CurrentEntry
= CurrentEntry
->Flink
;
735 // size of the structure for every process
736 CurrentSize
= sizeof(SYSTEM_PROCESS_INFORMATION
) + sizeof(SYSTEM_THREAD_INFORMATION
) * ThreadsCount
;
738 Status
= SeLocateProcessImageName(Process
, &ProcessImageName
);
740 if (NT_SUCCESS(Status
) && (ProcessImageName
->Length
> 0))
742 szSrc
= (PWCHAR
)((PCHAR
)ProcessImageName
->Buffer
+ ProcessImageName
->Length
);
743 /* Loop the file name*/
744 while (szSrc
> ProcessImageName
->Buffer
)
746 /* Make sure this isn't a backslash */
747 if (*--szSrc
== OBJ_NAME_PATH_SEPARATOR
)
754 ImageNameLength
+= sizeof(WCHAR
);
758 if (!ImageNameLength
&& Process
!= PsIdleProcess
&& Process
->ImageFileName
)
760 ImageNameLength
= (USHORT
)strlen(Process
->ImageFileName
) * sizeof(WCHAR
);
763 /* Round up the image name length as NT does */
764 if (ImageNameLength
> 0)
765 ImageNameMaximumLength
= ROUND_UP(ImageNameLength
+ sizeof(WCHAR
), 8);
767 ImageNameMaximumLength
= 0;
769 TotalSize
+= CurrentSize
+ ImageNameMaximumLength
;
771 /* Check for overflow */
772 if (TotalSize
> Size
)
775 /* Fill system information */
778 SpiCurrent
->NextEntryOffset
= CurrentSize
+ ImageNameMaximumLength
; // relative offset to the beginnnig of the next structure
779 SpiCurrent
->NumberOfThreads
= ThreadsCount
;
780 SpiCurrent
->CreateTime
= Process
->CreateTime
;
781 SpiCurrent
->ImageName
.Length
= ImageNameLength
;
782 SpiCurrent
->ImageName
.MaximumLength
= ImageNameMaximumLength
;
783 SpiCurrent
->ImageName
.Buffer
= (void*)(Current
+ CurrentSize
);
785 /* Copy name to the end of the struct */
786 if(Process
!= PsIdleProcess
)
790 RtlCopyMemory(SpiCurrent
->ImageName
.Buffer
, szSrc
, SpiCurrent
->ImageName
.Length
);
792 /* Release the memory allocated by SeLocateProcessImageName */
793 ExFreePool(ProcessImageName
);
795 else if (Process
->ImageFileName
)
797 RtlInitAnsiString(&ImageName
, Process
->ImageFileName
);
798 RtlAnsiStringToUnicodeString(&SpiCurrent
->ImageName
, &ImageName
, FALSE
);
803 RtlInitUnicodeString(&SpiCurrent
->ImageName
, NULL
);
806 SpiCurrent
->BasePriority
= Process
->Pcb
.BasePriority
;
807 SpiCurrent
->UniqueProcessId
= Process
->UniqueProcessId
;
808 SpiCurrent
->InheritedFromUniqueProcessId
= Process
->InheritedFromUniqueProcessId
;
809 SpiCurrent
->HandleCount
= ObGetProcessHandleCount(Process
);
810 SpiCurrent
->PeakVirtualSize
= Process
->PeakVirtualSize
;
811 SpiCurrent
->VirtualSize
= Process
->VirtualSize
;
812 SpiCurrent
->PageFaultCount
= Process
->Vm
.PageFaultCount
;
813 SpiCurrent
->PeakWorkingSetSize
= Process
->Vm
.PeakWorkingSetSize
;
814 SpiCurrent
->WorkingSetSize
= Process
->Vm
.WorkingSetSize
;
815 SpiCurrent
->QuotaPeakPagedPoolUsage
= Process
->QuotaPeak
[0];
816 SpiCurrent
->QuotaPagedPoolUsage
= Process
->QuotaUsage
[0];
817 SpiCurrent
->QuotaPeakNonPagedPoolUsage
= Process
->QuotaPeak
[1];
818 SpiCurrent
->QuotaNonPagedPoolUsage
= Process
->QuotaUsage
[1];
819 SpiCurrent
->PagefileUsage
= Process
->QuotaUsage
[2];
820 SpiCurrent
->PeakPagefileUsage
= Process
->QuotaPeak
[2];
821 SpiCurrent
->PrivatePageCount
= Process
->CommitCharge
;
822 ThreadInfo
= (PSYSTEM_THREAD_INFORMATION
)(SpiCurrent
+ 1);
824 CurrentEntry
= Process
->ThreadListHead
.Flink
;
825 while (CurrentEntry
!= &Process
->ThreadListHead
)
827 CurrentThread
= CONTAINING_RECORD(CurrentEntry
, ETHREAD
,
830 ThreadInfo
->KernelTime
.QuadPart
= UInt32x32To64(CurrentThread
->Tcb
.KernelTime
, KeMaximumIncrement
);
831 ThreadInfo
->UserTime
.QuadPart
= UInt32x32To64(CurrentThread
->Tcb
.UserTime
, KeMaximumIncrement
);
832 ThreadInfo
->CreateTime
.QuadPart
= CurrentThread
->CreateTime
.QuadPart
;
833 ThreadInfo
->WaitTime
= CurrentThread
->Tcb
.WaitTime
;
834 ThreadInfo
->StartAddress
= (PVOID
) CurrentThread
->StartAddress
;
835 ThreadInfo
->ClientId
= CurrentThread
->Cid
;
836 ThreadInfo
->Priority
= CurrentThread
->Tcb
.Priority
;
837 ThreadInfo
->BasePriority
= CurrentThread
->Tcb
.BasePriority
;
838 ThreadInfo
->ContextSwitches
= CurrentThread
->Tcb
.ContextSwitches
;
839 ThreadInfo
->ThreadState
= CurrentThread
->Tcb
.State
;
840 ThreadInfo
->WaitReason
= CurrentThread
->Tcb
.WaitReason
;
843 CurrentEntry
= CurrentEntry
->Flink
;
846 /* Query total user/kernel times of a process */
847 TotalKernel
= KeQueryRuntimeProcess(&Process
->Pcb
, &TotalUser
);
848 SpiCurrent
->UserTime
.QuadPart
= UInt32x32To64(TotalUser
, KeMaximumIncrement
);
849 SpiCurrent
->KernelTime
.QuadPart
= UInt32x32To64(TotalKernel
, KeMaximumIncrement
);
852 /* Handle idle process entry */
853 if (Process
== PsIdleProcess
) Process
= NULL
;
855 Process
= PsGetNextProcess(Process
);
857 if ((Process
== SystemProcess
) || (Process
== NULL
))
860 SpiCurrent
->NextEntryOffset
= 0;
864 Current
+= CurrentSize
+ ImageNameMaximumLength
;
865 } while ((Process
!= SystemProcess
) && (Process
!= NULL
));
868 ObDereferenceObject(Process
);
869 Status
= STATUS_SUCCESS
;
871 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
874 ObDereferenceObject(Process
);
875 Status
= _SEH2_GetExceptionCode();
880 Status
= STATUS_INFO_LENGTH_MISMATCH
;
882 *ReqSize
= TotalSize
;
886 /* Class 6 - Call Count Information */
887 QSI_DEF(SystemCallCountInformation
)
890 DPRINT1("NtQuerySystemInformation - SystemCallCountInformation not implemented\n");
891 return STATUS_NOT_IMPLEMENTED
;
894 /* Class 7 - Device Information */
895 QSI_DEF(SystemDeviceInformation
)
897 PSYSTEM_DEVICE_INFORMATION Sdi
898 = (PSYSTEM_DEVICE_INFORMATION
) Buffer
;
899 PCONFIGURATION_INFORMATION ConfigInfo
;
901 *ReqSize
= sizeof(SYSTEM_DEVICE_INFORMATION
);
903 /* Check user buffer's size */
904 if (Size
< sizeof(SYSTEM_DEVICE_INFORMATION
))
906 return STATUS_INFO_LENGTH_MISMATCH
;
909 ConfigInfo
= IoGetConfigurationInformation();
911 Sdi
->NumberOfDisks
= ConfigInfo
->DiskCount
;
912 Sdi
->NumberOfFloppies
= ConfigInfo
->FloppyCount
;
913 Sdi
->NumberOfCdRoms
= ConfigInfo
->CdRomCount
;
914 Sdi
->NumberOfTapes
= ConfigInfo
->TapeCount
;
915 Sdi
->NumberOfSerialPorts
= ConfigInfo
->SerialCount
;
916 Sdi
->NumberOfParallelPorts
= ConfigInfo
->ParallelCount
;
918 return STATUS_SUCCESS
;
921 /* Class 8 - Processor Performance Information */
922 QSI_DEF(SystemProcessorPerformanceInformation
)
924 PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION Spi
925 = (PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
) Buffer
;
931 *ReqSize
= KeNumberProcessors
* sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
);
933 /* Check user buffer's size */
936 return STATUS_INFO_LENGTH_MISMATCH
;
939 for (i
= 0; i
< KeNumberProcessors
; i
++)
941 /* Get the PRCB on this processor */
942 Prcb
= KiProcessorBlock
[i
];
944 /* Calculate total user and kernel times */
945 TotalTime
= Prcb
->IdleThread
->KernelTime
+ Prcb
->IdleThread
->UserTime
;
946 Spi
->IdleTime
.QuadPart
= UInt32x32To64(TotalTime
, KeMaximumIncrement
);
947 Spi
->KernelTime
.QuadPart
= UInt32x32To64(Prcb
->KernelTime
, KeMaximumIncrement
);
948 Spi
->UserTime
.QuadPart
= UInt32x32To64(Prcb
->UserTime
, KeMaximumIncrement
);
949 Spi
->DpcTime
.QuadPart
= UInt32x32To64(Prcb
->DpcTime
, KeMaximumIncrement
);
950 Spi
->InterruptTime
.QuadPart
= UInt32x32To64(Prcb
->InterruptTime
, KeMaximumIncrement
);
951 Spi
->InterruptCount
= Prcb
->InterruptCount
;
955 return STATUS_SUCCESS
;
958 /* Class 9 - Flags Information */
959 QSI_DEF(SystemFlagsInformation
)
961 if (sizeof(SYSTEM_FLAGS_INFORMATION
) != Size
)
963 *ReqSize
= sizeof(SYSTEM_FLAGS_INFORMATION
);
964 return (STATUS_INFO_LENGTH_MISMATCH
);
966 ((PSYSTEM_FLAGS_INFORMATION
) Buffer
)->Flags
= NtGlobalFlag
;
967 return STATUS_SUCCESS
;
970 SSI_DEF(SystemFlagsInformation
)
972 if (sizeof(SYSTEM_FLAGS_INFORMATION
) != Size
)
974 return STATUS_INFO_LENGTH_MISMATCH
;
976 NtGlobalFlag
= ((PSYSTEM_FLAGS_INFORMATION
) Buffer
)->Flags
;
977 return STATUS_SUCCESS
;
980 /* Class 10 - Call Time Information */
981 QSI_DEF(SystemCallTimeInformation
)
984 DPRINT1("NtQuerySystemInformation - SystemCallTimeInformation not implemented\n");
985 return STATUS_NOT_IMPLEMENTED
;
988 /* Class 11 - Module Information */
989 QSI_DEF(SystemModuleInformation
)
993 /* Acquire system module list lock */
994 KeEnterCriticalRegion();
995 ExAcquireResourceExclusiveLite(&PsLoadedModuleResource
, TRUE
);
997 /* Call the generic handler with the system module list */
998 Status
= ExpQueryModuleInformation(&PsLoadedModuleList
,
999 &MmLoadedUserImageList
,
1000 (PRTL_PROCESS_MODULES
)Buffer
,
1004 /* Release list lock and return status */
1005 ExReleaseResourceLite(&PsLoadedModuleResource
);
1006 KeLeaveCriticalRegion();
1010 /* Class 12 - Locks Information */
1011 QSI_DEF(SystemLocksInformation
)
1014 DPRINT1("NtQuerySystemInformation - SystemLocksInformation not implemented\n");
1015 return STATUS_NOT_IMPLEMENTED
;
1018 /* Class 13 - Stack Trace Information */
1019 QSI_DEF(SystemStackTraceInformation
)
1022 DPRINT1("NtQuerySystemInformation - SystemStackTraceInformation not implemented\n");
1023 return STATUS_NOT_IMPLEMENTED
;
1026 /* Class 14 - Paged Pool Information */
1027 QSI_DEF(SystemPagedPoolInformation
)
1030 DPRINT1("NtQuerySystemInformation - SystemPagedPoolInformation not implemented\n");
1031 return STATUS_NOT_IMPLEMENTED
;
1034 /* Class 15 - Non Paged Pool Information */
1035 QSI_DEF(SystemNonPagedPoolInformation
)
1038 DPRINT1("NtQuerySystemInformation - SystemNonPagedPoolInformation not implemented\n");
1039 return STATUS_NOT_IMPLEMENTED
;
1043 /* Class 16 - Handle Information */
1044 QSI_DEF(SystemHandleInformation
)
1046 PEPROCESS pr
, syspr
;
1047 ULONG curSize
, i
= 0;
1050 PSYSTEM_HANDLE_INFORMATION Shi
=
1051 (PSYSTEM_HANDLE_INFORMATION
) Buffer
;
1053 DPRINT("NtQuerySystemInformation - SystemHandleInformation\n");
1055 if (Size
< sizeof(SYSTEM_HANDLE_INFORMATION
))
1057 *ReqSize
= sizeof(SYSTEM_HANDLE_INFORMATION
);
1058 return STATUS_INFO_LENGTH_MISMATCH
;
1061 DPRINT("SystemHandleInformation 1\n");
1063 /* First Calc Size from Count. */
1064 syspr
= PsGetNextProcess(NULL
);
1069 hCount
= hCount
+ ObGetProcessHandleCount(pr
);
1070 pr
= PsGetNextProcess(pr
);
1072 if ((pr
== syspr
) || (pr
== NULL
)) break;
1074 while ((pr
!= syspr
) && (pr
!= NULL
));
1078 ObDereferenceObject(pr
);
1081 DPRINT("SystemHandleInformation 2\n");
1083 curSize
= sizeof(SYSTEM_HANDLE_INFORMATION
) +
1084 ((sizeof(SYSTEM_HANDLE_TABLE_ENTRY_INFO
) * hCount
) -
1085 (sizeof(SYSTEM_HANDLE_TABLE_ENTRY_INFO
)));
1087 Shi
->NumberOfHandles
= hCount
;
1092 return (STATUS_INFO_LENGTH_MISMATCH
);
1095 DPRINT("SystemHandleInformation 3\n");
1097 /* Now get Handles from all processs. */
1098 syspr
= PsGetNextProcess(NULL
);
1103 int Count
= 0, HandleCount
;
1105 HandleCount
= ObGetProcessHandleCount(pr
);
1107 for (Count
= 0; HandleCount
> 0 ; HandleCount
--)
1109 Shi
->Handles
[i
].UniqueProcessId
= (USHORT
)(ULONG_PTR
)pr
->UniqueProcessId
;
1114 pr
= PsGetNextProcess(pr
);
1116 if ((pr
== syspr
) || (pr
== NULL
)) break;
1118 while ((pr
!= syspr
) && (pr
!= NULL
));
1120 if(pr
!= NULL
) ObDereferenceObject(pr
);
1122 DPRINT("SystemHandleInformation 4\n");
1123 return STATUS_SUCCESS
;
1127 SSI_DEF(SystemHandleInformation)
1130 return STATUS_SUCCESS;
1134 /* Class 17 - Information */
1135 QSI_DEF(SystemObjectInformation
)
1138 DPRINT1("NtQuerySystemInformation - SystemObjectInformation not implemented\n");
1139 return STATUS_NOT_IMPLEMENTED
;
1142 /* Class 18 - Information */
1143 QSI_DEF(SystemPageFileInformation
)
1145 UNICODE_STRING FileName
; /* FIXME */
1146 SYSTEM_PAGEFILE_INFORMATION
*Spfi
= (SYSTEM_PAGEFILE_INFORMATION
*) Buffer
;
1148 if (Size
< sizeof(SYSTEM_PAGEFILE_INFORMATION
))
1150 * ReqSize
= sizeof(SYSTEM_PAGEFILE_INFORMATION
);
1151 return STATUS_INFO_LENGTH_MISMATCH
;
1154 RtlInitUnicodeString(&FileName
, NULL
); /* FIXME */
1157 Spfi
->NextEntryOffset
= 0;
1159 Spfi
->TotalSize
= MiFreeSwapPages
+ MiUsedSwapPages
;
1160 Spfi
->TotalInUse
= MiUsedSwapPages
;
1161 Spfi
->PeakUsage
= MiUsedSwapPages
; /* FIXME */
1162 Spfi
->PageFileName
= FileName
;
1163 return STATUS_SUCCESS
;
1166 /* Class 19 - Vdm Instemul Information */
1167 QSI_DEF(SystemVdmInstemulInformation
)
1170 DPRINT1("NtQuerySystemInformation - SystemVdmInstemulInformation not implemented\n");
1171 return STATUS_NOT_IMPLEMENTED
;
1174 /* Class 20 - Vdm Bop Information */
1175 QSI_DEF(SystemVdmBopInformation
)
1178 DPRINT1("NtQuerySystemInformation - SystemVdmBopInformation not implemented\n");
1179 return STATUS_NOT_IMPLEMENTED
;
1182 /* Class 21 - File Cache Information */
1183 QSI_DEF(SystemFileCacheInformation
)
1185 SYSTEM_FILECACHE_INFORMATION
*Sci
= (SYSTEM_FILECACHE_INFORMATION
*) Buffer
;
1187 if (Size
< sizeof(SYSTEM_FILECACHE_INFORMATION
))
1189 *ReqSize
= sizeof(SYSTEM_FILECACHE_INFORMATION
);
1190 return STATUS_INFO_LENGTH_MISMATCH
;
1193 RtlZeroMemory(Sci
, sizeof(SYSTEM_FILECACHE_INFORMATION
));
1195 /* Return the Byte size not the page size. */
1197 MiMemoryConsumers
[MC_CACHE
].PagesUsed
* PAGE_SIZE
;
1199 MiMemoryConsumers
[MC_CACHE
].PagesUsed
* PAGE_SIZE
; /* FIXME */
1200 /* Taskmgr multiplies this one by page size right away */
1201 Sci
->CurrentSizeIncludingTransitionInPages
=
1202 MiMemoryConsumers
[MC_CACHE
].PagesUsed
; /* FIXME: Should be */
1203 /* system working set and standby pages. */
1204 Sci
->PageFaultCount
= 0; /* FIXME */
1205 Sci
->MinimumWorkingSet
= 0; /* FIXME */
1206 Sci
->MaximumWorkingSet
= 0; /* FIXME */
1208 return STATUS_SUCCESS
;
1211 SSI_DEF(SystemFileCacheInformation
)
1213 if (Size
< sizeof(SYSTEM_FILECACHE_INFORMATION
))
1215 return STATUS_INFO_LENGTH_MISMATCH
;
1218 DPRINT1("NtSetSystemInformation - SystemFileCacheInformation not implemented\n");
1219 return STATUS_NOT_IMPLEMENTED
;
1222 /* Class 22 - Pool Tag Information */
1223 QSI_DEF(SystemPoolTagInformation
)
1226 DPRINT1("NtQuerySystemInformation - SystemPoolTagInformation not implemented\n");
1227 return STATUS_NOT_IMPLEMENTED
;
1230 /* Class 23 - Interrupt Information for all processors */
1231 QSI_DEF(SystemInterruptInformation
)
1236 PSYSTEM_INTERRUPT_INFORMATION sii
= (PSYSTEM_INTERRUPT_INFORMATION
)Buffer
;
1238 if(Size
< KeNumberProcessors
* sizeof(SYSTEM_INTERRUPT_INFORMATION
))
1240 return STATUS_INFO_LENGTH_MISMATCH
;
1243 ti
= KeQueryTimeIncrement();
1245 for (i
= 0; i
< KeNumberProcessors
; i
++)
1247 Prcb
= KiProcessorBlock
[i
];
1248 sii
->ContextSwitches
= KeGetContextSwitches(Prcb
);
1249 sii
->DpcCount
= Prcb
->DpcData
[0].DpcCount
;
1250 sii
->DpcRate
= Prcb
->DpcRequestRate
;
1251 sii
->TimeIncrement
= ti
;
1252 sii
->DpcBypassCount
= 0;
1253 sii
->ApcBypassCount
= 0;
1257 return STATUS_SUCCESS
;
1260 /* Class 24 - DPC Behaviour Information */
1261 QSI_DEF(SystemDpcBehaviourInformation
)
1264 DPRINT1("NtQuerySystemInformation - SystemDpcBehaviourInformation not implemented\n");
1265 return STATUS_NOT_IMPLEMENTED
;
1268 SSI_DEF(SystemDpcBehaviourInformation
)
1271 DPRINT1("NtSetSystemInformation - SystemDpcBehaviourInformation not implemented\n");
1272 return STATUS_NOT_IMPLEMENTED
;
1275 /* Class 25 - Full Memory Information */
1276 QSI_DEF(SystemFullMemoryInformation
)
1278 PULONG Spi
= (PULONG
) Buffer
;
1280 PEPROCESS TheIdleProcess
;
1282 *ReqSize
= sizeof(ULONG
);
1284 if (sizeof(ULONG
) != Size
)
1286 return STATUS_INFO_LENGTH_MISMATCH
;
1289 DPRINT("SystemFullMemoryInformation\n");
1291 TheIdleProcess
= PsIdleProcess
;
1293 DPRINT("PID: %d, KernelTime: %u PFFree: %d PFUsed: %d\n",
1294 TheIdleProcess
->UniqueProcessId
,
1295 TheIdleProcess
->Pcb
.KernelTime
,
1299 *Spi
= MiMemoryConsumers
[MC_USER
].PagesUsed
;
1301 return STATUS_SUCCESS
;
1304 /* Class 26 - Load Image */
1305 SSI_DEF(SystemLoadGdiDriverInformation
)
1307 PSYSTEM_GDI_DRIVER_INFORMATION DriverInfo
= (PVOID
)Buffer
;
1308 UNICODE_STRING ImageName
;
1310 PVOID SectionPointer
;
1311 ULONG_PTR EntryPoint
;
1314 PIMAGE_NT_HEADERS NtHeader
;
1317 if (Size
!= sizeof(SYSTEM_GDI_DRIVER_INFORMATION
))
1319 /* Incorrect buffer length, fail */
1320 return STATUS_INFO_LENGTH_MISMATCH
;
1323 /* Only kernel mode can call this function */
1324 if (ExGetPreviousMode() != KernelMode
) return STATUS_PRIVILEGE_NOT_HELD
;
1326 /* Load the driver */
1327 ImageName
= DriverInfo
->DriverName
;
1328 Status
= MmLoadSystemImage(&ImageName
,
1334 if (!NT_SUCCESS(Status
)) return Status
;
1336 /* Return the export pointer */
1337 DriverInfo
->ExportSectionPointer
=
1338 RtlImageDirectoryEntryToData(ImageBase
,
1340 IMAGE_DIRECTORY_ENTRY_EXPORT
,
1343 /* Get the entrypoint */
1344 NtHeader
= RtlImageNtHeader(ImageBase
);
1345 EntryPoint
= NtHeader
->OptionalHeader
.AddressOfEntryPoint
;
1346 EntryPoint
+= (ULONG_PTR
)ImageBase
;
1348 /* Save other data */
1349 DriverInfo
->ImageAddress
= ImageBase
;
1350 DriverInfo
->SectionPointer
= SectionPointer
;
1351 DriverInfo
->EntryPoint
= (PVOID
)EntryPoint
;
1352 DriverInfo
->ImageLength
= NtHeader
->OptionalHeader
.SizeOfImage
;
1355 return STATUS_SUCCESS
;
1358 /* Class 27 - Unload Image */
1359 SSI_DEF(SystemUnloadGdiDriverInformation
)
1361 PVOID SectionPointer
= Buffer
;
1364 if (Size
!= sizeof(PVOID
))
1366 /* Incorrect length, fail */
1367 return STATUS_INFO_LENGTH_MISMATCH
;
1370 /* Only kernel mode can call this function */
1371 if (ExGetPreviousMode() != KernelMode
) return STATUS_PRIVILEGE_NOT_HELD
;
1373 /* Unload the image */
1374 MmUnloadSystemImage(SectionPointer
);
1375 return STATUS_SUCCESS
;
1378 /* Class 28 - Time Adjustment Information */
1379 QSI_DEF(SystemTimeAdjustmentInformation
)
1381 PSYSTEM_QUERY_TIME_ADJUST_INFORMATION TimeInfo
=
1382 (PSYSTEM_QUERY_TIME_ADJUST_INFORMATION
)Buffer
;
1384 /* Check if enough storage was provided */
1385 if (sizeof(SYSTEM_QUERY_TIME_ADJUST_INFORMATION
) > Size
)
1387 * ReqSize
= sizeof(SYSTEM_QUERY_TIME_ADJUST_INFORMATION
);
1388 return STATUS_INFO_LENGTH_MISMATCH
;
1391 /* Give time values to our caller */
1392 TimeInfo
->TimeIncrement
= KeMaximumIncrement
;
1393 TimeInfo
->TimeAdjustment
= KeTimeAdjustment
;
1394 TimeInfo
->Enable
= !KiTimeAdjustmentEnabled
;
1396 return STATUS_SUCCESS
;
1399 SSI_DEF(SystemTimeAdjustmentInformation
)
1401 KPROCESSOR_MODE PreviousMode
= KeGetPreviousMode();
1402 PSYSTEM_SET_TIME_ADJUST_INFORMATION TimeInfo
=
1403 (PSYSTEM_SET_TIME_ADJUST_INFORMATION
)Buffer
;
1405 /* Check size of a buffer, it must match our expectations */
1406 if (sizeof(SYSTEM_SET_TIME_ADJUST_INFORMATION
) != Size
)
1407 return STATUS_INFO_LENGTH_MISMATCH
;
1409 /* Check who is calling */
1410 if (PreviousMode
!= KernelMode
)
1412 /* Check access rights */
1413 if (!SeSinglePrivilegeCheck(SeSystemtimePrivilege
, PreviousMode
))
1415 return STATUS_PRIVILEGE_NOT_HELD
;
1419 /* FIXME: behaviour suggests the member be named 'Disable' */
1420 if (TimeInfo
->Enable
)
1422 /* Disable time adjustment and set default value */
1423 KiTimeAdjustmentEnabled
= FALSE
;
1424 KeTimeAdjustment
= KeMaximumIncrement
;
1428 /* Check if a valid time adjustment value is given */
1429 if (TimeInfo
->TimeAdjustment
== 0) return STATUS_INVALID_PARAMETER_2
;
1431 /* Enable time adjustment and set the adjustment value */
1432 KiTimeAdjustmentEnabled
= TRUE
;
1433 KeTimeAdjustment
= TimeInfo
->TimeAdjustment
;
1436 return STATUS_SUCCESS
;
1439 /* Class 29 - Summary Memory Information */
1440 QSI_DEF(SystemSummaryMemoryInformation
)
1443 DPRINT1("NtQuerySystemInformation - SystemSummaryMemoryInformation not implemented\n");
1444 return STATUS_NOT_IMPLEMENTED
;
1447 /* Class 30 - Next Event Id Information */
1448 QSI_DEF(SystemNextEventIdInformation
)
1451 DPRINT1("NtQuerySystemInformation - SystemNextEventIdInformation not implemented\n");
1452 return STATUS_NOT_IMPLEMENTED
;
1455 /* Class 31 - Event Ids Information */
1456 QSI_DEF(SystemEventIdsInformation
)
1459 DPRINT1("NtQuerySystemInformation - SystemEventIdsInformation not implemented\n");
1460 return STATUS_NOT_IMPLEMENTED
;
1463 /* Class 32 - Crash Dump Information */
1464 QSI_DEF(SystemCrashDumpInformation
)
1467 DPRINT1("NtQuerySystemInformation - SystemCrashDumpInformation not implemented\n");
1468 return STATUS_NOT_IMPLEMENTED
;
1471 /* Class 33 - Exception Information */
1472 QSI_DEF(SystemExceptionInformation
)
1474 PSYSTEM_EXCEPTION_INFORMATION ExceptionInformation
=
1475 (PSYSTEM_EXCEPTION_INFORMATION
)Buffer
;
1477 ULONG AlignmentFixupCount
= 0, ExceptionDispatchCount
= 0;
1478 ULONG FloatingEmulationCount
= 0, ByteWordEmulationCount
= 0;
1481 /* Check size of a buffer, it must match our expectations */
1482 if (sizeof(SYSTEM_EXCEPTION_INFORMATION
) != Size
)
1483 return STATUS_INFO_LENGTH_MISMATCH
;
1485 /* Sum up exception count information from all processors */
1486 for (i
= 0; i
< KeNumberProcessors
; i
++)
1488 Prcb
= KiProcessorBlock
[i
];
1491 AlignmentFixupCount
+= Prcb
->KeAlignmentFixupCount
;
1492 ExceptionDispatchCount
+= Prcb
->KeExceptionDispatchCount
;
1493 FloatingEmulationCount
+= Prcb
->KeFloatingEmulationCount
;
1497 /* Save information in user's buffer */
1498 ExceptionInformation
->AlignmentFixupCount
= AlignmentFixupCount
;
1499 ExceptionInformation
->ExceptionDispatchCount
= ExceptionDispatchCount
;
1500 ExceptionInformation
->FloatingEmulationCount
= FloatingEmulationCount
;
1501 ExceptionInformation
->ByteWordEmulationCount
= ByteWordEmulationCount
;
1503 return STATUS_SUCCESS
;
1506 /* Class 34 - Crash Dump State Information */
1507 QSI_DEF(SystemCrashDumpStateInformation
)
1510 DPRINT1("NtQuerySystemInformation - SystemCrashDumpStateInformation not implemented\n");
1511 return STATUS_NOT_IMPLEMENTED
;
1514 /* Class 35 - Kernel Debugger Information */
1515 QSI_DEF(SystemKernelDebuggerInformation
)
1517 PSYSTEM_KERNEL_DEBUGGER_INFORMATION skdi
= (PSYSTEM_KERNEL_DEBUGGER_INFORMATION
) Buffer
;
1519 *ReqSize
= sizeof(SYSTEM_KERNEL_DEBUGGER_INFORMATION
);
1520 if (Size
< sizeof(SYSTEM_KERNEL_DEBUGGER_INFORMATION
))
1522 return STATUS_INFO_LENGTH_MISMATCH
;
1525 skdi
->KernelDebuggerEnabled
= KD_DEBUGGER_ENABLED
;
1526 skdi
->KernelDebuggerNotPresent
= KD_DEBUGGER_NOT_PRESENT
;
1528 return STATUS_SUCCESS
;
1531 /* Class 36 - Context Switch Information */
1532 QSI_DEF(SystemContextSwitchInformation
)
1534 PSYSTEM_CONTEXT_SWITCH_INFORMATION ContextSwitchInformation
=
1535 (PSYSTEM_CONTEXT_SWITCH_INFORMATION
)Buffer
;
1536 ULONG ContextSwitches
;
1540 /* Check size of a buffer, it must match our expectations */
1541 if (sizeof(SYSTEM_CONTEXT_SWITCH_INFORMATION
) != Size
)
1542 return STATUS_INFO_LENGTH_MISMATCH
;
1544 /* Calculate total value of context switches across all processors */
1545 ContextSwitches
= 0;
1546 for (i
= 0; i
< KeNumberProcessors
; i
++)
1548 Prcb
= KiProcessorBlock
[i
];
1551 ContextSwitches
+= KeGetContextSwitches(Prcb
);
1555 ContextSwitchInformation
->ContextSwitches
= ContextSwitches
;
1558 ContextSwitchInformation
->FindAny
= 0;
1559 ContextSwitchInformation
->FindLast
= 0;
1560 ContextSwitchInformation
->FindIdeal
= 0;
1561 ContextSwitchInformation
->IdleAny
= 0;
1562 ContextSwitchInformation
->IdleCurrent
= 0;
1563 ContextSwitchInformation
->IdleLast
= 0;
1564 ContextSwitchInformation
->IdleIdeal
= 0;
1565 ContextSwitchInformation
->PreemptAny
= 0;
1566 ContextSwitchInformation
->PreemptCurrent
= 0;
1567 ContextSwitchInformation
->PreemptLast
= 0;
1568 ContextSwitchInformation
->SwitchToIdle
= 0;
1570 return STATUS_SUCCESS
;
1573 /* Class 37 - Registry Quota Information */
1574 QSI_DEF(SystemRegistryQuotaInformation
)
1576 PSYSTEM_REGISTRY_QUOTA_INFORMATION srqi
= (PSYSTEM_REGISTRY_QUOTA_INFORMATION
) Buffer
;
1578 *ReqSize
= sizeof(SYSTEM_REGISTRY_QUOTA_INFORMATION
);
1579 if (Size
< sizeof(SYSTEM_REGISTRY_QUOTA_INFORMATION
))
1581 return STATUS_INFO_LENGTH_MISMATCH
;
1584 DPRINT1("Faking max registry size of 32 MB\n");
1585 srqi
->RegistryQuotaAllowed
= 0x2000000;
1586 srqi
->RegistryQuotaUsed
= 0x200000;
1587 srqi
->PagedPoolSize
= 0x200000;
1589 return STATUS_SUCCESS
;
1592 SSI_DEF(SystemRegistryQuotaInformation
)
1595 DPRINT1("NtSetSystemInformation - SystemRegistryQuotaInformation not implemented\n");
1596 return STATUS_NOT_IMPLEMENTED
;
1599 /* Class 38 - Load And Call Image */
1600 SSI_DEF(SystemExtendServiceTableInformation
)
1602 UNICODE_STRING ImageName
;
1603 KPROCESSOR_MODE PreviousMode
= KeGetPreviousMode();
1604 PLDR_DATA_TABLE_ENTRY ModuleObject
;
1606 PIMAGE_NT_HEADERS NtHeader
;
1607 DRIVER_OBJECT Win32k
;
1608 PDRIVER_INITIALIZE DriverInit
;
1610 ULONG_PTR EntryPoint
;
1612 /* Validate the size */
1613 if (Size
!= sizeof(UNICODE_STRING
)) return STATUS_INFO_LENGTH_MISMATCH
;
1615 /* Check who is calling */
1616 if (PreviousMode
!= KernelMode
)
1618 /* Make sure we can load drivers */
1619 if (!SeSinglePrivilegeCheck(SeLoadDriverPrivilege
, UserMode
))
1621 /* FIXME: We can't, fail */
1622 //return STATUS_PRIVILEGE_NOT_HELD;
1626 /* Probe and capture the driver name */
1627 ProbeAndCaptureUnicodeString(&ImageName
, PreviousMode
, Buffer
);
1629 /* Load the image */
1630 Status
= MmLoadSystemImage(&ImageName
,
1634 (PVOID
)&ModuleObject
,
1637 /* Release String */
1638 ReleaseCapturedUnicodeString(&ImageName
, PreviousMode
);
1640 if (!NT_SUCCESS(Status
)) return Status
;
1642 /* Get the headers */
1643 NtHeader
= RtlImageNtHeader(ImageBase
);
1647 MmUnloadSystemImage(ModuleObject
);
1648 return STATUS_INVALID_IMAGE_FORMAT
;
1651 /* Get the entrypoint */
1652 EntryPoint
= NtHeader
->OptionalHeader
.AddressOfEntryPoint
;
1653 EntryPoint
+= (ULONG_PTR
)ImageBase
;
1654 DriverInit
= (PDRIVER_INITIALIZE
)EntryPoint
;
1656 /* Create a dummy device */
1657 RtlZeroMemory(&Win32k
, sizeof(Win32k
));
1658 ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL
);
1659 Win32k
.DriverStart
= ImageBase
;
1662 Status
= (DriverInit
)(&Win32k
, NULL
);
1663 ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL
);
1665 /* Unload if we failed */
1666 if (!NT_SUCCESS(Status
)) MmUnloadSystemImage(ModuleObject
);
1670 /* Class 39 - Priority Separation */
1671 SSI_DEF(SystemPrioritySeperation
)
1674 DPRINT1("NtSetSystemInformation - SystemPrioritySeperation not implemented\n");
1675 return STATUS_NOT_IMPLEMENTED
;
1678 /* Class 40 - Plug Play Bus Information */
1679 QSI_DEF(SystemPlugPlayBusInformation
)
1682 DPRINT1("NtQuerySystemInformation - SystemPlugPlayBusInformation not implemented\n");
1683 return STATUS_NOT_IMPLEMENTED
;
1686 /* Class 41 - Dock Information */
1687 QSI_DEF(SystemDockInformation
)
1690 DPRINT1("NtQuerySystemInformation - SystemDockInformation not implemented\n");
1691 return STATUS_NOT_IMPLEMENTED
;
1694 /* Class 42 - Power Information */
1695 QSI_DEF(SystemPowerInformation
)
1698 DPRINT1("NtQuerySystemInformation - SystemPowerInformation not implemented\n");
1699 return STATUS_NOT_IMPLEMENTED
;
1702 /* Class 43 - Processor Speed Information */
1703 QSI_DEF(SystemProcessorSpeedInformation
)
1706 DPRINT1("NtQuerySystemInformation - SystemProcessorSpeedInformation not implemented\n");
1707 return STATUS_NOT_IMPLEMENTED
;
1710 /* Class 44 - Current Time Zone Information */
1711 QSI_DEF(SystemCurrentTimeZoneInformation
)
1713 *ReqSize
= sizeof(TIME_ZONE_INFORMATION
);
1715 if (sizeof(TIME_ZONE_INFORMATION
) != Size
)
1717 return STATUS_INFO_LENGTH_MISMATCH
;
1720 /* Copy the time zone information struct */
1723 sizeof(TIME_ZONE_INFORMATION
));
1725 return STATUS_SUCCESS
;
1729 SSI_DEF(SystemCurrentTimeZoneInformation
)
1731 /* Check user buffer's size */
1732 if (Size
< sizeof(TIME_ZONE_INFORMATION
))
1734 return STATUS_INFO_LENGTH_MISMATCH
;
1737 return ExpSetTimeZoneInformation((PTIME_ZONE_INFORMATION
)Buffer
);
1741 /* Class 45 - Lookaside Information */
1742 QSI_DEF(SystemLookasideInformation
)
1745 DPRINT1("NtQuerySystemInformation - SystemLookasideInformation not implemented\n");
1746 return STATUS_NOT_IMPLEMENTED
;
1750 /* Class 46 - Set time slip event */
1751 SSI_DEF(SystemSetTimeSlipEvent
)
1754 DPRINT1("NtSetSystemInformation - SystemSetTimSlipEvent not implemented\n");
1755 return STATUS_NOT_IMPLEMENTED
;
1760 MmSessionCreate(OUT PULONG SessionId
);
1762 /* Class 47 - Create a new session (TSE) */
1763 SSI_DEF(SystemCreateSession
)
1766 KPROCESSOR_MODE PreviousMode
= KeGetPreviousMode();
1769 if (Size
!= sizeof(ULONG
)) return STATUS_INFO_LENGTH_MISMATCH
;
1771 if (PreviousMode
!= KernelMode
)
1773 if (!SeSinglePrivilegeCheck(SeLoadDriverPrivilege
, PreviousMode
))
1775 return STATUS_PRIVILEGE_NOT_HELD
;
1779 Status
= MmSessionCreate(&SessionId
);
1780 if (NT_SUCCESS(Status
)) *(PULONG
)Buffer
= SessionId
;
1786 /* Class 48 - Delete an existing session (TSE) */
1787 SSI_DEF(SystemDeleteSession
)
1790 DPRINT1("NtSetSystemInformation - SystemDeleteSession not implemented\n");
1791 return STATUS_NOT_IMPLEMENTED
;
1795 /* Class 49 - UNKNOWN */
1796 QSI_DEF(SystemInvalidInfoClass4
)
1799 DPRINT1("NtQuerySystemInformation - SystemInvalidInfoClass4 not implemented\n");
1800 return STATUS_NOT_IMPLEMENTED
;
1804 /* Class 50 - System range start address */
1805 QSI_DEF(SystemRangeStartInformation
)
1807 /* Check user buffer's size */
1808 if (Size
!= sizeof(ULONG_PTR
)) return STATUS_INFO_LENGTH_MISMATCH
;
1810 *(PULONG_PTR
)Buffer
= (ULONG_PTR
)MmSystemRangeStart
;
1812 if (ReqSize
) *ReqSize
= sizeof(ULONG_PTR
);
1814 return STATUS_SUCCESS
;
1817 /* Class 51 - Driver verifier information */
1818 QSI_DEF(SystemVerifierInformation
)
1821 DPRINT1("NtQuerySystemInformation - SystemVerifierInformation not implemented\n");
1822 return STATUS_NOT_IMPLEMENTED
;
1826 SSI_DEF(SystemVerifierInformation
)
1829 DPRINT1("NtSetSystemInformation - SystemVerifierInformation not implemented\n");
1830 return STATUS_NOT_IMPLEMENTED
;
1834 /* Class 52 - Add a driver verifier */
1835 SSI_DEF(SystemAddVerifier
)
1838 DPRINT1("NtSetSystemInformation - SystemAddVerifier not implemented\n");
1839 return STATUS_NOT_IMPLEMENTED
;
1843 /* Class 53 - A session's processes */
1844 QSI_DEF(SystemSessionProcessesInformation
)
1847 DPRINT1("NtQuerySystemInformation - SystemSessionProcessInformation not implemented\n");
1848 return STATUS_NOT_IMPLEMENTED
;
1852 /* Query/Set Calls Table */
1856 NTSTATUS (* Query
) (PVOID
,ULONG
,PULONG
);
1857 NTSTATUS (* Set
) (PVOID
,ULONG
);
1864 // XX unknown behaviour
1866 #define SI_QS(n) {QSI_USE(n),SSI_USE(n)}
1867 #define SI_QX(n) {QSI_USE(n),NULL}
1868 #define SI_XS(n) {NULL,SSI_USE(n)}
1869 #define SI_XX(n) {NULL,NULL}
1875 SI_QX(SystemBasicInformation
),
1876 SI_QX(SystemProcessorInformation
),
1877 SI_QX(SystemPerformanceInformation
),
1878 SI_QX(SystemTimeOfDayInformation
),
1879 SI_QX(SystemPathInformation
), /* should be SI_XX */
1880 SI_QX(SystemProcessInformation
),
1881 SI_QX(SystemCallCountInformation
),
1882 SI_QX(SystemDeviceInformation
),
1883 SI_QX(SystemProcessorPerformanceInformation
),
1884 SI_QS(SystemFlagsInformation
),
1885 SI_QX(SystemCallTimeInformation
), /* should be SI_XX */
1886 SI_QX(SystemModuleInformation
),
1887 SI_QX(SystemLocksInformation
),
1888 SI_QX(SystemStackTraceInformation
), /* should be SI_XX */
1889 SI_QX(SystemPagedPoolInformation
), /* should be SI_XX */
1890 SI_QX(SystemNonPagedPoolInformation
), /* should be SI_XX */
1891 SI_QX(SystemHandleInformation
),
1892 SI_QX(SystemObjectInformation
),
1893 SI_QX(SystemPageFileInformation
),
1894 SI_QX(SystemVdmInstemulInformation
),
1895 SI_QX(SystemVdmBopInformation
), /* it should be SI_XX */
1896 SI_QS(SystemFileCacheInformation
),
1897 SI_QX(SystemPoolTagInformation
),
1898 SI_QX(SystemInterruptInformation
),
1899 SI_QS(SystemDpcBehaviourInformation
),
1900 SI_QX(SystemFullMemoryInformation
), /* it should be SI_XX */
1901 SI_XS(SystemLoadGdiDriverInformation
),
1902 SI_XS(SystemUnloadGdiDriverInformation
),
1903 SI_QS(SystemTimeAdjustmentInformation
),
1904 SI_QX(SystemSummaryMemoryInformation
), /* it should be SI_XX */
1905 SI_QX(SystemNextEventIdInformation
), /* it should be SI_XX */
1906 SI_QX(SystemEventIdsInformation
), /* it should be SI_XX */
1907 SI_QX(SystemCrashDumpInformation
),
1908 SI_QX(SystemExceptionInformation
),
1909 SI_QX(SystemCrashDumpStateInformation
),
1910 SI_QX(SystemKernelDebuggerInformation
),
1911 SI_QX(SystemContextSwitchInformation
),
1912 SI_QS(SystemRegistryQuotaInformation
),
1913 SI_XS(SystemExtendServiceTableInformation
),
1914 SI_XS(SystemPrioritySeperation
),
1915 SI_QX(SystemPlugPlayBusInformation
), /* it should be SI_XX */
1916 SI_QX(SystemDockInformation
), /* it should be SI_XX */
1917 SI_QX(SystemPowerInformation
), /* it should be SI_XX */
1918 SI_QX(SystemProcessorSpeedInformation
), /* it should be SI_XX */
1919 SI_QS(SystemCurrentTimeZoneInformation
), /* it should be SI_QX */
1920 SI_QX(SystemLookasideInformation
),
1921 SI_XS(SystemSetTimeSlipEvent
),
1922 SI_XS(SystemCreateSession
),
1923 SI_XS(SystemDeleteSession
),
1924 SI_QX(SystemInvalidInfoClass4
), /* it should be SI_XX */
1925 SI_QX(SystemRangeStartInformation
),
1926 SI_QS(SystemVerifierInformation
),
1927 SI_XS(SystemAddVerifier
),
1928 SI_QX(SystemSessionProcessesInformation
)
1931 C_ASSERT(SystemBasicInformation
== 0);
1932 #define MIN_SYSTEM_INFO_CLASS (SystemBasicInformation)
1933 #define MAX_SYSTEM_INFO_CLASS (sizeof(CallQS) / sizeof(CallQS[0]))
1939 NtQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInformationClass
,
1940 OUT PVOID SystemInformation
,
1942 OUT PULONG UnsafeResultLength
)
1944 KPROCESSOR_MODE PreviousMode
;
1946 NTSTATUS FStatus
= STATUS_NOT_IMPLEMENTED
;
1950 PreviousMode
= ExGetPreviousMode();
1954 if (PreviousMode
!= KernelMode
)
1956 /* SystemKernelDebuggerInformation needs only BOOLEAN alignment */
1957 ProbeForWrite(SystemInformation
, Length
, 1);
1958 if (UnsafeResultLength
!= NULL
)
1959 ProbeForWriteUlong(UnsafeResultLength
);
1963 * Check the request is valid.
1965 if (SystemInformationClass
>= MAX_SYSTEM_INFO_CLASS
)
1967 _SEH2_YIELD(return STATUS_INVALID_INFO_CLASS
);
1970 if (NULL
!= CallQS
[SystemInformationClass
].Query
)
1973 * Hand the request to a subhandler.
1975 FStatus
= CallQS
[SystemInformationClass
].Query(SystemInformation
,
1979 /* Save the result length to the caller */
1980 if (UnsafeResultLength
)
1981 *UnsafeResultLength
= ResultLength
;
1984 _SEH2_EXCEPT(ExSystemExceptionFilter())
1986 FStatus
= _SEH2_GetExceptionCode();
1996 NtSetSystemInformation (IN SYSTEM_INFORMATION_CLASS SystemInformationClass
,
1997 IN PVOID SystemInformation
,
1998 IN ULONG SystemInformationLength
)
2003 * If called from user mode, check
2004 * possible unsafe arguments.
2007 if (KernelMode
!= KeGetPreviousMode())
2011 // SystemInformation,
2021 * Check the request is valid.
2023 if ((SystemInformationClass
>= MIN_SYSTEM_INFO_CLASS
) &&
2024 (SystemInformationClass
< MAX_SYSTEM_INFO_CLASS
))
2026 if (NULL
!= CallQS
[SystemInformationClass
].Set
)
2029 * Hand the request to a subhandler.
2031 return CallQS
[SystemInformationClass
].Set(SystemInformation
,
2032 SystemInformationLength
);
2036 return STATUS_INVALID_INFO_CLASS
;
2041 NtFlushInstructionCache(IN HANDLE ProcessHandle
,
2042 IN PVOID BaseAddress
,
2043 IN ULONG NumberOfBytesToFlush
)
2047 #if defined(_M_IX86) || defined(_M_AMD64)
2049 #elif defined(_M_PPC)
2050 __asm__
__volatile__("tlbsync");
2051 #elif defined(_M_MIPS)
2052 DPRINT1("NtFlushInstructionCache() is not implemented\n");
2054 #elif defined(_M_ARM)
2055 __asm__
__volatile__("mov r1, #0; mcr p15, 0, r1, c7, c5, 0");
2057 #error Unknown architecture
2059 return STATUS_SUCCESS
;
2064 NtGetCurrentProcessorNumber(VOID
)
2066 /* Just return the CPU */
2067 return KeGetCurrentProcessorNumber();
2073 #undef ExGetPreviousMode
2076 ExGetPreviousMode (VOID
)
2078 return KeGetPreviousMode();