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 VOID
MmPrintMemoryStatistic(VOID
);
19 FAST_MUTEX ExpEnvironmentLock
;
20 ERESOURCE ExpFirmwareTableResource
;
21 LIST_ENTRY ExpFirmwareTableProviderListHead
;
25 ExpQueryModuleInformation(IN PLIST_ENTRY KernelModeList
,
26 IN PLIST_ENTRY UserModeList
,
27 OUT PRTL_PROCESS_MODULES Modules
,
29 OUT PULONG ReturnLength
)
31 NTSTATUS Status
= STATUS_SUCCESS
;
33 PRTL_PROCESS_MODULE_INFORMATION ModuleInfo
;
34 PLDR_DATA_TABLE_ENTRY LdrEntry
;
35 ANSI_STRING ModuleName
;
36 ULONG ModuleCount
= 0;
37 PLIST_ENTRY NextEntry
;
41 RequiredLength
= FIELD_OFFSET(RTL_PROCESS_MODULES
, Modules
);
42 ModuleInfo
= &Modules
->Modules
[0];
44 /* Loop the kernel list */
45 NextEntry
= KernelModeList
->Flink
;
46 while (NextEntry
!= KernelModeList
)
49 LdrEntry
= CONTAINING_RECORD(NextEntry
,
53 /* Update size and check if we can manage one more entry */
54 RequiredLength
+= sizeof(RTL_PROCESS_MODULE_INFORMATION
);
55 if (Length
>= RequiredLength
)
58 ModuleInfo
->MappedBase
= NULL
;
59 ModuleInfo
->ImageBase
= LdrEntry
->DllBase
;
60 ModuleInfo
->ImageSize
= LdrEntry
->SizeOfImage
;
61 ModuleInfo
->Flags
= LdrEntry
->Flags
;
62 ModuleInfo
->LoadCount
= LdrEntry
->LoadCount
;
63 ModuleInfo
->LoadOrderIndex
= (USHORT
)ModuleCount
;
64 ModuleInfo
->InitOrderIndex
= 0;
67 RtlInitEmptyAnsiString(&ModuleName
,
68 ModuleInfo
->FullPathName
,
69 sizeof(ModuleInfo
->FullPathName
));
72 Status
= RtlUnicodeStringToAnsiString(&ModuleName
,
73 &LdrEntry
->FullDllName
,
75 if ((NT_SUCCESS(Status
)) || (Status
== STATUS_BUFFER_OVERFLOW
))
77 /* Calculate offset to name */
78 p
= ModuleName
.Buffer
+ ModuleName
.Length
;
79 while ((p
> ModuleName
.Buffer
) && (*--p
))
81 /* Check if we found the separator */
82 if (*p
== OBJ_NAME_PATH_SEPARATOR
)
84 /* We did, break out */
91 ModuleInfo
->OffsetToFileName
= p
- ModuleName
.Buffer
;
95 /* Return empty name */
96 ModuleInfo
->FullPathName
[0] = ANSI_NULL
;
97 ModuleInfo
->OffsetToFileName
= 0;
100 /* Go to the next module */
106 Status
= STATUS_INFO_LENGTH_MISMATCH
;
109 /* Update count and move to next entry */
111 NextEntry
= NextEntry
->Flink
;
114 /* Check if caller also wanted user modules */
118 DPRINT1("User-mode list not yet supported in ReactOS!\n");
121 /* Update return length */
122 if (ReturnLength
) *ReturnLength
= RequiredLength
;
124 /* Validate the length again */
125 if (Length
>= FIELD_OFFSET(RTL_PROCESS_MODULES
, Modules
))
127 /* Set the final count */
128 Modules
->NumberOfModules
= ModuleCount
;
132 /* Otherwise, we failed */
133 Status
= STATUS_INFO_LENGTH_MISMATCH
;
140 /* FUNCTIONS *****************************************************************/
147 ExGetCurrentProcessorCpuUsage(PULONG CpuUsage
)
151 ULONGLONG ScaledIdle
;
153 Prcb
= KeGetCurrentPrcb();
155 ScaledIdle
= Prcb
->IdleThread
->KernelTime
* 100;
156 TotalTime
= Prcb
->KernelTime
+ Prcb
->UserTime
;
158 *CpuUsage
= (ULONG
)(100 - (ScaledIdle
/ TotalTime
));
168 ExGetCurrentProcessorCounts(PULONG ThreadKernelTime
,
170 PULONG ProcessorNumber
)
174 Prcb
= KeGetCurrentPrcb();
176 *ThreadKernelTime
= Prcb
->KernelTime
+ Prcb
->UserTime
;
177 *TotalCpuTime
= Prcb
->CurrentThread
->KernelTime
;
178 *ProcessorNumber
= KeGetCurrentProcessorNumber();
186 ExIsProcessorFeaturePresent(IN ULONG ProcessorFeature
)
188 /* Quick check to see if it exists at all */
189 if (ProcessorFeature
>= PROCESSOR_FEATURE_MAX
) return(FALSE
);
191 /* Return our support for it */
192 return(SharedUserData
->ProcessorFeatures
[ProcessorFeature
]);
200 ExVerifySuite(SUITE_TYPE SuiteType
)
202 if (SuiteType
== Personal
) return TRUE
;
208 NtQuerySystemEnvironmentValue(IN PUNICODE_STRING VariableName
,
209 OUT PWSTR ValueBuffer
,
210 IN ULONG ValueBufferLength
,
211 IN OUT PULONG ReturnLength OPTIONAL
)
214 UNICODE_STRING WName
;
218 UNICODE_STRING WValue
;
219 KPROCESSOR_MODE PreviousMode
;
223 PreviousMode
= ExGetPreviousMode();
225 if (PreviousMode
!= KernelMode
)
229 ProbeForRead(VariableName
,
230 sizeof(UNICODE_STRING
),
233 ProbeForWrite(ValueBuffer
,
237 if (ReturnLength
!= NULL
) ProbeForWriteUlong(ReturnLength
);
239 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
241 /* Return the exception code */
242 _SEH2_YIELD(return _SEH2_GetExceptionCode());
248 * Copy the name to kernel space if necessary and convert it to ANSI.
250 Status
= ProbeAndCaptureUnicodeString(&WName
,
253 if (NT_SUCCESS(Status
))
256 * according to ntinternals the SeSystemEnvironmentName privilege is required!
258 if (!SeSinglePrivilegeCheck(SeSystemEnvironmentPrivilege
,
261 ReleaseCapturedUnicodeString(&WName
, PreviousMode
);
262 DPRINT1("NtQuerySystemEnvironmentValue: Caller requires the SeSystemEnvironmentPrivilege privilege!\n");
263 return STATUS_PRIVILEGE_NOT_HELD
;
267 * convert the value name to ansi
269 Status
= RtlUnicodeStringToAnsiString(&AName
, &WName
, TRUE
);
270 ReleaseCapturedUnicodeString(&WName
, PreviousMode
);
272 if (!NT_SUCCESS(Status
)) return Status
;
275 * Create a temporary buffer for the value
277 Value
= ExAllocatePool(NonPagedPool
, ValueBufferLength
);
280 RtlFreeAnsiString(&AName
);
281 return STATUS_INSUFFICIENT_RESOURCES
;
285 * Get the environment variable
287 Result
= HalGetEnvironmentVariable(AName
.Buffer
,
288 (USHORT
)ValueBufferLength
,
292 RtlFreeAnsiString(&AName
);
294 return STATUS_UNSUCCESSFUL
;
298 * Convert the result to UNICODE, protect with SEH in case the value buffer
299 * isn't NULL-terminated!
303 RtlInitAnsiString(&AValue
, Value
);
304 Status
= RtlAnsiStringToUnicodeString(&WValue
, &AValue
, TRUE
);
306 _SEH2_EXCEPT(ExSystemExceptionFilter())
308 Status
= _SEH2_GetExceptionCode();
312 if (NT_SUCCESS(Status
))
315 * Copy the result back to the caller.
319 RtlCopyMemory(ValueBuffer
, WValue
.Buffer
, WValue
.Length
);
320 ValueBuffer
[WValue
.Length
/ sizeof(WCHAR
)] = L
'\0';
321 if (ReturnLength
!= NULL
)
323 *ReturnLength
= WValue
.Length
+ sizeof(WCHAR
);
326 Status
= STATUS_SUCCESS
;
328 _SEH2_EXCEPT(ExSystemExceptionFilter())
330 Status
= _SEH2_GetExceptionCode();
336 * Cleanup allocated resources.
338 RtlFreeAnsiString(&AName
);
348 NtSetSystemEnvironmentValue(IN PUNICODE_STRING VariableName
,
349 IN PUNICODE_STRING Value
)
351 UNICODE_STRING CapturedName
, CapturedValue
;
352 ANSI_STRING AName
, AValue
;
353 KPROCESSOR_MODE PreviousMode
;
358 PreviousMode
= ExGetPreviousMode();
361 * Copy the strings to kernel space if necessary
363 Status
= ProbeAndCaptureUnicodeString(&CapturedName
,
366 if (NT_SUCCESS(Status
))
368 Status
= ProbeAndCaptureUnicodeString(&CapturedValue
,
371 if (NT_SUCCESS(Status
))
374 * according to ntinternals the SeSystemEnvironmentName privilege is required!
376 if (SeSinglePrivilegeCheck(SeSystemEnvironmentPrivilege
,
380 * convert the strings to ANSI
382 Status
= RtlUnicodeStringToAnsiString(&AName
,
385 if (NT_SUCCESS(Status
))
387 Status
= RtlUnicodeStringToAnsiString(&AValue
,
390 if (NT_SUCCESS(Status
))
392 ARC_STATUS Result
= HalSetEnvironmentVariable(AName
.Buffer
,
395 Status
= (Result
? STATUS_SUCCESS
: STATUS_UNSUCCESSFUL
);
401 DPRINT1("NtSetSystemEnvironmentValue: Caller requires the SeSystemEnvironmentPrivilege privilege!\n");
402 Status
= STATUS_PRIVILEGE_NOT_HELD
;
405 ReleaseCapturedUnicodeString(&CapturedValue
,
409 ReleaseCapturedUnicodeString(&CapturedName
,
418 NtEnumerateSystemEnvironmentValuesEx(IN ULONG InformationClass
,
420 IN ULONG BufferLength
)
423 return STATUS_NOT_IMPLEMENTED
;
428 NtQuerySystemEnvironmentValueEx(IN PUNICODE_STRING VariableName
,
429 IN LPGUID VendorGuid
,
431 IN OUT PULONG ReturnLength
,
432 IN OUT PULONG Attributes
)
435 return STATUS_NOT_IMPLEMENTED
;
440 NtSetSystemEnvironmentValueEx(IN PUNICODE_STRING VariableName
,
441 IN LPGUID VendorGuid
)
444 return STATUS_NOT_IMPLEMENTED
;
447 /* --- Query/Set System Information --- */
450 * NOTE: QSI_DEF(n) and SSI_DEF(n) define _cdecl function symbols
451 * so the stack is popped only in one place on x86 platform.
453 #define QSI_USE(n) QSI##n
455 static NTSTATUS QSI_USE(n) (PVOID Buffer, ULONG Size, PULONG ReqSize)
457 #define SSI_USE(n) SSI##n
459 static NTSTATUS SSI_USE(n) (PVOID Buffer, ULONG Size)
462 /* Class 0 - Basic Information */
463 QSI_DEF(SystemBasicInformation
)
465 PSYSTEM_BASIC_INFORMATION Sbi
466 = (PSYSTEM_BASIC_INFORMATION
) Buffer
;
468 *ReqSize
= sizeof(SYSTEM_BASIC_INFORMATION
);
470 /* Check user buffer's size */
471 if (Size
!= sizeof(SYSTEM_BASIC_INFORMATION
))
473 return STATUS_INFO_LENGTH_MISMATCH
;
476 RtlZeroMemory(Sbi
, Size
);
478 Sbi
->TimerResolution
= KeMaximumIncrement
;
479 Sbi
->PageSize
= PAGE_SIZE
;
480 Sbi
->NumberOfPhysicalPages
= MmNumberOfPhysicalPages
;
481 Sbi
->LowestPhysicalPageNumber
= MmLowestPhysicalPage
;
482 Sbi
->HighestPhysicalPageNumber
= MmHighestPhysicalPage
;
483 Sbi
->AllocationGranularity
= MM_VIRTMEM_GRANULARITY
; /* hard coded on Intel? */
484 Sbi
->MinimumUserModeAddress
= 0x10000; /* Top of 64k */
485 Sbi
->MaximumUserModeAddress
= (ULONG_PTR
)MmHighestUserAddress
;
486 Sbi
->ActiveProcessorsAffinityMask
= KeActiveProcessors
;
487 Sbi
->NumberOfProcessors
= KeNumberProcessors
;
489 return STATUS_SUCCESS
;
492 /* Class 1 - Processor Information */
493 QSI_DEF(SystemProcessorInformation
)
495 PSYSTEM_PROCESSOR_INFORMATION Spi
496 = (PSYSTEM_PROCESSOR_INFORMATION
) Buffer
;
498 *ReqSize
= sizeof(SYSTEM_PROCESSOR_INFORMATION
);
500 /* Check user buffer's size */
501 if (Size
< sizeof(SYSTEM_PROCESSOR_INFORMATION
))
503 return STATUS_INFO_LENGTH_MISMATCH
;
505 Spi
->ProcessorArchitecture
= KeProcessorArchitecture
;
506 Spi
->ProcessorLevel
= KeProcessorLevel
;
507 Spi
->ProcessorRevision
= KeProcessorRevision
;
509 Spi
->ProcessorFeatureBits
= KeFeatureBits
;
511 DPRINT("Arch %d Level %d Rev 0x%x\n", Spi
->ProcessorArchitecture
,
512 Spi
->ProcessorLevel
, Spi
->ProcessorRevision
);
514 return STATUS_SUCCESS
;
517 /* Class 2 - Performance Information */
518 QSI_DEF(SystemPerformanceInformation
)
520 ULONG IdleUser
, IdleKernel
;
521 PSYSTEM_PERFORMANCE_INFORMATION Spi
522 = (PSYSTEM_PERFORMANCE_INFORMATION
) Buffer
;
524 PEPROCESS TheIdleProcess
;
526 *ReqSize
= sizeof(SYSTEM_PERFORMANCE_INFORMATION
);
528 /* Check user buffer's size */
529 if (Size
< sizeof(SYSTEM_PERFORMANCE_INFORMATION
))
531 return STATUS_INFO_LENGTH_MISMATCH
;
534 TheIdleProcess
= PsIdleProcess
;
536 IdleKernel
= KeQueryRuntimeProcess(&TheIdleProcess
->Pcb
, &IdleUser
);
537 Spi
->IdleProcessTime
.QuadPart
= UInt32x32To64(IdleKernel
, KeMaximumIncrement
);
538 Spi
->IoReadTransferCount
= IoReadTransferCount
;
539 Spi
->IoWriteTransferCount
= IoWriteTransferCount
;
540 Spi
->IoOtherTransferCount
= IoOtherTransferCount
;
541 Spi
->IoReadOperationCount
= IoReadOperationCount
;
542 Spi
->IoWriteOperationCount
= IoWriteOperationCount
;
543 Spi
->IoOtherOperationCount
= IoOtherOperationCount
;
545 Spi
->AvailablePages
= MmAvailablePages
;
547 * Add up all the used "Committed" memory + pagefile.
548 * Not sure this is right. 8^\
550 Spi
->CommittedPages
= MiMemoryConsumers
[MC_SYSTEM
].PagesUsed
+
551 MiMemoryConsumers
[MC_CACHE
].PagesUsed
+
552 MiMemoryConsumers
[MC_USER
].PagesUsed
+
555 * Add up the full system total + pagefile.
556 * All this make Taskmgr happy but not sure it is the right numbers.
557 * This too, fixes some of GlobalMemoryStatusEx numbers.
559 Spi
->CommitLimit
= MmNumberOfPhysicalPages
+ MiFreeSwapPages
+ MiUsedSwapPages
;
561 Spi
->PeakCommitment
= 0; /* FIXME */
562 Spi
->PageFaultCount
= 0; /* FIXME */
563 Spi
->CopyOnWriteCount
= 0; /* FIXME */
564 Spi
->TransitionCount
= 0; /* FIXME */
565 Spi
->CacheTransitionCount
= 0; /* FIXME */
566 Spi
->DemandZeroCount
= 0; /* FIXME */
567 Spi
->PageReadCount
= 0; /* FIXME */
568 Spi
->PageReadIoCount
= 0; /* FIXME */
569 Spi
->CacheReadCount
= 0; /* FIXME */
570 Spi
->CacheIoCount
= 0; /* FIXME */
571 Spi
->DirtyPagesWriteCount
= 0; /* FIXME */
572 Spi
->DirtyWriteIoCount
= 0; /* FIXME */
573 Spi
->MappedPagesWriteCount
= 0; /* FIXME */
574 Spi
->MappedWriteIoCount
= 0; /* FIXME */
576 Spi
->PagedPoolPages
= 0; /* FIXME */
577 Spi
->PagedPoolAllocs
= 0; /* FIXME */
578 Spi
->PagedPoolFrees
= 0; /* FIXME */
579 Spi
->NonPagedPoolPages
= 0; /* FIXME */
580 Spi
->NonPagedPoolAllocs
= 0; /* FIXME */
581 Spi
->NonPagedPoolFrees
= 0; /* FIXME */
583 Spi
->FreeSystemPtes
= 0; /* FIXME */
585 Spi
->ResidentSystemCodePage
= 0; /* FIXME */
587 Spi
->TotalSystemDriverPages
= 0; /* FIXME */
588 Spi
->TotalSystemCodePages
= 0; /* FIXME */
589 Spi
->NonPagedPoolLookasideHits
= 0; /* FIXME */
590 Spi
->PagedPoolLookasideHits
= 0; /* FIXME */
591 Spi
->Spare3Count
= 0; /* FIXME */
593 Spi
->ResidentSystemCachePage
= MiMemoryConsumers
[MC_CACHE
].PagesUsed
;
594 Spi
->ResidentPagedPoolPage
= 0; /* FIXME */
596 Spi
->ResidentSystemDriverPage
= 0; /* FIXME */
597 Spi
->CcFastReadNoWait
= 0; /* FIXME */
598 Spi
->CcFastReadWait
= 0; /* FIXME */
599 Spi
->CcFastReadResourceMiss
= 0; /* FIXME */
600 Spi
->CcFastReadNotPossible
= 0; /* FIXME */
602 Spi
->CcFastMdlReadNoWait
= 0; /* FIXME */
603 Spi
->CcFastMdlReadWait
= 0; /* FIXME */
604 Spi
->CcFastMdlReadResourceMiss
= 0; /* FIXME */
605 Spi
->CcFastMdlReadNotPossible
= 0; /* FIXME */
607 Spi
->CcMapDataNoWait
= 0; /* FIXME */
608 Spi
->CcMapDataWait
= 0; /* FIXME */
609 Spi
->CcMapDataNoWaitMiss
= 0; /* FIXME */
610 Spi
->CcMapDataWaitMiss
= 0; /* FIXME */
612 Spi
->CcPinMappedDataCount
= 0; /* FIXME */
613 Spi
->CcPinReadNoWait
= 0; /* FIXME */
614 Spi
->CcPinReadWait
= 0; /* FIXME */
615 Spi
->CcPinReadNoWaitMiss
= 0; /* FIXME */
616 Spi
->CcPinReadWaitMiss
= 0; /* FIXME */
617 Spi
->CcCopyReadNoWait
= 0; /* FIXME */
618 Spi
->CcCopyReadWait
= 0; /* FIXME */
619 Spi
->CcCopyReadNoWaitMiss
= 0; /* FIXME */
620 Spi
->CcCopyReadWaitMiss
= 0; /* FIXME */
622 Spi
->CcMdlReadNoWait
= 0; /* FIXME */
623 Spi
->CcMdlReadWait
= 0; /* FIXME */
624 Spi
->CcMdlReadNoWaitMiss
= 0; /* FIXME */
625 Spi
->CcMdlReadWaitMiss
= 0; /* FIXME */
626 Spi
->CcReadAheadIos
= 0; /* FIXME */
627 Spi
->CcLazyWriteIos
= 0; /* FIXME */
628 Spi
->CcLazyWritePages
= 0; /* FIXME */
629 Spi
->CcDataFlushes
= 0; /* FIXME */
630 Spi
->CcDataPages
= 0; /* FIXME */
631 Spi
->ContextSwitches
= 0; /* FIXME */
632 Spi
->FirstLevelTbFills
= 0; /* FIXME */
633 Spi
->SecondLevelTbFills
= 0; /* FIXME */
634 Spi
->SystemCalls
= 0; /* FIXME */
636 return STATUS_SUCCESS
;
639 /* Class 3 - Time Of Day Information */
640 QSI_DEF(SystemTimeOfDayInformation
)
642 SYSTEM_TIMEOFDAY_INFORMATION Sti
;
643 LARGE_INTEGER CurrentTime
;
645 /* Set amount of written information to 0 */
648 /* Check user buffer's size */
649 if (Size
> sizeof(SYSTEM_TIMEOFDAY_INFORMATION
))
651 return STATUS_INFO_LENGTH_MISMATCH
;
654 /* Get current time */
655 KeQuerySystemTime(&CurrentTime
);
657 /* Zero local buffer */
658 RtlZeroMemory(&Sti
, sizeof(SYSTEM_TIMEOFDAY_INFORMATION
));
660 /* Fill local time structure */
661 Sti
.BootTime
= KeBootTime
;
662 Sti
.CurrentTime
= CurrentTime
;
663 Sti
.TimeZoneBias
.QuadPart
= ExpTimeZoneBias
.QuadPart
;
664 Sti
.TimeZoneId
= ExpTimeZoneId
;
667 /* Copy as much as requested by caller */
668 RtlCopyMemory(Buffer
, &Sti
, Size
);
670 /* Set amount of information we copied */
673 return STATUS_SUCCESS
;
676 /* Class 4 - Path Information */
677 QSI_DEF(SystemPathInformation
)
679 /* FIXME: QSI returns STATUS_BREAKPOINT. Why? */
680 DPRINT1("NtQuerySystemInformation - SystemPathInformation not implemented\n");
682 return STATUS_BREAKPOINT
;
685 /* Class 5 - Process Information */
686 QSI_DEF(SystemProcessInformation
)
688 PSYSTEM_PROCESS_INFORMATION SpiCurrent
;
689 PSYSTEM_THREAD_INFORMATION ThreadInfo
;
690 PEPROCESS Process
= NULL
, SystemProcess
;
691 PETHREAD CurrentThread
;
692 ANSI_STRING ImageName
;
694 USHORT ImageNameMaximumLength
; // image name len in bytes
695 USHORT ImageNameLength
;
696 PLIST_ENTRY CurrentEntry
;
697 ULONG TotalSize
= 0, ThreadsCount
;
698 ULONG TotalUser
, TotalKernel
;
700 NTSTATUS Status
= STATUS_SUCCESS
;
701 PUNICODE_STRING ProcessImageName
;
703 BOOLEAN Overflow
= FALSE
;
707 /* scan the process list */
709 PSYSTEM_PROCESS_INFORMATION Spi
710 = (PSYSTEM_PROCESS_INFORMATION
) Buffer
;
712 *ReqSize
= sizeof(SYSTEM_PROCESS_INFORMATION
);
714 /* Check for overflow */
715 if (Size
< sizeof(SYSTEM_PROCESS_INFORMATION
))
718 /* Zero user's buffer */
719 if (!Overflow
) RtlZeroMemory(Spi
, Size
);
721 SystemProcess
= PsIdleProcess
;
722 Process
= SystemProcess
;
723 Current
= (PUCHAR
) Spi
;
727 SpiCurrent
= (PSYSTEM_PROCESS_INFORMATION
) Current
;
730 CurrentEntry
= Process
->ThreadListHead
.Flink
;
731 while (CurrentEntry
!= &Process
->ThreadListHead
)
734 CurrentEntry
= CurrentEntry
->Flink
;
737 // size of the structure for every process
738 CurrentSize
= sizeof(SYSTEM_PROCESS_INFORMATION
) + sizeof(SYSTEM_THREAD_INFORMATION
) * ThreadsCount
;
740 Status
= SeLocateProcessImageName(Process
, &ProcessImageName
);
742 if (NT_SUCCESS(Status
) && (ProcessImageName
->Length
> 0))
744 szSrc
= (PWCHAR
)((PCHAR
)ProcessImageName
->Buffer
+ ProcessImageName
->Length
);
745 /* Loop the file name*/
746 while (szSrc
> ProcessImageName
->Buffer
)
748 /* Make sure this isn't a backslash */
749 if (*--szSrc
== OBJ_NAME_PATH_SEPARATOR
)
756 ImageNameLength
+= sizeof(WCHAR
);
760 if (!ImageNameLength
&& Process
!= PsIdleProcess
&& Process
->ImageFileName
)
762 ImageNameLength
= strlen(Process
->ImageFileName
) * sizeof(WCHAR
);
765 /* Round up the image name length as NT does */
766 if (ImageNameLength
> 0)
767 ImageNameMaximumLength
= ROUND_UP(ImageNameLength
+ sizeof(WCHAR
), 8);
769 ImageNameMaximumLength
= 0;
771 TotalSize
+= CurrentSize
+ ImageNameMaximumLength
;
773 /* Check for overflow */
774 if (TotalSize
> Size
)
777 /* Fill system information */
780 SpiCurrent
->NextEntryOffset
= CurrentSize
+ ImageNameMaximumLength
; // relative offset to the beginnnig of the next structure
781 SpiCurrent
->NumberOfThreads
= ThreadsCount
;
782 SpiCurrent
->CreateTime
= Process
->CreateTime
;
783 SpiCurrent
->ImageName
.Length
= ImageNameLength
;
784 SpiCurrent
->ImageName
.MaximumLength
= ImageNameMaximumLength
;
785 SpiCurrent
->ImageName
.Buffer
= (void*)(Current
+ CurrentSize
);
787 /* Copy name to the end of the struct */
788 if(Process
!= PsIdleProcess
)
792 RtlCopyMemory(SpiCurrent
->ImageName
.Buffer
, szSrc
, SpiCurrent
->ImageName
.Length
);
794 /* Release the memory allocated by SeLocateProcessImageName */
795 ExFreePool(ProcessImageName
);
797 else if (Process
->ImageFileName
)
799 RtlInitAnsiString(&ImageName
, Process
->ImageFileName
);
800 RtlAnsiStringToUnicodeString(&SpiCurrent
->ImageName
, &ImageName
, FALSE
);
805 RtlInitUnicodeString(&SpiCurrent
->ImageName
, NULL
);
808 SpiCurrent
->BasePriority
= Process
->Pcb
.BasePriority
;
809 SpiCurrent
->UniqueProcessId
= Process
->UniqueProcessId
;
810 SpiCurrent
->InheritedFromUniqueProcessId
= Process
->InheritedFromUniqueProcessId
;
811 SpiCurrent
->HandleCount
= ObGetProcessHandleCount(Process
);
812 SpiCurrent
->PeakVirtualSize
= Process
->PeakVirtualSize
;
813 SpiCurrent
->VirtualSize
= Process
->VirtualSize
;
814 SpiCurrent
->PageFaultCount
= Process
->Vm
.PageFaultCount
;
815 SpiCurrent
->PeakWorkingSetSize
= Process
->Vm
.PeakWorkingSetSize
;
816 SpiCurrent
->WorkingSetSize
= Process
->Vm
.WorkingSetSize
;
817 SpiCurrent
->QuotaPeakPagedPoolUsage
= Process
->QuotaPeak
[0];
818 SpiCurrent
->QuotaPagedPoolUsage
= Process
->QuotaUsage
[0];
819 SpiCurrent
->QuotaPeakNonPagedPoolUsage
= Process
->QuotaPeak
[1];
820 SpiCurrent
->QuotaNonPagedPoolUsage
= Process
->QuotaUsage
[1];
821 SpiCurrent
->PagefileUsage
= Process
->QuotaUsage
[2];
822 SpiCurrent
->PeakPagefileUsage
= Process
->QuotaPeak
[2];
823 SpiCurrent
->PrivatePageCount
= Process
->CommitCharge
;
824 ThreadInfo
= (PSYSTEM_THREAD_INFORMATION
)(SpiCurrent
+ 1);
826 CurrentEntry
= Process
->ThreadListHead
.Flink
;
827 while (CurrentEntry
!= &Process
->ThreadListHead
)
829 CurrentThread
= CONTAINING_RECORD(CurrentEntry
, ETHREAD
,
832 ThreadInfo
->KernelTime
.QuadPart
= UInt32x32To64(CurrentThread
->Tcb
.KernelTime
, KeMaximumIncrement
);
833 ThreadInfo
->UserTime
.QuadPart
= UInt32x32To64(CurrentThread
->Tcb
.UserTime
, KeMaximumIncrement
);
834 ThreadInfo
->CreateTime
.QuadPart
= CurrentThread
->CreateTime
.QuadPart
;
835 ThreadInfo
->WaitTime
= CurrentThread
->Tcb
.WaitTime
;
836 ThreadInfo
->StartAddress
= (PVOID
) CurrentThread
->StartAddress
;
837 ThreadInfo
->ClientId
= CurrentThread
->Cid
;
838 ThreadInfo
->Priority
= CurrentThread
->Tcb
.Priority
;
839 ThreadInfo
->BasePriority
= CurrentThread
->Tcb
.BasePriority
;
840 ThreadInfo
->ContextSwitches
= CurrentThread
->Tcb
.ContextSwitches
;
841 ThreadInfo
->ThreadState
= CurrentThread
->Tcb
.State
;
842 ThreadInfo
->WaitReason
= CurrentThread
->Tcb
.WaitReason
;
845 CurrentEntry
= CurrentEntry
->Flink
;
848 /* Query total user/kernel times of a process */
849 TotalKernel
= KeQueryRuntimeProcess(&Process
->Pcb
, &TotalUser
);
850 SpiCurrent
->UserTime
.QuadPart
= UInt32x32To64(TotalUser
, KeMaximumIncrement
);
851 SpiCurrent
->KernelTime
.QuadPart
= UInt32x32To64(TotalKernel
, KeMaximumIncrement
);
854 /* Handle idle process entry */
855 if (Process
== PsIdleProcess
) Process
= NULL
;
857 Process
= PsGetNextProcess(Process
);
859 if ((Process
== SystemProcess
) || (Process
== NULL
))
862 SpiCurrent
->NextEntryOffset
= 0;
866 Current
+= CurrentSize
+ ImageNameMaximumLength
;
867 } while ((Process
!= SystemProcess
) && (Process
!= NULL
));
870 ObDereferenceObject(Process
);
871 Status
= STATUS_SUCCESS
;
873 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
876 ObDereferenceObject(Process
);
877 Status
= _SEH2_GetExceptionCode();
882 Status
= STATUS_INFO_LENGTH_MISMATCH
;
884 *ReqSize
= TotalSize
;
888 /* Class 6 - Call Count Information */
889 QSI_DEF(SystemCallCountInformation
)
892 DPRINT1("NtQuerySystemInformation - SystemCallCountInformation not implemented\n");
893 return STATUS_NOT_IMPLEMENTED
;
896 /* Class 7 - Device Information */
897 QSI_DEF(SystemDeviceInformation
)
899 PSYSTEM_DEVICE_INFORMATION Sdi
900 = (PSYSTEM_DEVICE_INFORMATION
) Buffer
;
901 PCONFIGURATION_INFORMATION ConfigInfo
;
903 *ReqSize
= sizeof(SYSTEM_DEVICE_INFORMATION
);
905 /* Check user buffer's size */
906 if (Size
< sizeof(SYSTEM_DEVICE_INFORMATION
))
908 return STATUS_INFO_LENGTH_MISMATCH
;
911 ConfigInfo
= IoGetConfigurationInformation();
913 Sdi
->NumberOfDisks
= ConfigInfo
->DiskCount
;
914 Sdi
->NumberOfFloppies
= ConfigInfo
->FloppyCount
;
915 Sdi
->NumberOfCdRoms
= ConfigInfo
->CdRomCount
;
916 Sdi
->NumberOfTapes
= ConfigInfo
->TapeCount
;
917 Sdi
->NumberOfSerialPorts
= ConfigInfo
->SerialCount
;
918 Sdi
->NumberOfParallelPorts
= ConfigInfo
->ParallelCount
;
920 return STATUS_SUCCESS
;
923 /* Class 8 - Processor Performance Information */
924 QSI_DEF(SystemProcessorPerformanceInformation
)
926 PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION Spi
927 = (PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
) Buffer
;
933 *ReqSize
= KeNumberProcessors
* sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
);
935 /* Check user buffer's size */
938 return STATUS_INFO_LENGTH_MISMATCH
;
941 for (i
= 0; i
< KeNumberProcessors
; i
++)
943 /* Get the PRCB on this processor */
944 Prcb
= KiProcessorBlock
[i
];
946 /* Calculate total user and kernel times */
947 TotalTime
= Prcb
->IdleThread
->KernelTime
+ Prcb
->IdleThread
->UserTime
;
948 Spi
->IdleTime
.QuadPart
= UInt32x32To64(TotalTime
, KeMaximumIncrement
);
949 Spi
->KernelTime
.QuadPart
= UInt32x32To64(Prcb
->KernelTime
, KeMaximumIncrement
);
950 Spi
->UserTime
.QuadPart
= UInt32x32To64(Prcb
->UserTime
, KeMaximumIncrement
);
951 Spi
->DpcTime
.QuadPart
= UInt32x32To64(Prcb
->DpcTime
, KeMaximumIncrement
);
952 Spi
->InterruptTime
.QuadPart
= UInt32x32To64(Prcb
->InterruptTime
, KeMaximumIncrement
);
953 Spi
->InterruptCount
= Prcb
->InterruptCount
;
957 return STATUS_SUCCESS
;
960 /* Class 9 - Flags Information */
961 QSI_DEF(SystemFlagsInformation
)
963 if (sizeof(SYSTEM_FLAGS_INFORMATION
) != Size
)
965 *ReqSize
= sizeof(SYSTEM_FLAGS_INFORMATION
);
966 return (STATUS_INFO_LENGTH_MISMATCH
);
968 ((PSYSTEM_FLAGS_INFORMATION
) Buffer
)->Flags
= NtGlobalFlag
;
969 return STATUS_SUCCESS
;
972 SSI_DEF(SystemFlagsInformation
)
974 if (sizeof(SYSTEM_FLAGS_INFORMATION
) != Size
)
976 return STATUS_INFO_LENGTH_MISMATCH
;
978 NtGlobalFlag
= ((PSYSTEM_FLAGS_INFORMATION
) Buffer
)->Flags
;
979 return STATUS_SUCCESS
;
982 /* Class 10 - Call Time Information */
983 QSI_DEF(SystemCallTimeInformation
)
986 DPRINT1("NtQuerySystemInformation - SystemCallTimeInformation not implemented\n");
987 return STATUS_NOT_IMPLEMENTED
;
990 /* Class 11 - Module Information */
991 QSI_DEF(SystemModuleInformation
)
995 /* Acquire system module list lock */
996 KeEnterCriticalRegion();
997 ExAcquireResourceExclusiveLite(&PsLoadedModuleResource
, TRUE
);
999 /* Call the generic handler with the system module list */
1000 Status
= ExpQueryModuleInformation(&PsLoadedModuleList
,
1001 &MmLoadedUserImageList
,
1002 (PRTL_PROCESS_MODULES
)Buffer
,
1006 /* Release list lock and return status */
1007 ExReleaseResourceLite(&PsLoadedModuleResource
);
1008 KeLeaveCriticalRegion();
1012 /* Class 12 - Locks Information */
1013 QSI_DEF(SystemLocksInformation
)
1016 DPRINT1("NtQuerySystemInformation - SystemLocksInformation not implemented\n");
1017 return STATUS_NOT_IMPLEMENTED
;
1020 /* Class 13 - Stack Trace Information */
1021 QSI_DEF(SystemStackTraceInformation
)
1024 DPRINT1("NtQuerySystemInformation - SystemStackTraceInformation not implemented\n");
1025 return STATUS_NOT_IMPLEMENTED
;
1028 /* Class 14 - Paged Pool Information */
1029 QSI_DEF(SystemPagedPoolInformation
)
1032 DPRINT1("NtQuerySystemInformation - SystemPagedPoolInformation not implemented\n");
1033 return STATUS_NOT_IMPLEMENTED
;
1036 /* Class 15 - Non Paged Pool Information */
1037 QSI_DEF(SystemNonPagedPoolInformation
)
1040 DPRINT1("NtQuerySystemInformation - SystemNonPagedPoolInformation not implemented\n");
1041 return STATUS_NOT_IMPLEMENTED
;
1045 /* Class 16 - Handle Information */
1046 QSI_DEF(SystemHandleInformation
)
1048 PEPROCESS pr
, syspr
;
1049 ULONG curSize
, i
= 0;
1052 PSYSTEM_HANDLE_INFORMATION Shi
=
1053 (PSYSTEM_HANDLE_INFORMATION
) Buffer
;
1055 DPRINT("NtQuerySystemInformation - SystemHandleInformation\n");
1057 if (Size
< sizeof(SYSTEM_HANDLE_INFORMATION
))
1059 *ReqSize
= sizeof(SYSTEM_HANDLE_INFORMATION
);
1060 return STATUS_INFO_LENGTH_MISMATCH
;
1063 DPRINT("SystemHandleInformation 1\n");
1065 /* First Calc Size from Count. */
1066 syspr
= PsGetNextProcess(NULL
);
1071 hCount
= hCount
+ ObGetProcessHandleCount(pr
);
1072 pr
= PsGetNextProcess(pr
);
1074 if ((pr
== syspr
) || (pr
== NULL
)) break;
1076 while ((pr
!= syspr
) && (pr
!= NULL
));
1080 ObDereferenceObject(pr
);
1083 DPRINT("SystemHandleInformation 2\n");
1085 curSize
= sizeof(SYSTEM_HANDLE_INFORMATION
) +
1086 ((sizeof(SYSTEM_HANDLE_TABLE_ENTRY_INFO
) * hCount
) -
1087 (sizeof(SYSTEM_HANDLE_TABLE_ENTRY_INFO
)));
1089 Shi
->NumberOfHandles
= hCount
;
1094 return (STATUS_INFO_LENGTH_MISMATCH
);
1097 DPRINT("SystemHandleInformation 3\n");
1099 /* Now get Handles from all processs. */
1100 syspr
= PsGetNextProcess(NULL
);
1105 int Count
= 0, HandleCount
;
1107 HandleCount
= ObGetProcessHandleCount(pr
);
1109 for (Count
= 0; HandleCount
> 0 ; HandleCount
--)
1111 Shi
->Handles
[i
].UniqueProcessId
= (USHORT
)(ULONG_PTR
)pr
->UniqueProcessId
;
1116 pr
= PsGetNextProcess(pr
);
1118 if ((pr
== syspr
) || (pr
== NULL
)) break;
1120 while ((pr
!= syspr
) && (pr
!= NULL
));
1122 if(pr
!= NULL
) ObDereferenceObject(pr
);
1124 DPRINT("SystemHandleInformation 4\n");
1125 return STATUS_SUCCESS
;
1129 SSI_DEF(SystemHandleInformation)
1132 return STATUS_SUCCESS;
1136 /* Class 17 - Information */
1137 QSI_DEF(SystemObjectInformation
)
1140 DPRINT1("NtQuerySystemInformation - SystemObjectInformation not implemented\n");
1141 return STATUS_NOT_IMPLEMENTED
;
1144 /* Class 18 - Information */
1145 QSI_DEF(SystemPageFileInformation
)
1147 UNICODE_STRING FileName
; /* FIXME */
1148 SYSTEM_PAGEFILE_INFORMATION
*Spfi
= (SYSTEM_PAGEFILE_INFORMATION
*) Buffer
;
1150 if (Size
< sizeof(SYSTEM_PAGEFILE_INFORMATION
))
1152 * ReqSize
= sizeof(SYSTEM_PAGEFILE_INFORMATION
);
1153 return STATUS_INFO_LENGTH_MISMATCH
;
1156 RtlInitUnicodeString(&FileName
, NULL
); /* FIXME */
1159 Spfi
->NextEntryOffset
= 0;
1161 Spfi
->TotalSize
= MiFreeSwapPages
+ MiUsedSwapPages
;
1162 Spfi
->TotalInUse
= MiUsedSwapPages
;
1163 Spfi
->PeakUsage
= MiUsedSwapPages
; /* FIXME */
1164 Spfi
->PageFileName
= FileName
;
1165 return STATUS_SUCCESS
;
1168 /* Class 19 - Vdm Instemul Information */
1169 QSI_DEF(SystemVdmInstemulInformation
)
1172 DPRINT1("NtQuerySystemInformation - SystemVdmInstemulInformation not implemented\n");
1173 return STATUS_NOT_IMPLEMENTED
;
1176 /* Class 20 - Vdm Bop Information */
1177 QSI_DEF(SystemVdmBopInformation
)
1180 DPRINT1("NtQuerySystemInformation - SystemVdmBopInformation not implemented\n");
1181 return STATUS_NOT_IMPLEMENTED
;
1184 /* Class 21 - File Cache Information */
1185 QSI_DEF(SystemFileCacheInformation
)
1187 SYSTEM_FILECACHE_INFORMATION
*Sci
= (SYSTEM_FILECACHE_INFORMATION
*) Buffer
;
1189 if (Size
< sizeof(SYSTEM_FILECACHE_INFORMATION
))
1191 *ReqSize
= sizeof(SYSTEM_FILECACHE_INFORMATION
);
1192 return STATUS_INFO_LENGTH_MISMATCH
;
1195 RtlZeroMemory(Sci
, sizeof(SYSTEM_FILECACHE_INFORMATION
));
1197 /* Return the Byte size not the page size. */
1199 MiMemoryConsumers
[MC_CACHE
].PagesUsed
* PAGE_SIZE
;
1201 MiMemoryConsumers
[MC_CACHE
].PagesUsed
* PAGE_SIZE
; /* FIXME */
1202 /* Taskmgr multiplies this one by page size right away */
1203 Sci
->CurrentSizeIncludingTransitionInPages
=
1204 MiMemoryConsumers
[MC_CACHE
].PagesUsed
; /* FIXME: Should be */
1205 /* system working set and standby pages. */
1206 Sci
->PageFaultCount
= 0; /* FIXME */
1207 Sci
->MinimumWorkingSet
= 0; /* FIXME */
1208 Sci
->MaximumWorkingSet
= 0; /* FIXME */
1210 return STATUS_SUCCESS
;
1213 SSI_DEF(SystemFileCacheInformation
)
1215 if (Size
< sizeof(SYSTEM_FILECACHE_INFORMATION
))
1217 return STATUS_INFO_LENGTH_MISMATCH
;
1220 DPRINT1("NtSetSystemInformation - SystemFileCacheInformation not implemented\n");
1221 return STATUS_NOT_IMPLEMENTED
;
1224 /* Class 22 - Pool Tag Information */
1225 QSI_DEF(SystemPoolTagInformation
)
1228 DPRINT1("NtQuerySystemInformation - SystemPoolTagInformation not implemented\n");
1229 return STATUS_NOT_IMPLEMENTED
;
1232 /* Class 23 - Interrupt Information for all processors */
1233 QSI_DEF(SystemInterruptInformation
)
1238 PSYSTEM_INTERRUPT_INFORMATION sii
= (PSYSTEM_INTERRUPT_INFORMATION
)Buffer
;
1240 if(Size
< KeNumberProcessors
* sizeof(SYSTEM_INTERRUPT_INFORMATION
))
1242 return STATUS_INFO_LENGTH_MISMATCH
;
1245 ti
= KeQueryTimeIncrement();
1247 for (i
= 0; i
< KeNumberProcessors
; i
++)
1249 Prcb
= KiProcessorBlock
[i
];
1250 sii
->ContextSwitches
= KeGetContextSwitches(Prcb
);
1251 sii
->DpcCount
= Prcb
->DpcData
[0].DpcCount
;
1252 sii
->DpcRate
= Prcb
->DpcRequestRate
;
1253 sii
->TimeIncrement
= ti
;
1254 sii
->DpcBypassCount
= 0;
1255 sii
->ApcBypassCount
= 0;
1259 return STATUS_SUCCESS
;
1262 /* Class 24 - DPC Behaviour Information */
1263 QSI_DEF(SystemDpcBehaviourInformation
)
1266 DPRINT1("NtQuerySystemInformation - SystemDpcBehaviourInformation not implemented\n");
1267 return STATUS_NOT_IMPLEMENTED
;
1270 SSI_DEF(SystemDpcBehaviourInformation
)
1273 DPRINT1("NtSetSystemInformation - SystemDpcBehaviourInformation not implemented\n");
1274 return STATUS_NOT_IMPLEMENTED
;
1277 /* Class 25 - Full Memory Information */
1278 QSI_DEF(SystemFullMemoryInformation
)
1280 PULONG Spi
= (PULONG
) Buffer
;
1282 PEPROCESS TheIdleProcess
;
1284 *ReqSize
= sizeof(ULONG
);
1286 if (sizeof(ULONG
) != Size
)
1288 return STATUS_INFO_LENGTH_MISMATCH
;
1291 DPRINT("SystemFullMemoryInformation\n");
1293 TheIdleProcess
= PsIdleProcess
;
1295 DPRINT("PID: %d, KernelTime: %u PFFree: %d PFUsed: %d\n",
1296 TheIdleProcess
->UniqueProcessId
,
1297 TheIdleProcess
->Pcb
.KernelTime
,
1302 MmPrintMemoryStatistic();
1305 *Spi
= MiMemoryConsumers
[MC_USER
].PagesUsed
;
1307 return STATUS_SUCCESS
;
1310 /* Class 26 - Load Image */
1311 SSI_DEF(SystemLoadGdiDriverInformation
)
1313 PSYSTEM_GDI_DRIVER_INFORMATION DriverInfo
= (PVOID
)Buffer
;
1314 UNICODE_STRING ImageName
;
1316 PVOID SectionPointer
;
1317 ULONG_PTR EntryPoint
;
1320 PIMAGE_NT_HEADERS NtHeader
;
1323 if (Size
!= sizeof(SYSTEM_GDI_DRIVER_INFORMATION
))
1325 /* Incorrect buffer length, fail */
1326 return STATUS_INFO_LENGTH_MISMATCH
;
1329 /* Only kernel mode can call this function */
1330 if (ExGetPreviousMode() != KernelMode
) return STATUS_PRIVILEGE_NOT_HELD
;
1332 /* Load the driver */
1333 ImageName
= DriverInfo
->DriverName
;
1334 Status
= MmLoadSystemImage(&ImageName
,
1340 if (!NT_SUCCESS(Status
)) return Status
;
1342 /* Return the export pointer */
1343 DriverInfo
->ExportSectionPointer
=
1344 RtlImageDirectoryEntryToData(ImageBase
,
1346 IMAGE_DIRECTORY_ENTRY_EXPORT
,
1349 /* Get the entrypoint */
1350 NtHeader
= RtlImageNtHeader(ImageBase
);
1351 EntryPoint
= NtHeader
->OptionalHeader
.AddressOfEntryPoint
;
1352 EntryPoint
+= (ULONG_PTR
)ImageBase
;
1354 /* Save other data */
1355 DriverInfo
->ImageAddress
= ImageBase
;
1356 DriverInfo
->SectionPointer
= SectionPointer
;
1357 DriverInfo
->EntryPoint
= (PVOID
)EntryPoint
;
1358 DriverInfo
->ImageLength
= NtHeader
->OptionalHeader
.SizeOfImage
;
1361 return STATUS_SUCCESS
;
1364 /* Class 27 - Unload Image */
1365 SSI_DEF(SystemUnloadGdiDriverInformation
)
1367 PVOID SectionPointer
= Buffer
;
1370 if (Size
!= sizeof(PVOID
))
1372 /* Incorrect length, fail */
1373 return STATUS_INFO_LENGTH_MISMATCH
;
1376 /* Only kernel mode can call this function */
1377 if (ExGetPreviousMode() != KernelMode
) return STATUS_PRIVILEGE_NOT_HELD
;
1379 /* Unload the image */
1380 MmUnloadSystemImage(SectionPointer
);
1381 return STATUS_SUCCESS
;
1384 /* Class 28 - Time Adjustment Information */
1385 QSI_DEF(SystemTimeAdjustmentInformation
)
1387 PSYSTEM_QUERY_TIME_ADJUST_INFORMATION TimeInfo
=
1388 (PSYSTEM_QUERY_TIME_ADJUST_INFORMATION
)Buffer
;
1390 /* Check if enough storage was provided */
1391 if (sizeof(SYSTEM_QUERY_TIME_ADJUST_INFORMATION
) > Size
)
1393 * ReqSize
= sizeof(SYSTEM_QUERY_TIME_ADJUST_INFORMATION
);
1394 return STATUS_INFO_LENGTH_MISMATCH
;
1397 /* Give time values to our caller */
1398 TimeInfo
->TimeIncrement
= KeMaximumIncrement
;
1399 TimeInfo
->TimeAdjustment
= KeTimeAdjustment
;
1400 TimeInfo
->Enable
= TRUE
;
1402 return STATUS_SUCCESS
;
1405 SSI_DEF(SystemTimeAdjustmentInformation
)
1407 KPROCESSOR_MODE PreviousMode
= KeGetPreviousMode();
1408 /*PSYSTEM_SET_TIME_ADJUST_INFORMATION TimeInfo =
1409 (PSYSTEM_SET_TIME_ADJUST_INFORMATION)Buffer;*/
1411 /* Check size of a buffer, it must match our expectations */
1412 if (sizeof(SYSTEM_SET_TIME_ADJUST_INFORMATION
) != Size
)
1413 return STATUS_INFO_LENGTH_MISMATCH
;
1415 /* Check who is calling */
1416 if (PreviousMode
!= KernelMode
)
1418 /* Check access rights */
1419 if (!SeSinglePrivilegeCheck(SeSystemtimePrivilege
, PreviousMode
))
1421 return STATUS_PRIVILEGE_NOT_HELD
;
1425 /* TODO: Set time adjustment information */
1426 DPRINT1("Setting of SystemTimeAdjustmentInformation is not implemented yet!\n");
1427 return STATUS_NOT_IMPLEMENTED
;
1430 /* Class 29 - Summary Memory Information */
1431 QSI_DEF(SystemSummaryMemoryInformation
)
1434 DPRINT1("NtQuerySystemInformation - SystemSummaryMemoryInformation not implemented\n");
1435 return STATUS_NOT_IMPLEMENTED
;
1438 /* Class 30 - Next Event Id Information */
1439 QSI_DEF(SystemNextEventIdInformation
)
1442 DPRINT1("NtQuerySystemInformation - SystemNextEventIdInformation not implemented\n");
1443 return STATUS_NOT_IMPLEMENTED
;
1446 /* Class 31 - Event Ids Information */
1447 QSI_DEF(SystemEventIdsInformation
)
1450 DPRINT1("NtQuerySystemInformation - SystemEventIdsInformation not implemented\n");
1451 return STATUS_NOT_IMPLEMENTED
;
1454 /* Class 32 - Crash Dump Information */
1455 QSI_DEF(SystemCrashDumpInformation
)
1458 DPRINT1("NtQuerySystemInformation - SystemCrashDumpInformation not implemented\n");
1459 return STATUS_NOT_IMPLEMENTED
;
1462 /* Class 33 - Exception Information */
1463 QSI_DEF(SystemExceptionInformation
)
1465 PSYSTEM_EXCEPTION_INFORMATION ExceptionInformation
=
1466 (PSYSTEM_EXCEPTION_INFORMATION
)Buffer
;
1468 ULONG i
, AlignmentFixupCount
= 0, ExceptionDispatchCount
= 0;
1469 ULONG FloatingEmulationCount
= 0, ByteWordEmulationCount
= 0;
1471 /* Check size of a buffer, it must match our expectations */
1472 if (sizeof(SYSTEM_EXCEPTION_INFORMATION
) != Size
)
1473 return STATUS_INFO_LENGTH_MISMATCH
;
1475 /* Sum up exception count information from all processors */
1476 for (i
= 0; i
< KeNumberProcessors
; i
++)
1478 Prcb
= KiProcessorBlock
[i
];
1481 AlignmentFixupCount
+= Prcb
->KeAlignmentFixupCount
;
1482 ExceptionDispatchCount
+= Prcb
->KeExceptionDispatchCount
;
1483 FloatingEmulationCount
+= Prcb
->KeFloatingEmulationCount
;
1487 /* Save information in user's buffer */
1488 ExceptionInformation
->AlignmentFixupCount
= AlignmentFixupCount
;
1489 ExceptionInformation
->ExceptionDispatchCount
= ExceptionDispatchCount
;
1490 ExceptionInformation
->FloatingEmulationCount
= FloatingEmulationCount
;
1491 ExceptionInformation
->ByteWordEmulationCount
= ByteWordEmulationCount
;
1493 return STATUS_SUCCESS
;
1496 /* Class 34 - Crash Dump State Information */
1497 QSI_DEF(SystemCrashDumpStateInformation
)
1500 DPRINT1("NtQuerySystemInformation - SystemCrashDumpStateInformation not implemented\n");
1501 return STATUS_NOT_IMPLEMENTED
;
1504 /* Class 35 - Kernel Debugger Information */
1505 QSI_DEF(SystemKernelDebuggerInformation
)
1507 PSYSTEM_KERNEL_DEBUGGER_INFORMATION skdi
= (PSYSTEM_KERNEL_DEBUGGER_INFORMATION
) Buffer
;
1509 *ReqSize
= sizeof(SYSTEM_KERNEL_DEBUGGER_INFORMATION
);
1510 if (Size
< sizeof(SYSTEM_KERNEL_DEBUGGER_INFORMATION
))
1512 return STATUS_INFO_LENGTH_MISMATCH
;
1515 skdi
->KernelDebuggerEnabled
= KD_DEBUGGER_ENABLED
;
1516 skdi
->KernelDebuggerNotPresent
= KD_DEBUGGER_NOT_PRESENT
;
1518 return STATUS_SUCCESS
;
1521 /* Class 36 - Context Switch Information */
1522 QSI_DEF(SystemContextSwitchInformation
)
1524 PSYSTEM_CONTEXT_SWITCH_INFORMATION ContextSwitchInformation
=
1525 (PSYSTEM_CONTEXT_SWITCH_INFORMATION
)Buffer
;
1526 ULONG ContextSwitches
, i
;
1529 /* Check size of a buffer, it must match our expectations */
1530 if (sizeof(SYSTEM_CONTEXT_SWITCH_INFORMATION
) != Size
)
1531 return STATUS_INFO_LENGTH_MISMATCH
;
1533 /* Calculate total value of context switches across all processors */
1534 ContextSwitches
= 0;
1535 for (i
= 0; i
< KeNumberProcessors
; i
++)
1537 Prcb
= KiProcessorBlock
[i
];
1540 ContextSwitches
+= KeGetContextSwitches(Prcb
);
1544 ContextSwitchInformation
->ContextSwitches
= ContextSwitches
;
1547 ContextSwitchInformation
->FindAny
= 0;
1548 ContextSwitchInformation
->FindLast
= 0;
1549 ContextSwitchInformation
->FindIdeal
= 0;
1550 ContextSwitchInformation
->IdleAny
= 0;
1551 ContextSwitchInformation
->IdleCurrent
= 0;
1552 ContextSwitchInformation
->IdleLast
= 0;
1553 ContextSwitchInformation
->IdleIdeal
= 0;
1554 ContextSwitchInformation
->PreemptAny
= 0;
1555 ContextSwitchInformation
->PreemptCurrent
= 0;
1556 ContextSwitchInformation
->PreemptLast
= 0;
1557 ContextSwitchInformation
->SwitchToIdle
= 0;
1559 return STATUS_SUCCESS
;
1562 /* Class 37 - Registry Quota Information */
1563 QSI_DEF(SystemRegistryQuotaInformation
)
1565 PSYSTEM_REGISTRY_QUOTA_INFORMATION srqi
= (PSYSTEM_REGISTRY_QUOTA_INFORMATION
) Buffer
;
1567 *ReqSize
= sizeof(SYSTEM_REGISTRY_QUOTA_INFORMATION
);
1568 if (Size
< sizeof(SYSTEM_REGISTRY_QUOTA_INFORMATION
))
1570 return STATUS_INFO_LENGTH_MISMATCH
;
1573 DPRINT1("Faking max registry size of 32 MB\n");
1574 srqi
->RegistryQuotaAllowed
= 0x2000000;
1575 srqi
->RegistryQuotaUsed
= 0x200000;
1576 srqi
->PagedPoolSize
= 0x200000;
1578 return STATUS_SUCCESS
;
1581 SSI_DEF(SystemRegistryQuotaInformation
)
1584 DPRINT1("NtSetSystemInformation - SystemRegistryQuotaInformation not implemented\n");
1585 return STATUS_NOT_IMPLEMENTED
;
1588 /* Class 38 - Load And Call Image */
1589 SSI_DEF(SystemExtendServiceTableInformation
)
1591 UNICODE_STRING ImageName
;
1592 KPROCESSOR_MODE PreviousMode
= KeGetPreviousMode();
1593 PLDR_DATA_TABLE_ENTRY ModuleObject
;
1595 PIMAGE_NT_HEADERS NtHeader
;
1596 DRIVER_OBJECT Win32k
;
1597 PDRIVER_INITIALIZE DriverInit
;
1599 ULONG_PTR EntryPoint
;
1601 /* Validate the size */
1602 if (Size
!= sizeof(UNICODE_STRING
)) return STATUS_INFO_LENGTH_MISMATCH
;
1604 /* Check who is calling */
1605 if (PreviousMode
!= KernelMode
)
1607 /* Make sure we can load drivers */
1608 if (!SeSinglePrivilegeCheck(SeLoadDriverPrivilege
, UserMode
))
1610 /* FIXME: We can't, fail */
1611 //return STATUS_PRIVILEGE_NOT_HELD;
1615 /* Probe and capture the driver name */
1616 ProbeAndCaptureUnicodeString(&ImageName
, PreviousMode
, Buffer
);
1618 /* Load the image */
1619 Status
= MmLoadSystemImage(&ImageName
,
1623 (PVOID
)&ModuleObject
,
1626 /* Release String */
1627 ReleaseCapturedUnicodeString(&ImageName
, PreviousMode
);
1629 if (!NT_SUCCESS(Status
)) return Status
;
1631 /* Get the headers */
1632 NtHeader
= RtlImageNtHeader(ImageBase
);
1636 MmUnloadSystemImage(ModuleObject
);
1637 return STATUS_INVALID_IMAGE_FORMAT
;
1640 /* Get the entrypoint */
1641 EntryPoint
= NtHeader
->OptionalHeader
.AddressOfEntryPoint
;
1642 EntryPoint
+= (ULONG_PTR
)ImageBase
;
1643 DriverInit
= (PDRIVER_INITIALIZE
)EntryPoint
;
1645 /* Create a dummy device */
1646 RtlZeroMemory(&Win32k
, sizeof(Win32k
));
1647 ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL
);
1648 Win32k
.DriverStart
= ImageBase
;
1651 Status
= (DriverInit
)(&Win32k
, NULL
);
1652 ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL
);
1654 /* Unload if we failed */
1655 if (!NT_SUCCESS(Status
)) MmUnloadSystemImage(ModuleObject
);
1659 /* Class 39 - Priority Separation */
1660 SSI_DEF(SystemPrioritySeperation
)
1663 DPRINT1("NtSetSystemInformation - SystemPrioritySeperation not implemented\n");
1664 return STATUS_NOT_IMPLEMENTED
;
1667 /* Class 40 - Plug Play Bus Information */
1668 QSI_DEF(SystemPlugPlayBusInformation
)
1671 DPRINT1("NtQuerySystemInformation - SystemPlugPlayBusInformation not implemented\n");
1672 return STATUS_NOT_IMPLEMENTED
;
1675 /* Class 41 - Dock Information */
1676 QSI_DEF(SystemDockInformation
)
1679 DPRINT1("NtQuerySystemInformation - SystemDockInformation not implemented\n");
1680 return STATUS_NOT_IMPLEMENTED
;
1683 /* Class 42 - Power Information */
1684 QSI_DEF(SystemPowerInformation
)
1687 DPRINT1("NtQuerySystemInformation - SystemPowerInformation not implemented\n");
1688 return STATUS_NOT_IMPLEMENTED
;
1691 /* Class 43 - Processor Speed Information */
1692 QSI_DEF(SystemProcessorSpeedInformation
)
1695 DPRINT1("NtQuerySystemInformation - SystemProcessorSpeedInformation not implemented\n");
1696 return STATUS_NOT_IMPLEMENTED
;
1699 /* Class 44 - Current Time Zone Information */
1700 QSI_DEF(SystemCurrentTimeZoneInformation
)
1702 *ReqSize
= sizeof(TIME_ZONE_INFORMATION
);
1704 if (sizeof(TIME_ZONE_INFORMATION
) != Size
)
1706 return STATUS_INFO_LENGTH_MISMATCH
;
1709 /* Copy the time zone information struct */
1712 sizeof(TIME_ZONE_INFORMATION
));
1714 return STATUS_SUCCESS
;
1718 SSI_DEF(SystemCurrentTimeZoneInformation
)
1720 /* Check user buffer's size */
1721 if (Size
< sizeof(TIME_ZONE_INFORMATION
))
1723 return STATUS_INFO_LENGTH_MISMATCH
;
1726 return ExpSetTimeZoneInformation((PTIME_ZONE_INFORMATION
)Buffer
);
1730 /* Class 45 - Lookaside Information */
1731 QSI_DEF(SystemLookasideInformation
)
1734 DPRINT1("NtQuerySystemInformation - SystemLookasideInformation not implemented\n");
1735 return STATUS_NOT_IMPLEMENTED
;
1739 /* Class 46 - Set time slip event */
1740 SSI_DEF(SystemSetTimeSlipEvent
)
1743 DPRINT1("NtSetSystemInformation - SystemSetTimSlipEvent not implemented\n");
1744 return STATUS_NOT_IMPLEMENTED
;
1748 /* Class 47 - Create a new session (TSE) */
1749 SSI_DEF(SystemCreateSession
)
1752 DPRINT1("NtSetSystemInformation - SystemCreateSession not implemented\n");
1753 return STATUS_NOT_IMPLEMENTED
;
1757 /* Class 48 - Delete an existing session (TSE) */
1758 SSI_DEF(SystemDeleteSession
)
1761 DPRINT1("NtSetSystemInformation - SystemDeleteSession not implemented\n");
1762 return STATUS_NOT_IMPLEMENTED
;
1766 /* Class 49 - UNKNOWN */
1767 QSI_DEF(SystemInvalidInfoClass4
)
1770 DPRINT1("NtQuerySystemInformation - SystemInvalidInfoClass4 not implemented\n");
1771 return STATUS_NOT_IMPLEMENTED
;
1775 /* Class 50 - System range start address */
1776 QSI_DEF(SystemRangeStartInformation
)
1779 DPRINT1("NtQuerySystemInformation - SystemRangeStartInformation not implemented\n");
1780 return STATUS_NOT_IMPLEMENTED
;
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
,
1945 if (UnsafeResultLength
!= NULL
)
1947 if (PreviousMode
!= KernelMode
)
1949 *UnsafeResultLength
= ResultLength
;
1953 *UnsafeResultLength
= ResultLength
;
1958 _SEH2_EXCEPT(ExSystemExceptionFilter())
1960 FStatus
= _SEH2_GetExceptionCode();
1970 NtSetSystemInformation (IN SYSTEM_INFORMATION_CLASS SystemInformationClass
,
1971 IN PVOID SystemInformation
,
1972 IN ULONG SystemInformationLength
)
1977 * If called from user mode, check
1978 * possible unsafe arguments.
1981 if (KernelMode
!= KeGetPreviousMode())
1985 // SystemInformation,
1995 * Check the request is valid.
1997 if ((SystemInformationClass
>= MIN_SYSTEM_INFO_CLASS
) &&
1998 (SystemInformationClass
< MAX_SYSTEM_INFO_CLASS
))
2000 if (NULL
!= CallQS
[SystemInformationClass
].Set
)
2003 * Hand the request to a subhandler.
2005 return CallQS
[SystemInformationClass
].Set(SystemInformation
,
2006 SystemInformationLength
);
2010 return STATUS_INVALID_INFO_CLASS
;
2015 NtFlushInstructionCache(IN HANDLE ProcessHandle
,
2016 IN PVOID BaseAddress
,
2017 IN ULONG NumberOfBytesToFlush
)
2021 #if defined(_M_IX86) || defined(_M_AMD64)
2023 #elif defined(_M_PPC)
2024 __asm__
__volatile__("tlbsync");
2025 #elif defined(_M_MIPS)
2026 DPRINT1("NtFlushInstructionCache() is not implemented\n");
2028 #elif defined(_M_ARM)
2029 __asm__
__volatile__("mov r1, #0; mcr p15, 0, r1, c7, c5, 0");
2031 #error Unknown architecture
2033 return STATUS_SUCCESS
;
2038 NtGetCurrentProcessorNumber(VOID
)
2040 /* Just return the CPU */
2041 return KeGetCurrentProcessorNumber();
2047 #undef ExGetPreviousMode
2050 ExGetPreviousMode (VOID
)
2052 return KeGetPreviousMode();