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
= MmPagedPoolSize
; /* 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
)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
)
1471 DPRINT1("NtQuerySystemInformation - SystemExceptionInformation not implemented\n");
1472 return STATUS_NOT_IMPLEMENTED
;
1475 /* Class 34 - Crash Dump State Information */
1476 QSI_DEF(SystemCrashDumpStateInformation
)
1479 DPRINT1("NtQuerySystemInformation - SystemCrashDumpStateInformation not implemented\n");
1480 return STATUS_NOT_IMPLEMENTED
;
1483 /* Class 35 - Kernel Debugger Information */
1484 QSI_DEF(SystemKernelDebuggerInformation
)
1486 PSYSTEM_KERNEL_DEBUGGER_INFORMATION skdi
= (PSYSTEM_KERNEL_DEBUGGER_INFORMATION
) Buffer
;
1488 *ReqSize
= sizeof(SYSTEM_KERNEL_DEBUGGER_INFORMATION
);
1489 if (Size
< sizeof(SYSTEM_KERNEL_DEBUGGER_INFORMATION
))
1491 return STATUS_INFO_LENGTH_MISMATCH
;
1494 skdi
->KernelDebuggerEnabled
= KD_DEBUGGER_ENABLED
;
1495 skdi
->KernelDebuggerNotPresent
= KD_DEBUGGER_NOT_PRESENT
;
1497 return STATUS_SUCCESS
;
1500 /* Class 36 - Context Switch Information */
1501 QSI_DEF(SystemContextSwitchInformation
)
1504 DPRINT1("NtQuerySystemInformation - SystemContextSwitchInformation not implemented\n");
1505 return STATUS_NOT_IMPLEMENTED
;
1508 /* Class 37 - Registry Quota Information */
1509 QSI_DEF(SystemRegistryQuotaInformation
)
1511 PSYSTEM_REGISTRY_QUOTA_INFORMATION srqi
= (PSYSTEM_REGISTRY_QUOTA_INFORMATION
) Buffer
;
1513 *ReqSize
= sizeof(SYSTEM_REGISTRY_QUOTA_INFORMATION
);
1514 if (Size
< sizeof(SYSTEM_REGISTRY_QUOTA_INFORMATION
))
1516 return STATUS_INFO_LENGTH_MISMATCH
;
1519 DPRINT1("Faking max registry size of 32 MB\n");
1520 srqi
->RegistryQuotaAllowed
= 0x2000000;
1521 srqi
->RegistryQuotaUsed
= 0x200000;
1522 srqi
->PagedPoolSize
= 0x200000;
1524 return STATUS_SUCCESS
;
1527 SSI_DEF(SystemRegistryQuotaInformation
)
1530 DPRINT1("NtSetSystemInformation - SystemRegistryQuotaInformation not implemented\n");
1531 return STATUS_NOT_IMPLEMENTED
;
1534 /* Class 38 - Load And Call Image */
1535 SSI_DEF(SystemExtendServiceTableInformation
)
1537 UNICODE_STRING ImageName
;
1538 KPROCESSOR_MODE PreviousMode
= KeGetPreviousMode();
1539 PLDR_DATA_TABLE_ENTRY ModuleObject
;
1541 PIMAGE_NT_HEADERS NtHeader
;
1542 DRIVER_OBJECT Win32k
;
1543 PDRIVER_INITIALIZE DriverInit
;
1545 ULONG_PTR EntryPoint
;
1547 /* Validate the size */
1548 if (Size
!= sizeof(UNICODE_STRING
)) return STATUS_INFO_LENGTH_MISMATCH
;
1550 /* Check who is calling */
1551 if (PreviousMode
!= KernelMode
)
1553 /* Make sure we can load drivers */
1554 if (!SeSinglePrivilegeCheck(SeLoadDriverPrivilege
, UserMode
))
1556 /* FIXME: We can't, fail */
1557 //return STATUS_PRIVILEGE_NOT_HELD;
1561 /* Probe and capture the driver name */
1562 ProbeAndCaptureUnicodeString(&ImageName
, PreviousMode
, Buffer
);
1564 /* Load the image */
1565 Status
= MmLoadSystemImage(&ImageName
,
1569 (PVOID
)&ModuleObject
,
1572 /* Release String */
1573 ReleaseCapturedUnicodeString(&ImageName
, PreviousMode
);
1575 if (!NT_SUCCESS(Status
)) return Status
;
1577 /* Get the headers */
1578 NtHeader
= RtlImageNtHeader(ImageBase
);
1582 MmUnloadSystemImage(ModuleObject
);
1583 return STATUS_INVALID_IMAGE_FORMAT
;
1586 /* Get the entrypoint */
1587 EntryPoint
= NtHeader
->OptionalHeader
.AddressOfEntryPoint
;
1588 EntryPoint
+= (ULONG_PTR
)ImageBase
;
1589 DriverInit
= (PDRIVER_INITIALIZE
)EntryPoint
;
1591 /* Create a dummy device */
1592 RtlZeroMemory(&Win32k
, sizeof(Win32k
));
1593 ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL
);
1594 Win32k
.DriverStart
= ImageBase
;
1597 Status
= (DriverInit
)(&Win32k
, NULL
);
1598 ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL
);
1600 /* Unload if we failed */
1601 if (!NT_SUCCESS(Status
)) MmUnloadSystemImage(ModuleObject
);
1605 /* Class 39 - Priority Separation */
1606 SSI_DEF(SystemPrioritySeperation
)
1609 DPRINT1("NtSetSystemInformation - SystemPrioritySeperation not implemented\n");
1610 return STATUS_NOT_IMPLEMENTED
;
1613 /* Class 40 - Plug Play Bus Information */
1614 QSI_DEF(SystemPlugPlayBusInformation
)
1617 DPRINT1("NtQuerySystemInformation - SystemPlugPlayBusInformation not implemented\n");
1618 return STATUS_NOT_IMPLEMENTED
;
1621 /* Class 41 - Dock Information */
1622 QSI_DEF(SystemDockInformation
)
1625 DPRINT1("NtQuerySystemInformation - SystemDockInformation not implemented\n");
1626 return STATUS_NOT_IMPLEMENTED
;
1629 /* Class 42 - Power Information */
1630 QSI_DEF(SystemPowerInformation
)
1633 DPRINT1("NtQuerySystemInformation - SystemPowerInformation not implemented\n");
1634 return STATUS_NOT_IMPLEMENTED
;
1637 /* Class 43 - Processor Speed Information */
1638 QSI_DEF(SystemProcessorSpeedInformation
)
1641 DPRINT1("NtQuerySystemInformation - SystemProcessorSpeedInformation not implemented\n");
1642 return STATUS_NOT_IMPLEMENTED
;
1645 /* Class 44 - Current Time Zone Information */
1646 QSI_DEF(SystemCurrentTimeZoneInformation
)
1648 *ReqSize
= sizeof(TIME_ZONE_INFORMATION
);
1650 if (sizeof(TIME_ZONE_INFORMATION
) != Size
)
1652 return STATUS_INFO_LENGTH_MISMATCH
;
1655 /* Copy the time zone information struct */
1658 sizeof(TIME_ZONE_INFORMATION
));
1660 return STATUS_SUCCESS
;
1664 SSI_DEF(SystemCurrentTimeZoneInformation
)
1666 /* Check user buffer's size */
1667 if (Size
< sizeof(TIME_ZONE_INFORMATION
))
1669 return STATUS_INFO_LENGTH_MISMATCH
;
1672 return ExpSetTimeZoneInformation((PTIME_ZONE_INFORMATION
)Buffer
);
1676 /* Class 45 - Lookaside Information */
1677 QSI_DEF(SystemLookasideInformation
)
1680 DPRINT1("NtQuerySystemInformation - SystemLookasideInformation not implemented\n");
1681 return STATUS_NOT_IMPLEMENTED
;
1685 /* Class 46 - Set time slip event */
1686 SSI_DEF(SystemSetTimeSlipEvent
)
1689 DPRINT1("NtSetSystemInformation - SystemSetTimSlipEvent not implemented\n");
1690 return STATUS_NOT_IMPLEMENTED
;
1694 /* Class 47 - Create a new session (TSE) */
1695 SSI_DEF(SystemCreateSession
)
1698 DPRINT1("NtSetSystemInformation - SystemCreateSession not implemented\n");
1699 return STATUS_NOT_IMPLEMENTED
;
1703 /* Class 48 - Delete an existing session (TSE) */
1704 SSI_DEF(SystemDeleteSession
)
1707 DPRINT1("NtSetSystemInformation - SystemDeleteSession not implemented\n");
1708 return STATUS_NOT_IMPLEMENTED
;
1712 /* Class 49 - UNKNOWN */
1713 QSI_DEF(SystemInvalidInfoClass4
)
1716 DPRINT1("NtQuerySystemInformation - SystemInvalidInfoClass4 not implemented\n");
1717 return STATUS_NOT_IMPLEMENTED
;
1721 /* Class 50 - System range start address */
1722 QSI_DEF(SystemRangeStartInformation
)
1725 DPRINT1("NtQuerySystemInformation - SystemRangeStartInformation not implemented\n");
1726 return STATUS_NOT_IMPLEMENTED
;
1730 /* Class 51 - Driver verifier information */
1731 QSI_DEF(SystemVerifierInformation
)
1734 DPRINT1("NtQuerySystemInformation - SystemVerifierInformation not implemented\n");
1735 return STATUS_NOT_IMPLEMENTED
;
1739 SSI_DEF(SystemVerifierInformation
)
1742 DPRINT1("NtSetSystemInformation - SystemVerifierInformation not implemented\n");
1743 return STATUS_NOT_IMPLEMENTED
;
1747 /* Class 52 - Add a driver verifier */
1748 SSI_DEF(SystemAddVerifier
)
1751 DPRINT1("NtSetSystemInformation - SystemAddVerifier not implemented\n");
1752 return STATUS_NOT_IMPLEMENTED
;
1756 /* Class 53 - A session's processes */
1757 QSI_DEF(SystemSessionProcessesInformation
)
1760 DPRINT1("NtQuerySystemInformation - SystemSessionProcessInformation not implemented\n");
1761 return STATUS_NOT_IMPLEMENTED
;
1765 /* Query/Set Calls Table */
1769 NTSTATUS (* Query
) (PVOID
,ULONG
,PULONG
);
1770 NTSTATUS (* Set
) (PVOID
,ULONG
);
1777 // XX unknown behaviour
1779 #define SI_QS(n) {QSI_USE(n),SSI_USE(n)}
1780 #define SI_QX(n) {QSI_USE(n),NULL}
1781 #define SI_XS(n) {NULL,SSI_USE(n)}
1782 #define SI_XX(n) {NULL,NULL}
1788 SI_QX(SystemBasicInformation
),
1789 SI_QX(SystemProcessorInformation
),
1790 SI_QX(SystemPerformanceInformation
),
1791 SI_QX(SystemTimeOfDayInformation
),
1792 SI_QX(SystemPathInformation
), /* should be SI_XX */
1793 SI_QX(SystemProcessInformation
),
1794 SI_QX(SystemCallCountInformation
),
1795 SI_QX(SystemDeviceInformation
),
1796 SI_QX(SystemProcessorPerformanceInformation
),
1797 SI_QS(SystemFlagsInformation
),
1798 SI_QX(SystemCallTimeInformation
), /* should be SI_XX */
1799 SI_QX(SystemModuleInformation
),
1800 SI_QX(SystemLocksInformation
),
1801 SI_QX(SystemStackTraceInformation
), /* should be SI_XX */
1802 SI_QX(SystemPagedPoolInformation
), /* should be SI_XX */
1803 SI_QX(SystemNonPagedPoolInformation
), /* should be SI_XX */
1804 SI_QX(SystemHandleInformation
),
1805 SI_QX(SystemObjectInformation
),
1806 SI_QX(SystemPageFileInformation
),
1807 SI_QX(SystemVdmInstemulInformation
),
1808 SI_QX(SystemVdmBopInformation
), /* it should be SI_XX */
1809 SI_QS(SystemFileCacheInformation
),
1810 SI_QX(SystemPoolTagInformation
),
1811 SI_QX(SystemInterruptInformation
),
1812 SI_QS(SystemDpcBehaviourInformation
),
1813 SI_QX(SystemFullMemoryInformation
), /* it should be SI_XX */
1814 SI_XS(SystemLoadGdiDriverInformation
),
1815 SI_XS(SystemUnloadGdiDriverInformation
),
1816 SI_QS(SystemTimeAdjustmentInformation
),
1817 SI_QX(SystemSummaryMemoryInformation
), /* it should be SI_XX */
1818 SI_QX(SystemNextEventIdInformation
), /* it should be SI_XX */
1819 SI_QX(SystemEventIdsInformation
), /* it should be SI_XX */
1820 SI_QX(SystemCrashDumpInformation
),
1821 SI_QX(SystemExceptionInformation
),
1822 SI_QX(SystemCrashDumpStateInformation
),
1823 SI_QX(SystemKernelDebuggerInformation
),
1824 SI_QX(SystemContextSwitchInformation
),
1825 SI_QS(SystemRegistryQuotaInformation
),
1826 SI_XS(SystemExtendServiceTableInformation
),
1827 SI_XS(SystemPrioritySeperation
),
1828 SI_QX(SystemPlugPlayBusInformation
), /* it should be SI_XX */
1829 SI_QX(SystemDockInformation
), /* it should be SI_XX */
1830 SI_QX(SystemPowerInformation
), /* it should be SI_XX */
1831 SI_QX(SystemProcessorSpeedInformation
), /* it should be SI_XX */
1832 SI_QS(SystemCurrentTimeZoneInformation
), /* it should be SI_QX */
1833 SI_QX(SystemLookasideInformation
),
1834 SI_XS(SystemSetTimeSlipEvent
),
1835 SI_XS(SystemCreateSession
),
1836 SI_XS(SystemDeleteSession
),
1837 SI_QX(SystemInvalidInfoClass4
), /* it should be SI_XX */
1838 SI_QX(SystemRangeStartInformation
),
1839 SI_QS(SystemVerifierInformation
),
1840 SI_XS(SystemAddVerifier
),
1841 SI_QX(SystemSessionProcessesInformation
)
1844 C_ASSERT(SystemBasicInformation
== 0);
1845 #define MIN_SYSTEM_INFO_CLASS (SystemBasicInformation)
1846 #define MAX_SYSTEM_INFO_CLASS (sizeof(CallQS) / sizeof(CallQS[0]))
1852 NtQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInformationClass
,
1853 OUT PVOID SystemInformation
,
1855 OUT PULONG UnsafeResultLength
)
1857 KPROCESSOR_MODE PreviousMode
;
1859 NTSTATUS FStatus
= STATUS_NOT_IMPLEMENTED
;
1863 PreviousMode
= ExGetPreviousMode();
1867 if (PreviousMode
!= KernelMode
)
1869 /* SystemKernelDebuggerInformation needs only BOOLEAN alignment */
1870 ProbeForWrite(SystemInformation
, Length
, 1);
1871 if (UnsafeResultLength
!= NULL
)
1872 ProbeForWriteUlong(UnsafeResultLength
);
1876 * Check the request is valid.
1878 if (SystemInformationClass
>= MAX_SYSTEM_INFO_CLASS
)
1880 _SEH2_YIELD(return STATUS_INVALID_INFO_CLASS
);
1883 if (NULL
!= CallQS
[SystemInformationClass
].Query
)
1886 * Hand the request to a subhandler.
1888 FStatus
= CallQS
[SystemInformationClass
].Query(SystemInformation
,
1891 if (UnsafeResultLength
!= NULL
)
1893 if (PreviousMode
!= KernelMode
)
1895 *UnsafeResultLength
= ResultLength
;
1899 *UnsafeResultLength
= ResultLength
;
1904 _SEH2_EXCEPT(ExSystemExceptionFilter())
1906 FStatus
= _SEH2_GetExceptionCode();
1916 NtSetSystemInformation (IN SYSTEM_INFORMATION_CLASS SystemInformationClass
,
1917 IN PVOID SystemInformation
,
1918 IN ULONG SystemInformationLength
)
1923 * If called from user mode, check
1924 * possible unsafe arguments.
1927 if (KernelMode
!= KeGetPreviousMode())
1931 // SystemInformation,
1941 * Check the request is valid.
1943 if ((SystemInformationClass
>= MIN_SYSTEM_INFO_CLASS
) &&
1944 (SystemInformationClass
< MAX_SYSTEM_INFO_CLASS
))
1946 if (NULL
!= CallQS
[SystemInformationClass
].Set
)
1949 * Hand the request to a subhandler.
1951 return CallQS
[SystemInformationClass
].Set(SystemInformation
,
1952 SystemInformationLength
);
1956 return STATUS_INVALID_INFO_CLASS
;
1961 NtFlushInstructionCache(IN HANDLE ProcessHandle
,
1962 IN PVOID BaseAddress
,
1963 IN ULONG NumberOfBytesToFlush
)
1967 #if defined(_M_IX86)
1969 #elif defined(_M_PPC)
1970 __asm__
__volatile__("tlbsync");
1971 #elif defined(_M_MIPS)
1972 DPRINT1("NtFlushInstructionCache() is not implemented\n");
1974 #elif defined(_M_ARM)
1975 __asm__
__volatile__("mov r1, #0; mcr p15, 0, r1, c7, c5, 0");
1977 #error Unknown architecture
1979 return STATUS_SUCCESS
;
1984 NtGetCurrentProcessorNumber(VOID
)
1986 /* Just return the CPU */
1987 return KeGetCurrentProcessorNumber();
1993 #undef ExGetPreviousMode
1996 ExGetPreviousMode (VOID
)
1998 return KeGetPreviousMode();