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
= TRUE
;
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 /* TODO: Set time adjustment information */
1420 DPRINT1("Setting of SystemTimeAdjustmentInformation is not implemented yet!\n");
1421 return STATUS_NOT_IMPLEMENTED
;
1424 /* Class 29 - Summary Memory Information */
1425 QSI_DEF(SystemSummaryMemoryInformation
)
1428 DPRINT1("NtQuerySystemInformation - SystemSummaryMemoryInformation not implemented\n");
1429 return STATUS_NOT_IMPLEMENTED
;
1432 /* Class 30 - Next Event Id Information */
1433 QSI_DEF(SystemNextEventIdInformation
)
1436 DPRINT1("NtQuerySystemInformation - SystemNextEventIdInformation not implemented\n");
1437 return STATUS_NOT_IMPLEMENTED
;
1440 /* Class 31 - Event Ids Information */
1441 QSI_DEF(SystemEventIdsInformation
)
1444 DPRINT1("NtQuerySystemInformation - SystemEventIdsInformation not implemented\n");
1445 return STATUS_NOT_IMPLEMENTED
;
1448 /* Class 32 - Crash Dump Information */
1449 QSI_DEF(SystemCrashDumpInformation
)
1452 DPRINT1("NtQuerySystemInformation - SystemCrashDumpInformation not implemented\n");
1453 return STATUS_NOT_IMPLEMENTED
;
1456 /* Class 33 - Exception Information */
1457 QSI_DEF(SystemExceptionInformation
)
1459 PSYSTEM_EXCEPTION_INFORMATION ExceptionInformation
=
1460 (PSYSTEM_EXCEPTION_INFORMATION
)Buffer
;
1462 ULONG AlignmentFixupCount
= 0, ExceptionDispatchCount
= 0;
1463 ULONG FloatingEmulationCount
= 0, ByteWordEmulationCount
= 0;
1466 /* Check size of a buffer, it must match our expectations */
1467 if (sizeof(SYSTEM_EXCEPTION_INFORMATION
) != Size
)
1468 return STATUS_INFO_LENGTH_MISMATCH
;
1470 /* Sum up exception count information from all processors */
1471 for (i
= 0; i
< KeNumberProcessors
; i
++)
1473 Prcb
= KiProcessorBlock
[i
];
1476 AlignmentFixupCount
+= Prcb
->KeAlignmentFixupCount
;
1477 ExceptionDispatchCount
+= Prcb
->KeExceptionDispatchCount
;
1478 FloatingEmulationCount
+= Prcb
->KeFloatingEmulationCount
;
1482 /* Save information in user's buffer */
1483 ExceptionInformation
->AlignmentFixupCount
= AlignmentFixupCount
;
1484 ExceptionInformation
->ExceptionDispatchCount
= ExceptionDispatchCount
;
1485 ExceptionInformation
->FloatingEmulationCount
= FloatingEmulationCount
;
1486 ExceptionInformation
->ByteWordEmulationCount
= ByteWordEmulationCount
;
1488 return STATUS_SUCCESS
;
1491 /* Class 34 - Crash Dump State Information */
1492 QSI_DEF(SystemCrashDumpStateInformation
)
1495 DPRINT1("NtQuerySystemInformation - SystemCrashDumpStateInformation not implemented\n");
1496 return STATUS_NOT_IMPLEMENTED
;
1499 /* Class 35 - Kernel Debugger Information */
1500 QSI_DEF(SystemKernelDebuggerInformation
)
1502 PSYSTEM_KERNEL_DEBUGGER_INFORMATION skdi
= (PSYSTEM_KERNEL_DEBUGGER_INFORMATION
) Buffer
;
1504 *ReqSize
= sizeof(SYSTEM_KERNEL_DEBUGGER_INFORMATION
);
1505 if (Size
< sizeof(SYSTEM_KERNEL_DEBUGGER_INFORMATION
))
1507 return STATUS_INFO_LENGTH_MISMATCH
;
1510 skdi
->KernelDebuggerEnabled
= KD_DEBUGGER_ENABLED
;
1511 skdi
->KernelDebuggerNotPresent
= KD_DEBUGGER_NOT_PRESENT
;
1513 return STATUS_SUCCESS
;
1516 /* Class 36 - Context Switch Information */
1517 QSI_DEF(SystemContextSwitchInformation
)
1519 PSYSTEM_CONTEXT_SWITCH_INFORMATION ContextSwitchInformation
=
1520 (PSYSTEM_CONTEXT_SWITCH_INFORMATION
)Buffer
;
1521 ULONG ContextSwitches
;
1525 /* Check size of a buffer, it must match our expectations */
1526 if (sizeof(SYSTEM_CONTEXT_SWITCH_INFORMATION
) != Size
)
1527 return STATUS_INFO_LENGTH_MISMATCH
;
1529 /* Calculate total value of context switches across all processors */
1530 ContextSwitches
= 0;
1531 for (i
= 0; i
< KeNumberProcessors
; i
++)
1533 Prcb
= KiProcessorBlock
[i
];
1536 ContextSwitches
+= KeGetContextSwitches(Prcb
);
1540 ContextSwitchInformation
->ContextSwitches
= ContextSwitches
;
1543 ContextSwitchInformation
->FindAny
= 0;
1544 ContextSwitchInformation
->FindLast
= 0;
1545 ContextSwitchInformation
->FindIdeal
= 0;
1546 ContextSwitchInformation
->IdleAny
= 0;
1547 ContextSwitchInformation
->IdleCurrent
= 0;
1548 ContextSwitchInformation
->IdleLast
= 0;
1549 ContextSwitchInformation
->IdleIdeal
= 0;
1550 ContextSwitchInformation
->PreemptAny
= 0;
1551 ContextSwitchInformation
->PreemptCurrent
= 0;
1552 ContextSwitchInformation
->PreemptLast
= 0;
1553 ContextSwitchInformation
->SwitchToIdle
= 0;
1555 return STATUS_SUCCESS
;
1558 /* Class 37 - Registry Quota Information */
1559 QSI_DEF(SystemRegistryQuotaInformation
)
1561 PSYSTEM_REGISTRY_QUOTA_INFORMATION srqi
= (PSYSTEM_REGISTRY_QUOTA_INFORMATION
) Buffer
;
1563 *ReqSize
= sizeof(SYSTEM_REGISTRY_QUOTA_INFORMATION
);
1564 if (Size
< sizeof(SYSTEM_REGISTRY_QUOTA_INFORMATION
))
1566 return STATUS_INFO_LENGTH_MISMATCH
;
1569 DPRINT1("Faking max registry size of 32 MB\n");
1570 srqi
->RegistryQuotaAllowed
= 0x2000000;
1571 srqi
->RegistryQuotaUsed
= 0x200000;
1572 srqi
->PagedPoolSize
= 0x200000;
1574 return STATUS_SUCCESS
;
1577 SSI_DEF(SystemRegistryQuotaInformation
)
1580 DPRINT1("NtSetSystemInformation - SystemRegistryQuotaInformation not implemented\n");
1581 return STATUS_NOT_IMPLEMENTED
;
1584 /* Class 38 - Load And Call Image */
1585 SSI_DEF(SystemExtendServiceTableInformation
)
1587 UNICODE_STRING ImageName
;
1588 KPROCESSOR_MODE PreviousMode
= KeGetPreviousMode();
1589 PLDR_DATA_TABLE_ENTRY ModuleObject
;
1591 PIMAGE_NT_HEADERS NtHeader
;
1592 DRIVER_OBJECT Win32k
;
1593 PDRIVER_INITIALIZE DriverInit
;
1595 ULONG_PTR EntryPoint
;
1597 /* Validate the size */
1598 if (Size
!= sizeof(UNICODE_STRING
)) return STATUS_INFO_LENGTH_MISMATCH
;
1600 /* Check who is calling */
1601 if (PreviousMode
!= KernelMode
)
1603 /* Make sure we can load drivers */
1604 if (!SeSinglePrivilegeCheck(SeLoadDriverPrivilege
, UserMode
))
1606 /* FIXME: We can't, fail */
1607 //return STATUS_PRIVILEGE_NOT_HELD;
1611 /* Probe and capture the driver name */
1612 ProbeAndCaptureUnicodeString(&ImageName
, PreviousMode
, Buffer
);
1614 /* Load the image */
1615 Status
= MmLoadSystemImage(&ImageName
,
1619 (PVOID
)&ModuleObject
,
1622 /* Release String */
1623 ReleaseCapturedUnicodeString(&ImageName
, PreviousMode
);
1625 if (!NT_SUCCESS(Status
)) return Status
;
1627 /* Get the headers */
1628 NtHeader
= RtlImageNtHeader(ImageBase
);
1632 MmUnloadSystemImage(ModuleObject
);
1633 return STATUS_INVALID_IMAGE_FORMAT
;
1636 /* Get the entrypoint */
1637 EntryPoint
= NtHeader
->OptionalHeader
.AddressOfEntryPoint
;
1638 EntryPoint
+= (ULONG_PTR
)ImageBase
;
1639 DriverInit
= (PDRIVER_INITIALIZE
)EntryPoint
;
1641 /* Create a dummy device */
1642 RtlZeroMemory(&Win32k
, sizeof(Win32k
));
1643 ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL
);
1644 Win32k
.DriverStart
= ImageBase
;
1647 Status
= (DriverInit
)(&Win32k
, NULL
);
1648 ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL
);
1650 /* Unload if we failed */
1651 if (!NT_SUCCESS(Status
)) MmUnloadSystemImage(ModuleObject
);
1655 /* Class 39 - Priority Separation */
1656 SSI_DEF(SystemPrioritySeperation
)
1659 DPRINT1("NtSetSystemInformation - SystemPrioritySeperation not implemented\n");
1660 return STATUS_NOT_IMPLEMENTED
;
1663 /* Class 40 - Plug Play Bus Information */
1664 QSI_DEF(SystemPlugPlayBusInformation
)
1667 DPRINT1("NtQuerySystemInformation - SystemPlugPlayBusInformation not implemented\n");
1668 return STATUS_NOT_IMPLEMENTED
;
1671 /* Class 41 - Dock Information */
1672 QSI_DEF(SystemDockInformation
)
1675 DPRINT1("NtQuerySystemInformation - SystemDockInformation not implemented\n");
1676 return STATUS_NOT_IMPLEMENTED
;
1679 /* Class 42 - Power Information */
1680 QSI_DEF(SystemPowerInformation
)
1683 DPRINT1("NtQuerySystemInformation - SystemPowerInformation not implemented\n");
1684 return STATUS_NOT_IMPLEMENTED
;
1687 /* Class 43 - Processor Speed Information */
1688 QSI_DEF(SystemProcessorSpeedInformation
)
1691 DPRINT1("NtQuerySystemInformation - SystemProcessorSpeedInformation not implemented\n");
1692 return STATUS_NOT_IMPLEMENTED
;
1695 /* Class 44 - Current Time Zone Information */
1696 QSI_DEF(SystemCurrentTimeZoneInformation
)
1698 *ReqSize
= sizeof(TIME_ZONE_INFORMATION
);
1700 if (sizeof(TIME_ZONE_INFORMATION
) != Size
)
1702 return STATUS_INFO_LENGTH_MISMATCH
;
1705 /* Copy the time zone information struct */
1708 sizeof(TIME_ZONE_INFORMATION
));
1710 return STATUS_SUCCESS
;
1714 SSI_DEF(SystemCurrentTimeZoneInformation
)
1716 /* Check user buffer's size */
1717 if (Size
< sizeof(TIME_ZONE_INFORMATION
))
1719 return STATUS_INFO_LENGTH_MISMATCH
;
1722 return ExpSetTimeZoneInformation((PTIME_ZONE_INFORMATION
)Buffer
);
1726 /* Class 45 - Lookaside Information */
1727 QSI_DEF(SystemLookasideInformation
)
1730 DPRINT1("NtQuerySystemInformation - SystemLookasideInformation not implemented\n");
1731 return STATUS_NOT_IMPLEMENTED
;
1735 /* Class 46 - Set time slip event */
1736 SSI_DEF(SystemSetTimeSlipEvent
)
1739 DPRINT1("NtSetSystemInformation - SystemSetTimSlipEvent not implemented\n");
1740 return STATUS_NOT_IMPLEMENTED
;
1744 /* Class 47 - Create a new session (TSE) */
1745 SSI_DEF(SystemCreateSession
)
1748 DPRINT1("NtSetSystemInformation - SystemCreateSession not implemented\n");
1749 return STATUS_NOT_IMPLEMENTED
;
1753 /* Class 48 - Delete an existing session (TSE) */
1754 SSI_DEF(SystemDeleteSession
)
1757 DPRINT1("NtSetSystemInformation - SystemDeleteSession not implemented\n");
1758 return STATUS_NOT_IMPLEMENTED
;
1762 /* Class 49 - UNKNOWN */
1763 QSI_DEF(SystemInvalidInfoClass4
)
1766 DPRINT1("NtQuerySystemInformation - SystemInvalidInfoClass4 not implemented\n");
1767 return STATUS_NOT_IMPLEMENTED
;
1771 /* Class 50 - System range start address */
1772 QSI_DEF(SystemRangeStartInformation
)
1774 /* Check user buffer's size */
1775 if (Size
!= sizeof(ULONG_PTR
)) return STATUS_INFO_LENGTH_MISMATCH
;
1777 *(PULONG_PTR
)Buffer
= (ULONG_PTR
)MmSystemRangeStart
;
1779 if (ReqSize
) *ReqSize
= sizeof(ULONG_PTR
);
1781 return STATUS_SUCCESS
;
1784 /* Class 51 - Driver verifier information */
1785 QSI_DEF(SystemVerifierInformation
)
1788 DPRINT1("NtQuerySystemInformation - SystemVerifierInformation not implemented\n");
1789 return STATUS_NOT_IMPLEMENTED
;
1793 SSI_DEF(SystemVerifierInformation
)
1796 DPRINT1("NtSetSystemInformation - SystemVerifierInformation not implemented\n");
1797 return STATUS_NOT_IMPLEMENTED
;
1801 /* Class 52 - Add a driver verifier */
1802 SSI_DEF(SystemAddVerifier
)
1805 DPRINT1("NtSetSystemInformation - SystemAddVerifier not implemented\n");
1806 return STATUS_NOT_IMPLEMENTED
;
1810 /* Class 53 - A session's processes */
1811 QSI_DEF(SystemSessionProcessesInformation
)
1814 DPRINT1("NtQuerySystemInformation - SystemSessionProcessInformation not implemented\n");
1815 return STATUS_NOT_IMPLEMENTED
;
1819 /* Query/Set Calls Table */
1823 NTSTATUS (* Query
) (PVOID
,ULONG
,PULONG
);
1824 NTSTATUS (* Set
) (PVOID
,ULONG
);
1831 // XX unknown behaviour
1833 #define SI_QS(n) {QSI_USE(n),SSI_USE(n)}
1834 #define SI_QX(n) {QSI_USE(n),NULL}
1835 #define SI_XS(n) {NULL,SSI_USE(n)}
1836 #define SI_XX(n) {NULL,NULL}
1842 SI_QX(SystemBasicInformation
),
1843 SI_QX(SystemProcessorInformation
),
1844 SI_QX(SystemPerformanceInformation
),
1845 SI_QX(SystemTimeOfDayInformation
),
1846 SI_QX(SystemPathInformation
), /* should be SI_XX */
1847 SI_QX(SystemProcessInformation
),
1848 SI_QX(SystemCallCountInformation
),
1849 SI_QX(SystemDeviceInformation
),
1850 SI_QX(SystemProcessorPerformanceInformation
),
1851 SI_QS(SystemFlagsInformation
),
1852 SI_QX(SystemCallTimeInformation
), /* should be SI_XX */
1853 SI_QX(SystemModuleInformation
),
1854 SI_QX(SystemLocksInformation
),
1855 SI_QX(SystemStackTraceInformation
), /* should be SI_XX */
1856 SI_QX(SystemPagedPoolInformation
), /* should be SI_XX */
1857 SI_QX(SystemNonPagedPoolInformation
), /* should be SI_XX */
1858 SI_QX(SystemHandleInformation
),
1859 SI_QX(SystemObjectInformation
),
1860 SI_QX(SystemPageFileInformation
),
1861 SI_QX(SystemVdmInstemulInformation
),
1862 SI_QX(SystemVdmBopInformation
), /* it should be SI_XX */
1863 SI_QS(SystemFileCacheInformation
),
1864 SI_QX(SystemPoolTagInformation
),
1865 SI_QX(SystemInterruptInformation
),
1866 SI_QS(SystemDpcBehaviourInformation
),
1867 SI_QX(SystemFullMemoryInformation
), /* it should be SI_XX */
1868 SI_XS(SystemLoadGdiDriverInformation
),
1869 SI_XS(SystemUnloadGdiDriverInformation
),
1870 SI_QS(SystemTimeAdjustmentInformation
),
1871 SI_QX(SystemSummaryMemoryInformation
), /* it should be SI_XX */
1872 SI_QX(SystemNextEventIdInformation
), /* it should be SI_XX */
1873 SI_QX(SystemEventIdsInformation
), /* it should be SI_XX */
1874 SI_QX(SystemCrashDumpInformation
),
1875 SI_QX(SystemExceptionInformation
),
1876 SI_QX(SystemCrashDumpStateInformation
),
1877 SI_QX(SystemKernelDebuggerInformation
),
1878 SI_QX(SystemContextSwitchInformation
),
1879 SI_QS(SystemRegistryQuotaInformation
),
1880 SI_XS(SystemExtendServiceTableInformation
),
1881 SI_XS(SystemPrioritySeperation
),
1882 SI_QX(SystemPlugPlayBusInformation
), /* it should be SI_XX */
1883 SI_QX(SystemDockInformation
), /* it should be SI_XX */
1884 SI_QX(SystemPowerInformation
), /* it should be SI_XX */
1885 SI_QX(SystemProcessorSpeedInformation
), /* it should be SI_XX */
1886 SI_QS(SystemCurrentTimeZoneInformation
), /* it should be SI_QX */
1887 SI_QX(SystemLookasideInformation
),
1888 SI_XS(SystemSetTimeSlipEvent
),
1889 SI_XS(SystemCreateSession
),
1890 SI_XS(SystemDeleteSession
),
1891 SI_QX(SystemInvalidInfoClass4
), /* it should be SI_XX */
1892 SI_QX(SystemRangeStartInformation
),
1893 SI_QS(SystemVerifierInformation
),
1894 SI_XS(SystemAddVerifier
),
1895 SI_QX(SystemSessionProcessesInformation
)
1898 C_ASSERT(SystemBasicInformation
== 0);
1899 #define MIN_SYSTEM_INFO_CLASS (SystemBasicInformation)
1900 #define MAX_SYSTEM_INFO_CLASS (sizeof(CallQS) / sizeof(CallQS[0]))
1906 NtQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInformationClass
,
1907 OUT PVOID SystemInformation
,
1909 OUT PULONG UnsafeResultLength
)
1911 KPROCESSOR_MODE PreviousMode
;
1913 NTSTATUS FStatus
= STATUS_NOT_IMPLEMENTED
;
1917 PreviousMode
= ExGetPreviousMode();
1921 if (PreviousMode
!= KernelMode
)
1923 /* SystemKernelDebuggerInformation needs only BOOLEAN alignment */
1924 ProbeForWrite(SystemInformation
, Length
, 1);
1925 if (UnsafeResultLength
!= NULL
)
1926 ProbeForWriteUlong(UnsafeResultLength
);
1930 * Check the request is valid.
1932 if (SystemInformationClass
>= MAX_SYSTEM_INFO_CLASS
)
1934 _SEH2_YIELD(return STATUS_INVALID_INFO_CLASS
);
1937 if (NULL
!= CallQS
[SystemInformationClass
].Query
)
1940 * Hand the request to a subhandler.
1942 FStatus
= CallQS
[SystemInformationClass
].Query(SystemInformation
,
1946 /* Save the result length to the caller */
1947 if (UnsafeResultLength
)
1948 *UnsafeResultLength
= ResultLength
;
1951 _SEH2_EXCEPT(ExSystemExceptionFilter())
1953 FStatus
= _SEH2_GetExceptionCode();
1963 NtSetSystemInformation (IN SYSTEM_INFORMATION_CLASS SystemInformationClass
,
1964 IN PVOID SystemInformation
,
1965 IN ULONG SystemInformationLength
)
1970 * If called from user mode, check
1971 * possible unsafe arguments.
1974 if (KernelMode
!= KeGetPreviousMode())
1978 // SystemInformation,
1988 * Check the request is valid.
1990 if ((SystemInformationClass
>= MIN_SYSTEM_INFO_CLASS
) &&
1991 (SystemInformationClass
< MAX_SYSTEM_INFO_CLASS
))
1993 if (NULL
!= CallQS
[SystemInformationClass
].Set
)
1996 * Hand the request to a subhandler.
1998 return CallQS
[SystemInformationClass
].Set(SystemInformation
,
1999 SystemInformationLength
);
2003 return STATUS_INVALID_INFO_CLASS
;
2008 NtFlushInstructionCache(IN HANDLE ProcessHandle
,
2009 IN PVOID BaseAddress
,
2010 IN ULONG NumberOfBytesToFlush
)
2014 #if defined(_M_IX86) || defined(_M_AMD64)
2016 #elif defined(_M_PPC)
2017 __asm__
__volatile__("tlbsync");
2018 #elif defined(_M_MIPS)
2019 DPRINT1("NtFlushInstructionCache() is not implemented\n");
2021 #elif defined(_M_ARM)
2022 __asm__
__volatile__("mov r1, #0; mcr p15, 0, r1, c7, c5, 0");
2024 #error Unknown architecture
2026 return STATUS_SUCCESS
;
2031 NtGetCurrentProcessorNumber(VOID
)
2033 /* Just return the CPU */
2034 return KeGetCurrentProcessorNumber();
2040 #undef ExGetPreviousMode
2043 ExGetPreviousMode (VOID
)
2045 return KeGetPreviousMode();