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
;
499 *ReqSize
= sizeof(SYSTEM_PROCESSOR_INFORMATION
);
501 /* Check user buffer's size */
502 if (Size
< sizeof(SYSTEM_PROCESSOR_INFORMATION
))
504 return STATUS_INFO_LENGTH_MISMATCH
;
506 Prcb
= KeGetCurrentPrcb();
507 Spi
->ProcessorArchitecture
= KeProcessorArchitecture
;
508 Spi
->ProcessorLevel
= KeProcessorLevel
;
509 Spi
->ProcessorRevision
= KeProcessorRevision
;
511 Spi
->ProcessorFeatureBits
= KeFeatureBits
;
513 DPRINT("Arch %d Level %d Rev 0x%x\n", Spi
->ProcessorArchitecture
,
514 Spi
->ProcessorLevel
, Spi
->ProcessorRevision
);
516 return STATUS_SUCCESS
;
519 /* Class 2 - Performance Information */
520 QSI_DEF(SystemPerformanceInformation
)
522 ULONG IdleUser
, IdleKernel
;
523 PSYSTEM_PERFORMANCE_INFORMATION Spi
524 = (PSYSTEM_PERFORMANCE_INFORMATION
) Buffer
;
526 PEPROCESS TheIdleProcess
;
528 *ReqSize
= sizeof(SYSTEM_PERFORMANCE_INFORMATION
);
530 /* Check user buffer's size */
531 if (Size
< sizeof(SYSTEM_PERFORMANCE_INFORMATION
))
533 return STATUS_INFO_LENGTH_MISMATCH
;
536 TheIdleProcess
= PsIdleProcess
;
538 IdleKernel
= KeQueryRuntimeProcess(&TheIdleProcess
->Pcb
, &IdleUser
);
539 Spi
->IdleProcessTime
.QuadPart
= UInt32x32To64(IdleKernel
, KeMaximumIncrement
);
540 Spi
->IoReadTransferCount
= IoReadTransferCount
;
541 Spi
->IoWriteTransferCount
= IoWriteTransferCount
;
542 Spi
->IoOtherTransferCount
= IoOtherTransferCount
;
543 Spi
->IoReadOperationCount
= IoReadOperationCount
;
544 Spi
->IoWriteOperationCount
= IoWriteOperationCount
;
545 Spi
->IoOtherOperationCount
= IoOtherOperationCount
;
547 Spi
->AvailablePages
= MmAvailablePages
;
549 * Add up all the used "Committed" memory + pagefile.
550 * Not sure this is right. 8^\
552 Spi
->CommittedPages
= MiMemoryConsumers
[MC_PPOOL
].PagesUsed
+
553 MiMemoryConsumers
[MC_NPPOOL
].PagesUsed
+
554 MiMemoryConsumers
[MC_CACHE
].PagesUsed
+
555 MiMemoryConsumers
[MC_USER
].PagesUsed
+
558 * Add up the full system total + pagefile.
559 * All this make Taskmgr happy but not sure it is the right numbers.
560 * This too, fixes some of GlobalMemoryStatusEx numbers.
562 Spi
->CommitLimit
= MmNumberOfPhysicalPages
+ MiFreeSwapPages
+ MiUsedSwapPages
;
564 Spi
->PeakCommitment
= 0; /* FIXME */
565 Spi
->PageFaultCount
= 0; /* FIXME */
566 Spi
->CopyOnWriteCount
= 0; /* FIXME */
567 Spi
->TransitionCount
= 0; /* FIXME */
568 Spi
->CacheTransitionCount
= 0; /* FIXME */
569 Spi
->DemandZeroCount
= 0; /* FIXME */
570 Spi
->PageReadCount
= 0; /* FIXME */
571 Spi
->PageReadIoCount
= 0; /* FIXME */
572 Spi
->CacheReadCount
= 0; /* FIXME */
573 Spi
->CacheIoCount
= 0; /* FIXME */
574 Spi
->DirtyPagesWriteCount
= 0; /* FIXME */
575 Spi
->DirtyWriteIoCount
= 0; /* FIXME */
576 Spi
->MappedPagesWriteCount
= 0; /* FIXME */
577 Spi
->MappedWriteIoCount
= 0; /* FIXME */
579 Spi
->PagedPoolPages
= MiMemoryConsumers
[MC_PPOOL
].PagesUsed
;
580 Spi
->PagedPoolAllocs
= 0; /* FIXME */
581 Spi
->PagedPoolFrees
= 0; /* FIXME */
582 Spi
->NonPagedPoolPages
= MiMemoryConsumers
[MC_NPPOOL
].PagesUsed
;
583 Spi
->NonPagedPoolAllocs
= 0; /* FIXME */
584 Spi
->NonPagedPoolFrees
= 0; /* FIXME */
586 Spi
->FreeSystemPtes
= 0; /* FIXME */
588 Spi
->ResidentSystemCodePage
= 0; /* FIXME */
590 Spi
->TotalSystemDriverPages
= 0; /* FIXME */
591 Spi
->TotalSystemCodePages
= 0; /* FIXME */
592 Spi
->NonPagedPoolLookasideHits
= 0; /* FIXME */
593 Spi
->PagedPoolLookasideHits
= 0; /* FIXME */
594 Spi
->Spare3Count
= 0; /* FIXME */
596 Spi
->ResidentSystemCachePage
= MiMemoryConsumers
[MC_CACHE
].PagesUsed
;
597 Spi
->ResidentPagedPoolPage
= MiMemoryConsumers
[MC_PPOOL
].PagesUsed
; /* FIXME */
599 Spi
->ResidentSystemDriverPage
= 0; /* FIXME */
600 Spi
->CcFastReadNoWait
= 0; /* FIXME */
601 Spi
->CcFastReadWait
= 0; /* FIXME */
602 Spi
->CcFastReadResourceMiss
= 0; /* FIXME */
603 Spi
->CcFastReadNotPossible
= 0; /* FIXME */
605 Spi
->CcFastMdlReadNoWait
= 0; /* FIXME */
606 Spi
->CcFastMdlReadWait
= 0; /* FIXME */
607 Spi
->CcFastMdlReadResourceMiss
= 0; /* FIXME */
608 Spi
->CcFastMdlReadNotPossible
= 0; /* FIXME */
610 Spi
->CcMapDataNoWait
= 0; /* FIXME */
611 Spi
->CcMapDataWait
= 0; /* FIXME */
612 Spi
->CcMapDataNoWaitMiss
= 0; /* FIXME */
613 Spi
->CcMapDataWaitMiss
= 0; /* FIXME */
615 Spi
->CcPinMappedDataCount
= 0; /* FIXME */
616 Spi
->CcPinReadNoWait
= 0; /* FIXME */
617 Spi
->CcPinReadWait
= 0; /* FIXME */
618 Spi
->CcPinReadNoWaitMiss
= 0; /* FIXME */
619 Spi
->CcPinReadWaitMiss
= 0; /* FIXME */
620 Spi
->CcCopyReadNoWait
= 0; /* FIXME */
621 Spi
->CcCopyReadWait
= 0; /* FIXME */
622 Spi
->CcCopyReadNoWaitMiss
= 0; /* FIXME */
623 Spi
->CcCopyReadWaitMiss
= 0; /* FIXME */
625 Spi
->CcMdlReadNoWait
= 0; /* FIXME */
626 Spi
->CcMdlReadWait
= 0; /* FIXME */
627 Spi
->CcMdlReadNoWaitMiss
= 0; /* FIXME */
628 Spi
->CcMdlReadWaitMiss
= 0; /* FIXME */
629 Spi
->CcReadAheadIos
= 0; /* FIXME */
630 Spi
->CcLazyWriteIos
= 0; /* FIXME */
631 Spi
->CcLazyWritePages
= 0; /* FIXME */
632 Spi
->CcDataFlushes
= 0; /* FIXME */
633 Spi
->CcDataPages
= 0; /* FIXME */
634 Spi
->ContextSwitches
= 0; /* FIXME */
635 Spi
->FirstLevelTbFills
= 0; /* FIXME */
636 Spi
->SecondLevelTbFills
= 0; /* FIXME */
637 Spi
->SystemCalls
= 0; /* FIXME */
639 return STATUS_SUCCESS
;
642 /* Class 3 - Time Of Day Information */
643 QSI_DEF(SystemTimeOfDayInformation
)
645 SYSTEM_TIMEOFDAY_INFORMATION Sti
;
646 LARGE_INTEGER CurrentTime
;
648 /* Set amount of written information to 0 */
651 /* Check user buffer's size */
652 if (Size
> sizeof(SYSTEM_TIMEOFDAY_INFORMATION
))
654 return STATUS_INFO_LENGTH_MISMATCH
;
657 /* Get current time */
658 KeQuerySystemTime(&CurrentTime
);
660 /* Zero local buffer */
661 RtlZeroMemory(&Sti
, sizeof(SYSTEM_TIMEOFDAY_INFORMATION
));
663 /* Fill local time structure */
664 Sti
.BootTime
= KeBootTime
;
665 Sti
.CurrentTime
= CurrentTime
;
666 Sti
.TimeZoneBias
.QuadPart
= ExpTimeZoneBias
.QuadPart
;
667 Sti
.TimeZoneId
= ExpTimeZoneId
;
670 /* Copy as much as requested by caller */
671 RtlCopyMemory(Buffer
, &Sti
, Size
);
673 /* Set amount of information we copied */
676 return STATUS_SUCCESS
;
679 /* Class 4 - Path Information */
680 QSI_DEF(SystemPathInformation
)
682 /* FIXME: QSI returns STATUS_BREAKPOINT. Why? */
683 DPRINT1("NtQuerySystemInformation - SystemPathInformation not implemented\n");
685 return STATUS_BREAKPOINT
;
688 /* Class 5 - Process Information */
689 QSI_DEF(SystemProcessInformation
)
691 PSYSTEM_PROCESS_INFORMATION SpiCurrent
;
692 PSYSTEM_THREAD_INFORMATION ThreadInfo
;
693 PEPROCESS Process
= NULL
, SystemProcess
;
694 PETHREAD CurrentThread
;
695 ANSI_STRING ImageName
;
697 USHORT ImageNameMaximumLength
; // image name len in bytes
698 USHORT ImageNameLength
;
699 PLIST_ENTRY CurrentEntry
;
700 ULONG TotalSize
= 0, ThreadsCount
;
701 ULONG TotalUser
, TotalKernel
;
703 NTSTATUS Status
= STATUS_SUCCESS
;
704 PUNICODE_STRING ProcessImageName
;
706 BOOLEAN Overflow
= FALSE
;
710 /* scan the process list */
712 PSYSTEM_PROCESS_INFORMATION Spi
713 = (PSYSTEM_PROCESS_INFORMATION
) Buffer
;
715 *ReqSize
= sizeof(SYSTEM_PROCESS_INFORMATION
);
717 /* Check for overflow */
718 if (Size
< sizeof(SYSTEM_PROCESS_INFORMATION
))
721 /* Zero user's buffer */
722 if (!Overflow
) RtlZeroMemory(Spi
, Size
);
724 SystemProcess
= PsIdleProcess
;
725 Process
= SystemProcess
;
726 Current
= (PUCHAR
) Spi
;
730 SpiCurrent
= (PSYSTEM_PROCESS_INFORMATION
) Current
;
733 CurrentEntry
= Process
->ThreadListHead
.Flink
;
734 while (CurrentEntry
!= &Process
->ThreadListHead
)
737 CurrentEntry
= CurrentEntry
->Flink
;
740 // size of the structure for every process
741 CurrentSize
= sizeof(SYSTEM_PROCESS_INFORMATION
) + sizeof(SYSTEM_THREAD_INFORMATION
) * ThreadsCount
;
743 Status
= SeLocateProcessImageName(Process
, &ProcessImageName
);
745 if (NT_SUCCESS(Status
) && (ProcessImageName
->Length
> 0))
747 szSrc
= (PWCHAR
)((PCHAR
)ProcessImageName
->Buffer
+ ProcessImageName
->Length
);
748 /* Loop the file name*/
749 while (szSrc
> ProcessImageName
->Buffer
)
751 /* Make sure this isn't a backslash */
752 if (*--szSrc
== OBJ_NAME_PATH_SEPARATOR
)
759 ImageNameLength
+= sizeof(WCHAR
);
763 if (!ImageNameLength
&& Process
!= PsIdleProcess
&& Process
->ImageFileName
)
765 ImageNameLength
= strlen(Process
->ImageFileName
) * sizeof(WCHAR
);
768 /* Round up the image name length as NT does */
769 if (ImageNameLength
> 0)
770 ImageNameMaximumLength
= ROUND_UP(ImageNameLength
+ sizeof(WCHAR
), 8);
772 ImageNameMaximumLength
= 0;
774 TotalSize
+= CurrentSize
+ ImageNameMaximumLength
;
776 /* Check for overflow */
777 if (TotalSize
> Size
)
780 /* Fill system information */
783 SpiCurrent
->NextEntryOffset
= CurrentSize
+ ImageNameMaximumLength
; // relative offset to the beginnnig of the next structure
784 SpiCurrent
->NumberOfThreads
= ThreadsCount
;
785 SpiCurrent
->CreateTime
= Process
->CreateTime
;
786 SpiCurrent
->ImageName
.Length
= ImageNameLength
;
787 SpiCurrent
->ImageName
.MaximumLength
= ImageNameMaximumLength
;
788 SpiCurrent
->ImageName
.Buffer
= (void*)(Current
+ CurrentSize
);
790 /* Copy name to the end of the struct */
791 if(Process
!= PsIdleProcess
)
795 RtlCopyMemory(SpiCurrent
->ImageName
.Buffer
, szSrc
, SpiCurrent
->ImageName
.Length
);
797 /* Release the memory allocated by SeLocateProcessImageName */
798 ExFreePool(ProcessImageName
);
800 else if (Process
->ImageFileName
)
802 RtlInitAnsiString(&ImageName
, Process
->ImageFileName
);
803 RtlAnsiStringToUnicodeString(&SpiCurrent
->ImageName
, &ImageName
, FALSE
);
808 RtlInitUnicodeString(&SpiCurrent
->ImageName
, NULL
);
811 SpiCurrent
->BasePriority
= Process
->Pcb
.BasePriority
;
812 SpiCurrent
->UniqueProcessId
= Process
->UniqueProcessId
;
813 SpiCurrent
->InheritedFromUniqueProcessId
= Process
->InheritedFromUniqueProcessId
;
814 SpiCurrent
->HandleCount
= ObGetProcessHandleCount(Process
);
815 SpiCurrent
->PeakVirtualSize
= Process
->PeakVirtualSize
;
816 SpiCurrent
->VirtualSize
= Process
->VirtualSize
;
817 SpiCurrent
->PageFaultCount
= Process
->Vm
.PageFaultCount
;
818 SpiCurrent
->PeakWorkingSetSize
= Process
->Vm
.PeakWorkingSetSize
;
819 SpiCurrent
->WorkingSetSize
= Process
->Vm
.WorkingSetSize
;
820 SpiCurrent
->QuotaPeakPagedPoolUsage
= Process
->QuotaPeak
[0];
821 SpiCurrent
->QuotaPagedPoolUsage
= Process
->QuotaUsage
[0];
822 SpiCurrent
->QuotaPeakNonPagedPoolUsage
= Process
->QuotaPeak
[1];
823 SpiCurrent
->QuotaNonPagedPoolUsage
= Process
->QuotaUsage
[1];
824 SpiCurrent
->PagefileUsage
= Process
->QuotaUsage
[2];
825 SpiCurrent
->PeakPagefileUsage
= Process
->QuotaPeak
[2];
826 SpiCurrent
->PrivatePageCount
= Process
->CommitCharge
;
827 ThreadInfo
= (PSYSTEM_THREAD_INFORMATION
)(SpiCurrent
+ 1);
829 CurrentEntry
= Process
->ThreadListHead
.Flink
;
830 while (CurrentEntry
!= &Process
->ThreadListHead
)
832 CurrentThread
= CONTAINING_RECORD(CurrentEntry
, ETHREAD
,
835 ThreadInfo
->KernelTime
.QuadPart
= UInt32x32To64(CurrentThread
->Tcb
.KernelTime
, KeMaximumIncrement
);
836 ThreadInfo
->UserTime
.QuadPart
= UInt32x32To64(CurrentThread
->Tcb
.UserTime
, KeMaximumIncrement
);
837 ThreadInfo
->CreateTime
.QuadPart
= CurrentThread
->CreateTime
.QuadPart
;
838 ThreadInfo
->WaitTime
= CurrentThread
->Tcb
.WaitTime
;
839 ThreadInfo
->StartAddress
= (PVOID
) CurrentThread
->StartAddress
;
840 ThreadInfo
->ClientId
= CurrentThread
->Cid
;
841 ThreadInfo
->Priority
= CurrentThread
->Tcb
.Priority
;
842 ThreadInfo
->BasePriority
= CurrentThread
->Tcb
.BasePriority
;
843 ThreadInfo
->ContextSwitches
= CurrentThread
->Tcb
.ContextSwitches
;
844 ThreadInfo
->ThreadState
= CurrentThread
->Tcb
.State
;
845 ThreadInfo
->WaitReason
= CurrentThread
->Tcb
.WaitReason
;
848 CurrentEntry
= CurrentEntry
->Flink
;
851 /* Query total user/kernel times of a process */
852 TotalKernel
= KeQueryRuntimeProcess(&Process
->Pcb
, &TotalUser
);
853 SpiCurrent
->UserTime
.QuadPart
= UInt32x32To64(TotalUser
, KeMaximumIncrement
);
854 SpiCurrent
->KernelTime
.QuadPart
= UInt32x32To64(TotalKernel
, KeMaximumIncrement
);
857 /* Handle idle process entry */
858 if (Process
== PsIdleProcess
) Process
= NULL
;
860 Process
= PsGetNextProcess(Process
);
862 if ((Process
== SystemProcess
) || (Process
== NULL
))
865 SpiCurrent
->NextEntryOffset
= 0;
869 Current
+= CurrentSize
+ ImageNameMaximumLength
;
870 } while ((Process
!= SystemProcess
) && (Process
!= NULL
));
873 ObDereferenceObject(Process
);
874 Status
= STATUS_SUCCESS
;
876 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
879 ObDereferenceObject(Process
);
880 Status
= _SEH2_GetExceptionCode();
885 Status
= STATUS_INFO_LENGTH_MISMATCH
;
887 *ReqSize
= TotalSize
;
891 /* Class 6 - Call Count Information */
892 QSI_DEF(SystemCallCountInformation
)
895 DPRINT1("NtQuerySystemInformation - SystemCallCountInformation not implemented\n");
896 return STATUS_NOT_IMPLEMENTED
;
899 /* Class 7 - Device Information */
900 QSI_DEF(SystemDeviceInformation
)
902 PSYSTEM_DEVICE_INFORMATION Sdi
903 = (PSYSTEM_DEVICE_INFORMATION
) Buffer
;
904 PCONFIGURATION_INFORMATION ConfigInfo
;
906 *ReqSize
= sizeof(SYSTEM_DEVICE_INFORMATION
);
908 /* Check user buffer's size */
909 if (Size
< sizeof(SYSTEM_DEVICE_INFORMATION
))
911 return STATUS_INFO_LENGTH_MISMATCH
;
914 ConfigInfo
= IoGetConfigurationInformation();
916 Sdi
->NumberOfDisks
= ConfigInfo
->DiskCount
;
917 Sdi
->NumberOfFloppies
= ConfigInfo
->FloppyCount
;
918 Sdi
->NumberOfCdRoms
= ConfigInfo
->CdRomCount
;
919 Sdi
->NumberOfTapes
= ConfigInfo
->TapeCount
;
920 Sdi
->NumberOfSerialPorts
= ConfigInfo
->SerialCount
;
921 Sdi
->NumberOfParallelPorts
= ConfigInfo
->ParallelCount
;
923 return STATUS_SUCCESS
;
926 /* Class 8 - Processor Performance Information */
927 QSI_DEF(SystemProcessorPerformanceInformation
)
929 PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION Spi
930 = (PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
) Buffer
;
934 LARGE_INTEGER CurrentTime
;
937 *ReqSize
= KeNumberProcessors
* sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
);
939 /* Check user buffer's size */
942 return STATUS_INFO_LENGTH_MISMATCH
;
945 CurrentTime
.QuadPart
= KeQueryInterruptTime();
946 for (i
= 0; i
< KeNumberProcessors
; i
++)
948 /* Get the PRCB on this processor */
949 Prcb
= KiProcessorBlock
[i
];
951 /* Calculate total user and kernel times */
952 TotalTime
= Prcb
->IdleThread
->KernelTime
+ Prcb
->IdleThread
->UserTime
;
953 Spi
->IdleTime
.QuadPart
= UInt32x32To64(TotalTime
, KeMaximumIncrement
);
954 Spi
->KernelTime
.QuadPart
= UInt32x32To64(Prcb
->KernelTime
, KeMaximumIncrement
);
955 Spi
->UserTime
.QuadPart
= UInt32x32To64(Prcb
->UserTime
, KeMaximumIncrement
);
956 Spi
->DpcTime
.QuadPart
= UInt32x32To64(Prcb
->DpcTime
, KeMaximumIncrement
);
957 Spi
->InterruptTime
.QuadPart
= UInt32x32To64(Prcb
->InterruptTime
, KeMaximumIncrement
);
958 Spi
->InterruptCount
= Prcb
->InterruptCount
;
962 return STATUS_SUCCESS
;
965 /* Class 9 - Flags Information */
966 QSI_DEF(SystemFlagsInformation
)
968 if (sizeof(SYSTEM_FLAGS_INFORMATION
) != Size
)
970 *ReqSize
= sizeof(SYSTEM_FLAGS_INFORMATION
);
971 return (STATUS_INFO_LENGTH_MISMATCH
);
973 ((PSYSTEM_FLAGS_INFORMATION
) Buffer
)->Flags
= NtGlobalFlag
;
974 return STATUS_SUCCESS
;
977 SSI_DEF(SystemFlagsInformation
)
979 if (sizeof(SYSTEM_FLAGS_INFORMATION
) != Size
)
981 return STATUS_INFO_LENGTH_MISMATCH
;
983 NtGlobalFlag
= ((PSYSTEM_FLAGS_INFORMATION
) Buffer
)->Flags
;
984 return STATUS_SUCCESS
;
987 /* Class 10 - Call Time Information */
988 QSI_DEF(SystemCallTimeInformation
)
991 DPRINT1("NtQuerySystemInformation - SystemCallTimeInformation not implemented\n");
992 return STATUS_NOT_IMPLEMENTED
;
995 /* Class 11 - Module Information */
996 QSI_DEF(SystemModuleInformation
)
1000 /* Acquire system module list lock */
1001 KeEnterCriticalRegion();
1002 ExAcquireResourceExclusiveLite(&PsLoadedModuleResource
, TRUE
);
1004 /* Call the generic handler with the system module list */
1005 Status
= ExpQueryModuleInformation(&PsLoadedModuleList
,
1006 &MmLoadedUserImageList
,
1007 (PRTL_PROCESS_MODULES
)Buffer
,
1011 /* Release list lock and return status */
1012 ExReleaseResourceLite(&PsLoadedModuleResource
);
1013 KeLeaveCriticalRegion();
1017 /* Class 12 - Locks Information */
1018 QSI_DEF(SystemLocksInformation
)
1021 DPRINT1("NtQuerySystemInformation - SystemLocksInformation not implemented\n");
1022 return STATUS_NOT_IMPLEMENTED
;
1025 /* Class 13 - Stack Trace Information */
1026 QSI_DEF(SystemStackTraceInformation
)
1029 DPRINT1("NtQuerySystemInformation - SystemStackTraceInformation not implemented\n");
1030 return STATUS_NOT_IMPLEMENTED
;
1033 /* Class 14 - Paged Pool Information */
1034 QSI_DEF(SystemPagedPoolInformation
)
1037 DPRINT1("NtQuerySystemInformation - SystemPagedPoolInformation not implemented\n");
1038 return STATUS_NOT_IMPLEMENTED
;
1041 /* Class 15 - Non Paged Pool Information */
1042 QSI_DEF(SystemNonPagedPoolInformation
)
1045 DPRINT1("NtQuerySystemInformation - SystemNonPagedPoolInformation not implemented\n");
1046 return STATUS_NOT_IMPLEMENTED
;
1050 /* Class 16 - Handle Information */
1051 QSI_DEF(SystemHandleInformation
)
1053 PEPROCESS pr
, syspr
;
1054 ULONG curSize
, i
= 0;
1057 PSYSTEM_HANDLE_INFORMATION Shi
=
1058 (PSYSTEM_HANDLE_INFORMATION
) Buffer
;
1060 DPRINT("NtQuerySystemInformation - SystemHandleInformation\n");
1062 if (Size
< sizeof(SYSTEM_HANDLE_INFORMATION
))
1064 *ReqSize
= sizeof(SYSTEM_HANDLE_INFORMATION
);
1065 return STATUS_INFO_LENGTH_MISMATCH
;
1068 DPRINT("SystemHandleInformation 1\n");
1070 /* First Calc Size from Count. */
1071 syspr
= PsGetNextProcess(NULL
);
1076 hCount
= hCount
+ ObGetProcessHandleCount(pr
);
1077 pr
= PsGetNextProcess(pr
);
1079 if ((pr
== syspr
) || (pr
== NULL
)) break;
1081 while ((pr
!= syspr
) && (pr
!= NULL
));
1085 ObDereferenceObject(pr
);
1088 DPRINT("SystemHandleInformation 2\n");
1090 curSize
= sizeof(SYSTEM_HANDLE_INFORMATION
) +
1091 ((sizeof(SYSTEM_HANDLE_TABLE_ENTRY_INFO
) * hCount
) -
1092 (sizeof(SYSTEM_HANDLE_TABLE_ENTRY_INFO
)));
1094 Shi
->NumberOfHandles
= hCount
;
1099 return (STATUS_INFO_LENGTH_MISMATCH
);
1102 DPRINT("SystemHandleInformation 3\n");
1104 /* Now get Handles from all processs. */
1105 syspr
= PsGetNextProcess(NULL
);
1110 int Count
= 0, HandleCount
;
1112 HandleCount
= ObGetProcessHandleCount(pr
);
1114 for (Count
= 0; HandleCount
> 0 ; HandleCount
--)
1116 Shi
->Handles
[i
].UniqueProcessId
= (USHORT
)(ULONG_PTR
)pr
->UniqueProcessId
;
1121 pr
= PsGetNextProcess(pr
);
1123 if ((pr
== syspr
) || (pr
== NULL
)) break;
1125 while ((pr
!= syspr
) && (pr
!= NULL
));
1127 if(pr
!= NULL
) ObDereferenceObject(pr
);
1129 DPRINT("SystemHandleInformation 4\n");
1130 return STATUS_SUCCESS
;
1134 SSI_DEF(SystemHandleInformation)
1137 return STATUS_SUCCESS;
1141 /* Class 17 - Information */
1142 QSI_DEF(SystemObjectInformation
)
1145 DPRINT1("NtQuerySystemInformation - SystemObjectInformation not implemented\n");
1146 return STATUS_NOT_IMPLEMENTED
;
1149 /* Class 18 - Information */
1150 QSI_DEF(SystemPageFileInformation
)
1152 UNICODE_STRING FileName
; /* FIXME */
1153 SYSTEM_PAGEFILE_INFORMATION
*Spfi
= (SYSTEM_PAGEFILE_INFORMATION
*) Buffer
;
1155 if (Size
< sizeof(SYSTEM_PAGEFILE_INFORMATION
))
1157 * ReqSize
= sizeof(SYSTEM_PAGEFILE_INFORMATION
);
1158 return STATUS_INFO_LENGTH_MISMATCH
;
1161 RtlInitUnicodeString(&FileName
, NULL
); /* FIXME */
1164 Spfi
->NextEntryOffset
= 0;
1166 Spfi
->TotalSize
= MiFreeSwapPages
+ MiUsedSwapPages
;
1167 Spfi
->TotalInUse
= MiUsedSwapPages
;
1168 Spfi
->PeakUsage
= MiUsedSwapPages
; /* FIXME */
1169 Spfi
->PageFileName
= FileName
;
1170 return STATUS_SUCCESS
;
1173 /* Class 19 - Vdm Instemul Information */
1174 QSI_DEF(SystemVdmInstemulInformation
)
1177 DPRINT1("NtQuerySystemInformation - SystemVdmInstemulInformation not implemented\n");
1178 return STATUS_NOT_IMPLEMENTED
;
1181 /* Class 20 - Vdm Bop Information */
1182 QSI_DEF(SystemVdmBopInformation
)
1185 DPRINT1("NtQuerySystemInformation - SystemVdmBopInformation not implemented\n");
1186 return STATUS_NOT_IMPLEMENTED
;
1189 /* Class 21 - File Cache Information */
1190 QSI_DEF(SystemFileCacheInformation
)
1192 SYSTEM_FILECACHE_INFORMATION
*Sci
= (SYSTEM_FILECACHE_INFORMATION
*) Buffer
;
1194 if (Size
< sizeof(SYSTEM_FILECACHE_INFORMATION
))
1196 *ReqSize
= sizeof(SYSTEM_FILECACHE_INFORMATION
);
1197 return STATUS_INFO_LENGTH_MISMATCH
;
1200 RtlZeroMemory(Sci
, sizeof(SYSTEM_FILECACHE_INFORMATION
));
1202 /* Return the Byte size not the page size. */
1204 MiMemoryConsumers
[MC_CACHE
].PagesUsed
* PAGE_SIZE
;
1206 MiMemoryConsumers
[MC_CACHE
].PagesUsed
* PAGE_SIZE
; /* FIXME */
1207 /* Taskmgr multiplies this one by page size right away */
1208 Sci
->CurrentSizeIncludingTransitionInPages
=
1209 MiMemoryConsumers
[MC_CACHE
].PagesUsed
; /* FIXME: Should be */
1210 /* system working set and standby pages. */
1211 Sci
->PageFaultCount
= 0; /* FIXME */
1212 Sci
->MinimumWorkingSet
= 0; /* FIXME */
1213 Sci
->MaximumWorkingSet
= 0; /* FIXME */
1215 return STATUS_SUCCESS
;
1218 SSI_DEF(SystemFileCacheInformation
)
1220 if (Size
< sizeof(SYSTEM_FILECACHE_INFORMATION
))
1222 return STATUS_INFO_LENGTH_MISMATCH
;
1225 DPRINT1("NtSetSystemInformation - SystemFileCacheInformation not implemented\n");
1226 return STATUS_NOT_IMPLEMENTED
;
1229 /* Class 22 - Pool Tag Information */
1230 QSI_DEF(SystemPoolTagInformation
)
1233 DPRINT1("NtQuerySystemInformation - SystemPoolTagInformation not implemented\n");
1234 return STATUS_NOT_IMPLEMENTED
;
1237 /* Class 23 - Interrupt Information for all processors */
1238 QSI_DEF(SystemInterruptInformation
)
1243 PSYSTEM_INTERRUPT_INFORMATION sii
= (PSYSTEM_INTERRUPT_INFORMATION
)Buffer
;
1245 if(Size
< KeNumberProcessors
* sizeof(SYSTEM_INTERRUPT_INFORMATION
))
1247 return STATUS_INFO_LENGTH_MISMATCH
;
1250 ti
= KeQueryTimeIncrement();
1252 for (i
= 0; i
< KeNumberProcessors
; i
++)
1254 Prcb
= KiProcessorBlock
[i
];
1255 sii
->ContextSwitches
= KeGetContextSwitches(Prcb
);
1256 sii
->DpcCount
= Prcb
->DpcData
[0].DpcCount
;
1257 sii
->DpcRate
= Prcb
->DpcRequestRate
;
1258 sii
->TimeIncrement
= ti
;
1259 sii
->DpcBypassCount
= 0;
1260 sii
->ApcBypassCount
= 0;
1264 return STATUS_SUCCESS
;
1267 /* Class 24 - DPC Behaviour Information */
1268 QSI_DEF(SystemDpcBehaviourInformation
)
1271 DPRINT1("NtQuerySystemInformation - SystemDpcBehaviourInformation not implemented\n");
1272 return STATUS_NOT_IMPLEMENTED
;
1275 SSI_DEF(SystemDpcBehaviourInformation
)
1278 DPRINT1("NtSetSystemInformation - SystemDpcBehaviourInformation not implemented\n");
1279 return STATUS_NOT_IMPLEMENTED
;
1282 /* Class 25 - Full Memory Information */
1283 QSI_DEF(SystemFullMemoryInformation
)
1285 PULONG Spi
= (PULONG
) Buffer
;
1287 PEPROCESS TheIdleProcess
;
1289 *ReqSize
= sizeof(ULONG
);
1291 if (sizeof(ULONG
) != Size
)
1293 return STATUS_INFO_LENGTH_MISMATCH
;
1296 DPRINT("SystemFullMemoryInformation\n");
1298 TheIdleProcess
= PsIdleProcess
;
1300 DPRINT("PID: %d, KernelTime: %u PFFree: %d PFUsed: %d\n",
1301 TheIdleProcess
->UniqueProcessId
,
1302 TheIdleProcess
->Pcb
.KernelTime
,
1307 MmPrintMemoryStatistic();
1310 *Spi
= MiMemoryConsumers
[MC_USER
].PagesUsed
;
1312 return STATUS_SUCCESS
;
1315 /* Class 26 - Load Image */
1316 SSI_DEF(SystemLoadGdiDriverInformation
)
1318 PSYSTEM_GDI_DRIVER_INFORMATION DriverInfo
= (PVOID
)Buffer
;
1319 UNICODE_STRING ImageName
;
1321 PVOID SectionPointer
;
1322 ULONG_PTR EntryPoint
;
1325 PIMAGE_NT_HEADERS NtHeader
;
1328 if (Size
!= sizeof(SYSTEM_GDI_DRIVER_INFORMATION
))
1330 /* Incorrect buffer length, fail */
1331 return STATUS_INFO_LENGTH_MISMATCH
;
1334 /* Only kernel mode can call this function */
1335 if (ExGetPreviousMode() != KernelMode
) return STATUS_PRIVILEGE_NOT_HELD
;
1337 /* Load the driver */
1338 ImageName
= DriverInfo
->DriverName
;
1339 Status
= MmLoadSystemImage(&ImageName
,
1345 if (!NT_SUCCESS(Status
)) return Status
;
1347 /* Return the export pointer */
1348 DriverInfo
->ExportSectionPointer
=
1349 RtlImageDirectoryEntryToData(ImageBase
,
1351 IMAGE_DIRECTORY_ENTRY_EXPORT
,
1354 /* Get the entrypoint */
1355 NtHeader
= RtlImageNtHeader(ImageBase
);
1356 EntryPoint
= NtHeader
->OptionalHeader
.AddressOfEntryPoint
;
1357 EntryPoint
+= (ULONG_PTR
)ImageBase
;
1359 /* Save other data */
1360 DriverInfo
->ImageAddress
= ImageBase
;
1361 DriverInfo
->SectionPointer
= SectionPointer
;
1362 DriverInfo
->EntryPoint
= (PVOID
)EntryPoint
;
1363 DriverInfo
->ImageLength
= NtHeader
->OptionalHeader
.SizeOfImage
;
1366 return STATUS_SUCCESS
;
1369 /* Class 27 - Unload Image */
1370 SSI_DEF(SystemUnloadGdiDriverInformation
)
1372 PVOID SectionPointer
= Buffer
;
1375 if (Size
!= sizeof(PVOID
))
1377 /* Incorrect length, fail */
1378 return STATUS_INFO_LENGTH_MISMATCH
;
1381 /* Only kernel mode can call this function */
1382 if (ExGetPreviousMode() != KernelMode
) return STATUS_PRIVILEGE_NOT_HELD
;
1384 /* Unload the image */
1385 MmUnloadSystemImage(SectionPointer
);
1386 return STATUS_SUCCESS
;
1389 /* Class 28 - Time Adjustment Information */
1390 QSI_DEF(SystemTimeAdjustmentInformation
)
1392 PSYSTEM_QUERY_TIME_ADJUST_INFORMATION TimeInfo
=
1393 (PSYSTEM_QUERY_TIME_ADJUST_INFORMATION
)Buffer
;
1395 /* Check if enough storage was provided */
1396 if (sizeof(SYSTEM_QUERY_TIME_ADJUST_INFORMATION
) > Size
)
1398 * ReqSize
= sizeof(SYSTEM_QUERY_TIME_ADJUST_INFORMATION
);
1399 return STATUS_INFO_LENGTH_MISMATCH
;
1402 /* Give time values to our caller */
1403 TimeInfo
->TimeIncrement
= KeMaximumIncrement
;
1404 TimeInfo
->TimeAdjustment
= KeTimeAdjustment
;
1405 TimeInfo
->Enable
= TRUE
;
1407 return STATUS_SUCCESS
;
1410 SSI_DEF(SystemTimeAdjustmentInformation
)
1412 KPROCESSOR_MODE PreviousMode
= KeGetPreviousMode();
1413 /*PSYSTEM_SET_TIME_ADJUST_INFORMATION TimeInfo =
1414 (PSYSTEM_SET_TIME_ADJUST_INFORMATION)Buffer;*/
1416 /* Check size of a buffer, it must match our expectations */
1417 if (sizeof(SYSTEM_SET_TIME_ADJUST_INFORMATION
) != Size
)
1418 return STATUS_INFO_LENGTH_MISMATCH
;
1420 /* Check who is calling */
1421 if (PreviousMode
!= KernelMode
)
1423 /* Check access rights */
1424 if (!SeSinglePrivilegeCheck(SeSystemtimePrivilege
, PreviousMode
))
1426 return STATUS_PRIVILEGE_NOT_HELD
;
1430 /* TODO: Set time adjustment information */
1431 DPRINT1("Setting of SystemTimeAdjustmentInformation is not implemented yet!\n");
1432 return STATUS_NOT_IMPLEMENTED
;
1435 /* Class 29 - Summary Memory Information */
1436 QSI_DEF(SystemSummaryMemoryInformation
)
1439 DPRINT1("NtQuerySystemInformation - SystemSummaryMemoryInformation not implemented\n");
1440 return STATUS_NOT_IMPLEMENTED
;
1443 /* Class 30 - Next Event Id Information */
1444 QSI_DEF(SystemNextEventIdInformation
)
1447 DPRINT1("NtQuerySystemInformation - SystemNextEventIdInformation not implemented\n");
1448 return STATUS_NOT_IMPLEMENTED
;
1451 /* Class 31 - Event Ids Information */
1452 QSI_DEF(SystemEventIdsInformation
)
1455 DPRINT1("NtQuerySystemInformation - SystemEventIdsInformation not implemented\n");
1456 return STATUS_NOT_IMPLEMENTED
;
1459 /* Class 32 - Crash Dump Information */
1460 QSI_DEF(SystemCrashDumpInformation
)
1463 DPRINT1("NtQuerySystemInformation - SystemCrashDumpInformation not implemented\n");
1464 return STATUS_NOT_IMPLEMENTED
;
1467 /* Class 33 - Exception Information */
1468 QSI_DEF(SystemExceptionInformation
)
1470 PSYSTEM_EXCEPTION_INFORMATION ExceptionInformation
=
1471 (PSYSTEM_EXCEPTION_INFORMATION
)Buffer
;
1473 ULONG i
, AlignmentFixupCount
= 0, ExceptionDispatchCount
= 0;
1474 ULONG FloatingEmulationCount
= 0, ByteWordEmulationCount
= 0;
1476 /* Check size of a buffer, it must match our expectations */
1477 if (sizeof(SYSTEM_EXCEPTION_INFORMATION
) != Size
)
1478 return STATUS_INFO_LENGTH_MISMATCH
;
1480 /* Sum up exception count information from all processors */
1481 for (i
= 0; i
< KeNumberProcessors
; i
++)
1483 Prcb
= KiProcessorBlock
[i
];
1486 AlignmentFixupCount
+= Prcb
->KeAlignmentFixupCount
;
1487 ExceptionDispatchCount
+= Prcb
->KeExceptionDispatchCount
;
1488 FloatingEmulationCount
+= Prcb
->KeFloatingEmulationCount
;
1492 /* Save information in user's buffer */
1493 ExceptionInformation
->AlignmentFixupCount
= AlignmentFixupCount
;
1494 ExceptionInformation
->ExceptionDispatchCount
= ExceptionDispatchCount
;
1495 ExceptionInformation
->FloatingEmulationCount
= FloatingEmulationCount
;
1496 ExceptionInformation
->ByteWordEmulationCount
= ByteWordEmulationCount
;
1498 return STATUS_SUCCESS
;
1501 /* Class 34 - Crash Dump State Information */
1502 QSI_DEF(SystemCrashDumpStateInformation
)
1505 DPRINT1("NtQuerySystemInformation - SystemCrashDumpStateInformation not implemented\n");
1506 return STATUS_NOT_IMPLEMENTED
;
1509 /* Class 35 - Kernel Debugger Information */
1510 QSI_DEF(SystemKernelDebuggerInformation
)
1512 PSYSTEM_KERNEL_DEBUGGER_INFORMATION skdi
= (PSYSTEM_KERNEL_DEBUGGER_INFORMATION
) Buffer
;
1514 *ReqSize
= sizeof(SYSTEM_KERNEL_DEBUGGER_INFORMATION
);
1515 if (Size
< sizeof(SYSTEM_KERNEL_DEBUGGER_INFORMATION
))
1517 return STATUS_INFO_LENGTH_MISMATCH
;
1520 skdi
->KernelDebuggerEnabled
= KD_DEBUGGER_ENABLED
;
1521 skdi
->KernelDebuggerNotPresent
= KD_DEBUGGER_NOT_PRESENT
;
1523 return STATUS_SUCCESS
;
1526 /* Class 36 - Context Switch Information */
1527 QSI_DEF(SystemContextSwitchInformation
)
1529 PSYSTEM_CONTEXT_SWITCH_INFORMATION ContextSwitchInformation
=
1530 (PSYSTEM_CONTEXT_SWITCH_INFORMATION
)Buffer
;
1531 ULONG ContextSwitches
, i
;
1534 /* Check size of a buffer, it must match our expectations */
1535 if (sizeof(SYSTEM_CONTEXT_SWITCH_INFORMATION
) != Size
)
1536 return STATUS_INFO_LENGTH_MISMATCH
;
1538 /* Calculate total value of context switches across all processors */
1539 ContextSwitches
= 0;
1540 for (i
= 0; i
< KeNumberProcessors
; i
++)
1542 Prcb
= KiProcessorBlock
[i
];
1545 ContextSwitches
+= KeGetContextSwitches(Prcb
);
1549 ContextSwitchInformation
->ContextSwitches
= ContextSwitches
;
1552 ContextSwitchInformation
->FindAny
= 0;
1553 ContextSwitchInformation
->FindLast
= 0;
1554 ContextSwitchInformation
->FindIdeal
= 0;
1555 ContextSwitchInformation
->IdleAny
= 0;
1556 ContextSwitchInformation
->IdleCurrent
= 0;
1557 ContextSwitchInformation
->IdleLast
= 0;
1558 ContextSwitchInformation
->IdleIdeal
= 0;
1559 ContextSwitchInformation
->PreemptAny
= 0;
1560 ContextSwitchInformation
->PreemptCurrent
= 0;
1561 ContextSwitchInformation
->PreemptLast
= 0;
1562 ContextSwitchInformation
->SwitchToIdle
= 0;
1564 return STATUS_SUCCESS
;
1567 /* Class 37 - Registry Quota Information */
1568 QSI_DEF(SystemRegistryQuotaInformation
)
1570 PSYSTEM_REGISTRY_QUOTA_INFORMATION srqi
= (PSYSTEM_REGISTRY_QUOTA_INFORMATION
) Buffer
;
1572 *ReqSize
= sizeof(SYSTEM_REGISTRY_QUOTA_INFORMATION
);
1573 if (Size
< sizeof(SYSTEM_REGISTRY_QUOTA_INFORMATION
))
1575 return STATUS_INFO_LENGTH_MISMATCH
;
1578 DPRINT1("Faking max registry size of 32 MB\n");
1579 srqi
->RegistryQuotaAllowed
= 0x2000000;
1580 srqi
->RegistryQuotaUsed
= 0x200000;
1581 srqi
->PagedPoolSize
= 0x200000;
1583 return STATUS_SUCCESS
;
1586 SSI_DEF(SystemRegistryQuotaInformation
)
1589 DPRINT1("NtSetSystemInformation - SystemRegistryQuotaInformation not implemented\n");
1590 return STATUS_NOT_IMPLEMENTED
;
1593 /* Class 38 - Load And Call Image */
1594 SSI_DEF(SystemExtendServiceTableInformation
)
1596 UNICODE_STRING ImageName
;
1597 KPROCESSOR_MODE PreviousMode
= KeGetPreviousMode();
1598 PLDR_DATA_TABLE_ENTRY ModuleObject
;
1600 PIMAGE_NT_HEADERS NtHeader
;
1601 DRIVER_OBJECT Win32k
;
1602 PDRIVER_INITIALIZE DriverInit
;
1604 ULONG_PTR EntryPoint
;
1606 /* Validate the size */
1607 if (Size
!= sizeof(UNICODE_STRING
)) return STATUS_INFO_LENGTH_MISMATCH
;
1609 /* Check who is calling */
1610 if (PreviousMode
!= KernelMode
)
1612 /* Make sure we can load drivers */
1613 if (!SeSinglePrivilegeCheck(SeLoadDriverPrivilege
, UserMode
))
1615 /* FIXME: We can't, fail */
1616 //return STATUS_PRIVILEGE_NOT_HELD;
1620 /* Probe and capture the driver name */
1621 ProbeAndCaptureUnicodeString(&ImageName
, PreviousMode
, Buffer
);
1623 /* Load the image */
1624 Status
= MmLoadSystemImage(&ImageName
,
1628 (PVOID
)&ModuleObject
,
1631 /* Release String */
1632 ReleaseCapturedUnicodeString(&ImageName
, PreviousMode
);
1634 if (!NT_SUCCESS(Status
)) return Status
;
1636 /* Get the headers */
1637 NtHeader
= RtlImageNtHeader(ImageBase
);
1641 MmUnloadSystemImage(ModuleObject
);
1642 return STATUS_INVALID_IMAGE_FORMAT
;
1645 /* Get the entrypoint */
1646 EntryPoint
= NtHeader
->OptionalHeader
.AddressOfEntryPoint
;
1647 EntryPoint
+= (ULONG_PTR
)ImageBase
;
1648 DriverInit
= (PDRIVER_INITIALIZE
)EntryPoint
;
1650 /* Create a dummy device */
1651 RtlZeroMemory(&Win32k
, sizeof(Win32k
));
1652 ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL
);
1653 Win32k
.DriverStart
= ImageBase
;
1656 Status
= (DriverInit
)(&Win32k
, NULL
);
1657 ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL
);
1659 /* Unload if we failed */
1660 if (!NT_SUCCESS(Status
)) MmUnloadSystemImage(ModuleObject
);
1664 /* Class 39 - Priority Separation */
1665 SSI_DEF(SystemPrioritySeperation
)
1668 DPRINT1("NtSetSystemInformation - SystemPrioritySeperation not implemented\n");
1669 return STATUS_NOT_IMPLEMENTED
;
1672 /* Class 40 - Plug Play Bus Information */
1673 QSI_DEF(SystemPlugPlayBusInformation
)
1676 DPRINT1("NtQuerySystemInformation - SystemPlugPlayBusInformation not implemented\n");
1677 return STATUS_NOT_IMPLEMENTED
;
1680 /* Class 41 - Dock Information */
1681 QSI_DEF(SystemDockInformation
)
1684 DPRINT1("NtQuerySystemInformation - SystemDockInformation not implemented\n");
1685 return STATUS_NOT_IMPLEMENTED
;
1688 /* Class 42 - Power Information */
1689 QSI_DEF(SystemPowerInformation
)
1692 DPRINT1("NtQuerySystemInformation - SystemPowerInformation not implemented\n");
1693 return STATUS_NOT_IMPLEMENTED
;
1696 /* Class 43 - Processor Speed Information */
1697 QSI_DEF(SystemProcessorSpeedInformation
)
1700 DPRINT1("NtQuerySystemInformation - SystemProcessorSpeedInformation not implemented\n");
1701 return STATUS_NOT_IMPLEMENTED
;
1704 /* Class 44 - Current Time Zone Information */
1705 QSI_DEF(SystemCurrentTimeZoneInformation
)
1707 *ReqSize
= sizeof(TIME_ZONE_INFORMATION
);
1709 if (sizeof(TIME_ZONE_INFORMATION
) != Size
)
1711 return STATUS_INFO_LENGTH_MISMATCH
;
1714 /* Copy the time zone information struct */
1717 sizeof(TIME_ZONE_INFORMATION
));
1719 return STATUS_SUCCESS
;
1723 SSI_DEF(SystemCurrentTimeZoneInformation
)
1725 /* Check user buffer's size */
1726 if (Size
< sizeof(TIME_ZONE_INFORMATION
))
1728 return STATUS_INFO_LENGTH_MISMATCH
;
1731 return ExpSetTimeZoneInformation((PTIME_ZONE_INFORMATION
)Buffer
);
1735 /* Class 45 - Lookaside Information */
1736 QSI_DEF(SystemLookasideInformation
)
1739 DPRINT1("NtQuerySystemInformation - SystemLookasideInformation not implemented\n");
1740 return STATUS_NOT_IMPLEMENTED
;
1744 /* Class 46 - Set time slip event */
1745 SSI_DEF(SystemSetTimeSlipEvent
)
1748 DPRINT1("NtSetSystemInformation - SystemSetTimSlipEvent not implemented\n");
1749 return STATUS_NOT_IMPLEMENTED
;
1753 /* Class 47 - Create a new session (TSE) */
1754 SSI_DEF(SystemCreateSession
)
1757 DPRINT1("NtSetSystemInformation - SystemCreateSession not implemented\n");
1758 return STATUS_NOT_IMPLEMENTED
;
1762 /* Class 48 - Delete an existing session (TSE) */
1763 SSI_DEF(SystemDeleteSession
)
1766 DPRINT1("NtSetSystemInformation - SystemDeleteSession not implemented\n");
1767 return STATUS_NOT_IMPLEMENTED
;
1771 /* Class 49 - UNKNOWN */
1772 QSI_DEF(SystemInvalidInfoClass4
)
1775 DPRINT1("NtQuerySystemInformation - SystemInvalidInfoClass4 not implemented\n");
1776 return STATUS_NOT_IMPLEMENTED
;
1780 /* Class 50 - System range start address */
1781 QSI_DEF(SystemRangeStartInformation
)
1784 DPRINT1("NtQuerySystemInformation - SystemRangeStartInformation not implemented\n");
1785 return STATUS_NOT_IMPLEMENTED
;
1789 /* Class 51 - Driver verifier information */
1790 QSI_DEF(SystemVerifierInformation
)
1793 DPRINT1("NtQuerySystemInformation - SystemVerifierInformation not implemented\n");
1794 return STATUS_NOT_IMPLEMENTED
;
1798 SSI_DEF(SystemVerifierInformation
)
1801 DPRINT1("NtSetSystemInformation - SystemVerifierInformation not implemented\n");
1802 return STATUS_NOT_IMPLEMENTED
;
1806 /* Class 52 - Add a driver verifier */
1807 SSI_DEF(SystemAddVerifier
)
1810 DPRINT1("NtSetSystemInformation - SystemAddVerifier not implemented\n");
1811 return STATUS_NOT_IMPLEMENTED
;
1815 /* Class 53 - A session's processes */
1816 QSI_DEF(SystemSessionProcessesInformation
)
1819 DPRINT1("NtQuerySystemInformation - SystemSessionProcessInformation not implemented\n");
1820 return STATUS_NOT_IMPLEMENTED
;
1824 /* Query/Set Calls Table */
1828 NTSTATUS (* Query
) (PVOID
,ULONG
,PULONG
);
1829 NTSTATUS (* Set
) (PVOID
,ULONG
);
1836 // XX unknown behaviour
1838 #define SI_QS(n) {QSI_USE(n),SSI_USE(n)}
1839 #define SI_QX(n) {QSI_USE(n),NULL}
1840 #define SI_XS(n) {NULL,SSI_USE(n)}
1841 #define SI_XX(n) {NULL,NULL}
1847 SI_QX(SystemBasicInformation
),
1848 SI_QX(SystemProcessorInformation
),
1849 SI_QX(SystemPerformanceInformation
),
1850 SI_QX(SystemTimeOfDayInformation
),
1851 SI_QX(SystemPathInformation
), /* should be SI_XX */
1852 SI_QX(SystemProcessInformation
),
1853 SI_QX(SystemCallCountInformation
),
1854 SI_QX(SystemDeviceInformation
),
1855 SI_QX(SystemProcessorPerformanceInformation
),
1856 SI_QS(SystemFlagsInformation
),
1857 SI_QX(SystemCallTimeInformation
), /* should be SI_XX */
1858 SI_QX(SystemModuleInformation
),
1859 SI_QX(SystemLocksInformation
),
1860 SI_QX(SystemStackTraceInformation
), /* should be SI_XX */
1861 SI_QX(SystemPagedPoolInformation
), /* should be SI_XX */
1862 SI_QX(SystemNonPagedPoolInformation
), /* should be SI_XX */
1863 SI_QX(SystemHandleInformation
),
1864 SI_QX(SystemObjectInformation
),
1865 SI_QX(SystemPageFileInformation
),
1866 SI_QX(SystemVdmInstemulInformation
),
1867 SI_QX(SystemVdmBopInformation
), /* it should be SI_XX */
1868 SI_QS(SystemFileCacheInformation
),
1869 SI_QX(SystemPoolTagInformation
),
1870 SI_QX(SystemInterruptInformation
),
1871 SI_QS(SystemDpcBehaviourInformation
),
1872 SI_QX(SystemFullMemoryInformation
), /* it should be SI_XX */
1873 SI_XS(SystemLoadGdiDriverInformation
),
1874 SI_XS(SystemUnloadGdiDriverInformation
),
1875 SI_QS(SystemTimeAdjustmentInformation
),
1876 SI_QX(SystemSummaryMemoryInformation
), /* it should be SI_XX */
1877 SI_QX(SystemNextEventIdInformation
), /* it should be SI_XX */
1878 SI_QX(SystemEventIdsInformation
), /* it should be SI_XX */
1879 SI_QX(SystemCrashDumpInformation
),
1880 SI_QX(SystemExceptionInformation
),
1881 SI_QX(SystemCrashDumpStateInformation
),
1882 SI_QX(SystemKernelDebuggerInformation
),
1883 SI_QX(SystemContextSwitchInformation
),
1884 SI_QS(SystemRegistryQuotaInformation
),
1885 SI_XS(SystemExtendServiceTableInformation
),
1886 SI_XS(SystemPrioritySeperation
),
1887 SI_QX(SystemPlugPlayBusInformation
), /* it should be SI_XX */
1888 SI_QX(SystemDockInformation
), /* it should be SI_XX */
1889 SI_QX(SystemPowerInformation
), /* it should be SI_XX */
1890 SI_QX(SystemProcessorSpeedInformation
), /* it should be SI_XX */
1891 SI_QS(SystemCurrentTimeZoneInformation
), /* it should be SI_QX */
1892 SI_QX(SystemLookasideInformation
),
1893 SI_XS(SystemSetTimeSlipEvent
),
1894 SI_XS(SystemCreateSession
),
1895 SI_XS(SystemDeleteSession
),
1896 SI_QX(SystemInvalidInfoClass4
), /* it should be SI_XX */
1897 SI_QX(SystemRangeStartInformation
),
1898 SI_QS(SystemVerifierInformation
),
1899 SI_XS(SystemAddVerifier
),
1900 SI_QX(SystemSessionProcessesInformation
)
1903 C_ASSERT(SystemBasicInformation
== 0);
1904 #define MIN_SYSTEM_INFO_CLASS (SystemBasicInformation)
1905 #define MAX_SYSTEM_INFO_CLASS (sizeof(CallQS) / sizeof(CallQS[0]))
1911 NtQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInformationClass
,
1912 OUT PVOID SystemInformation
,
1914 OUT PULONG UnsafeResultLength
)
1916 KPROCESSOR_MODE PreviousMode
;
1918 NTSTATUS FStatus
= STATUS_NOT_IMPLEMENTED
;
1922 PreviousMode
= ExGetPreviousMode();
1926 if (PreviousMode
!= KernelMode
)
1928 /* SystemKernelDebuggerInformation needs only BOOLEAN alignment */
1929 ProbeForWrite(SystemInformation
, Length
, 1);
1930 if (UnsafeResultLength
!= NULL
)
1931 ProbeForWriteUlong(UnsafeResultLength
);
1935 * Check the request is valid.
1937 if (SystemInformationClass
>= MAX_SYSTEM_INFO_CLASS
)
1939 _SEH2_YIELD(return STATUS_INVALID_INFO_CLASS
);
1942 if (NULL
!= CallQS
[SystemInformationClass
].Query
)
1945 * Hand the request to a subhandler.
1947 FStatus
= CallQS
[SystemInformationClass
].Query(SystemInformation
,
1950 if (UnsafeResultLength
!= NULL
)
1952 if (PreviousMode
!= KernelMode
)
1954 *UnsafeResultLength
= ResultLength
;
1958 *UnsafeResultLength
= ResultLength
;
1963 _SEH2_EXCEPT(ExSystemExceptionFilter())
1965 FStatus
= _SEH2_GetExceptionCode();
1975 NtSetSystemInformation (IN SYSTEM_INFORMATION_CLASS SystemInformationClass
,
1976 IN PVOID SystemInformation
,
1977 IN ULONG SystemInformationLength
)
1982 * If called from user mode, check
1983 * possible unsafe arguments.
1986 if (KernelMode
!= KeGetPreviousMode())
1990 // SystemInformation,
2000 * Check the request is valid.
2002 if ((SystemInformationClass
>= MIN_SYSTEM_INFO_CLASS
) &&
2003 (SystemInformationClass
< MAX_SYSTEM_INFO_CLASS
))
2005 if (NULL
!= CallQS
[SystemInformationClass
].Set
)
2008 * Hand the request to a subhandler.
2010 return CallQS
[SystemInformationClass
].Set(SystemInformation
,
2011 SystemInformationLength
);
2015 return STATUS_INVALID_INFO_CLASS
;
2020 NtFlushInstructionCache(IN HANDLE ProcessHandle
,
2021 IN PVOID BaseAddress
,
2022 IN ULONG NumberOfBytesToFlush
)
2026 #if defined(_M_IX86) || defined(_M_AMD64)
2028 #elif defined(_M_PPC)
2029 __asm__
__volatile__("tlbsync");
2030 #elif defined(_M_MIPS)
2031 DPRINT1("NtFlushInstructionCache() is not implemented\n");
2033 #elif defined(_M_ARM)
2034 __asm__
__volatile__("mov r1, #0; mcr p15, 0, r1, c7, c5, 0");
2036 #error Unknown architecture
2038 return STATUS_SUCCESS
;
2043 NtGetCurrentProcessorNumber(VOID
)
2045 /* Just return the CPU */
2046 return KeGetCurrentProcessorNumber();
2052 #undef ExGetPreviousMode
2055 ExGetPreviousMode (VOID
)
2057 return KeGetPreviousMode();