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 *****************************************************************/
145 #undef ExGetPreviousMode
148 ExGetPreviousMode (VOID
)
150 return KeGetPreviousMode();
158 ExGetCurrentProcessorCpuUsage(PULONG CpuUsage
)
162 ULONGLONG ScaledIdle
;
164 Prcb
= KeGetCurrentPrcb();
166 ScaledIdle
= Prcb
->IdleThread
->KernelTime
* 100;
167 TotalTime
= Prcb
->KernelTime
+ Prcb
->UserTime
;
169 *CpuUsage
= (ULONG
)(100 - (ScaledIdle
/ TotalTime
));
179 ExGetCurrentProcessorCounts(PULONG ThreadKernelTime
,
181 PULONG ProcessorNumber
)
185 Prcb
= KeGetCurrentPrcb();
187 *ThreadKernelTime
= Prcb
->KernelTime
+ Prcb
->UserTime
;
188 *TotalCpuTime
= Prcb
->CurrentThread
->KernelTime
;
189 *ProcessorNumber
= KeGetCurrentProcessorNumber();
197 ExIsProcessorFeaturePresent(IN ULONG ProcessorFeature
)
199 /* Quick check to see if it exists at all */
200 if (ProcessorFeature
>= PROCESSOR_FEATURE_MAX
) return(FALSE
);
202 /* Return our support for it */
203 return(SharedUserData
->ProcessorFeatures
[ProcessorFeature
]);
211 ExVerifySuite(SUITE_TYPE SuiteType
)
213 if (SuiteType
== Personal
) return TRUE
;
219 NtQuerySystemEnvironmentValue(IN PUNICODE_STRING VariableName
,
220 OUT PWSTR ValueBuffer
,
221 IN ULONG ValueBufferLength
,
222 IN OUT PULONG ReturnLength OPTIONAL
)
225 UNICODE_STRING WName
;
229 UNICODE_STRING WValue
;
230 KPROCESSOR_MODE PreviousMode
;
231 NTSTATUS Status
= STATUS_SUCCESS
;
235 PreviousMode
= ExGetPreviousMode();
237 if (PreviousMode
!= KernelMode
)
241 ProbeForRead(VariableName
,
242 sizeof(UNICODE_STRING
),
245 ProbeForWrite(ValueBuffer
,
249 if (ReturnLength
!= NULL
) ProbeForWriteUlong(ReturnLength
);
251 _SEH2_EXCEPT(ExSystemExceptionFilter())
253 Status
= _SEH2_GetExceptionCode();
257 if (!NT_SUCCESS(Status
)) return Status
;
261 * Copy the name to kernel space if necessary and convert it to ANSI.
263 Status
= ProbeAndCaptureUnicodeString(&WName
,
266 if (NT_SUCCESS(Status
))
269 * according to ntinternals the SeSystemEnvironmentName privilege is required!
271 if (!SeSinglePrivilegeCheck(SeSystemEnvironmentPrivilege
,
274 ReleaseCapturedUnicodeString(&WName
, PreviousMode
);
275 DPRINT1("NtQuerySystemEnvironmentValue: Caller requires the SeSystemEnvironmentPrivilege privilege!\n");
276 return STATUS_PRIVILEGE_NOT_HELD
;
280 * convert the value name to ansi
282 Status
= RtlUnicodeStringToAnsiString(&AName
, &WName
, TRUE
);
283 ReleaseCapturedUnicodeString(&WName
, PreviousMode
);
285 if (!NT_SUCCESS(Status
)) return Status
;
288 * Create a temporary buffer for the value
290 Value
= ExAllocatePool(NonPagedPool
, ValueBufferLength
);
293 RtlFreeAnsiString(&AName
);
294 return STATUS_INSUFFICIENT_RESOURCES
;
298 * Get the environment variable
300 Result
= HalGetEnvironmentVariable(AName
.Buffer
,
301 (USHORT
)ValueBufferLength
,
305 RtlFreeAnsiString(&AName
);
307 return STATUS_UNSUCCESSFUL
;
311 * Convert the result to UNICODE, protect with SEH in case the value buffer
312 * isn't NULL-terminated!
316 RtlInitAnsiString(&AValue
, Value
);
317 Status
= RtlAnsiStringToUnicodeString(&WValue
, &AValue
, TRUE
);
319 _SEH2_EXCEPT(ExSystemExceptionFilter())
321 Status
= _SEH2_GetExceptionCode();
325 if (NT_SUCCESS(Status
))
328 * Copy the result back to the caller.
332 RtlCopyMemory(ValueBuffer
, WValue
.Buffer
, WValue
.Length
);
333 ValueBuffer
[WValue
.Length
/ sizeof(WCHAR
)] = L
'\0';
334 if (ReturnLength
!= NULL
)
336 *ReturnLength
= WValue
.Length
+ sizeof(WCHAR
);
339 Status
= STATUS_SUCCESS
;
341 _SEH2_EXCEPT(ExSystemExceptionFilter())
343 Status
= _SEH2_GetExceptionCode();
349 * Cleanup allocated resources.
351 RtlFreeAnsiString(&AName
);
361 NtSetSystemEnvironmentValue(IN PUNICODE_STRING VariableName
,
362 IN PUNICODE_STRING Value
)
364 UNICODE_STRING CapturedName
, CapturedValue
;
365 ANSI_STRING AName
, AValue
;
366 KPROCESSOR_MODE PreviousMode
;
371 PreviousMode
= ExGetPreviousMode();
374 * Copy the strings to kernel space if necessary
376 Status
= ProbeAndCaptureUnicodeString(&CapturedName
,
379 if (NT_SUCCESS(Status
))
381 Status
= ProbeAndCaptureUnicodeString(&CapturedValue
,
384 if (NT_SUCCESS(Status
))
387 * according to ntinternals the SeSystemEnvironmentName privilege is required!
389 if (SeSinglePrivilegeCheck(SeSystemEnvironmentPrivilege
,
393 * convert the strings to ANSI
395 Status
= RtlUnicodeStringToAnsiString(&AName
,
398 if (NT_SUCCESS(Status
))
400 Status
= RtlUnicodeStringToAnsiString(&AValue
,
403 if (NT_SUCCESS(Status
))
405 ARC_STATUS Result
= HalSetEnvironmentVariable(AName
.Buffer
,
408 Status
= (Result
? STATUS_SUCCESS
: STATUS_UNSUCCESSFUL
);
414 DPRINT1("NtSetSystemEnvironmentValue: Caller requires the SeSystemEnvironmentPrivilege privilege!\n");
415 Status
= STATUS_PRIVILEGE_NOT_HELD
;
418 ReleaseCapturedUnicodeString(&CapturedValue
,
422 ReleaseCapturedUnicodeString(&CapturedName
,
431 NtEnumerateSystemEnvironmentValuesEx(IN ULONG InformationClass
,
433 IN ULONG BufferLength
)
436 return STATUS_NOT_IMPLEMENTED
;
441 NtQuerySystemEnvironmentValueEx(IN PUNICODE_STRING VariableName
,
442 IN LPGUID VendorGuid
,
444 IN OUT PULONG ReturnLength
,
445 IN OUT PULONG Attributes
)
448 return STATUS_NOT_IMPLEMENTED
;
453 NtSetSystemEnvironmentValueEx(IN PUNICODE_STRING VariableName
,
454 IN LPGUID VendorGuid
)
457 return STATUS_NOT_IMPLEMENTED
;
460 /* --- Query/Set System Information --- */
463 * NOTE: QSI_DEF(n) and SSI_DEF(n) define _cdecl function symbols
464 * so the stack is popped only in one place on x86 platform.
466 #define QSI_USE(n) QSI##n
468 static NTSTATUS QSI_USE(n) (PVOID Buffer, ULONG Size, PULONG ReqSize)
470 #define SSI_USE(n) SSI##n
472 static NTSTATUS SSI_USE(n) (PVOID Buffer, ULONG Size)
475 /* Class 0 - Basic Information */
476 QSI_DEF(SystemBasicInformation
)
478 PSYSTEM_BASIC_INFORMATION Sbi
479 = (PSYSTEM_BASIC_INFORMATION
) Buffer
;
481 *ReqSize
= sizeof(SYSTEM_BASIC_INFORMATION
);
483 /* Check user buffer's size */
484 if (Size
!= sizeof(SYSTEM_BASIC_INFORMATION
))
486 return STATUS_INFO_LENGTH_MISMATCH
;
489 RtlZeroMemory(Sbi
, Size
);
491 Sbi
->TimerResolution
= KeMaximumIncrement
;
492 Sbi
->PageSize
= PAGE_SIZE
;
493 Sbi
->NumberOfPhysicalPages
= MmStats
.NrTotalPages
;
494 Sbi
->LowestPhysicalPageNumber
= 0; /* FIXME */
495 Sbi
->HighestPhysicalPageNumber
= MmStats
.NrTotalPages
; /* FIXME */
496 Sbi
->AllocationGranularity
= MM_VIRTMEM_GRANULARITY
; /* hard coded on Intel? */
497 Sbi
->MinimumUserModeAddress
= 0x10000; /* Top of 64k */
498 Sbi
->MaximumUserModeAddress
= (ULONG_PTR
)MmHighestUserAddress
;
499 Sbi
->ActiveProcessorsAffinityMask
= KeActiveProcessors
;
500 Sbi
->NumberOfProcessors
= KeNumberProcessors
;
502 return STATUS_SUCCESS
;
505 /* Class 1 - Processor Information */
506 QSI_DEF(SystemProcessorInformation
)
508 PSYSTEM_PROCESSOR_INFORMATION Spi
509 = (PSYSTEM_PROCESSOR_INFORMATION
) Buffer
;
512 *ReqSize
= sizeof(SYSTEM_PROCESSOR_INFORMATION
);
514 /* Check user buffer's size */
515 if (Size
< sizeof(SYSTEM_PROCESSOR_INFORMATION
))
517 return STATUS_INFO_LENGTH_MISMATCH
;
519 Prcb
= KeGetCurrentPrcb();
520 Spi
->ProcessorArchitecture
= KeProcessorArchitecture
;
521 Spi
->ProcessorLevel
= KeProcessorLevel
;
522 Spi
->ProcessorRevision
= KeProcessorRevision
;
524 Spi
->ProcessorFeatureBits
= KeFeatureBits
;
526 DPRINT("Arch %d Level %d Rev 0x%x\n", Spi
->ProcessorArchitecture
,
527 Spi
->ProcessorLevel
, Spi
->ProcessorRevision
);
529 return STATUS_SUCCESS
;
532 /* Class 2 - Performance Information */
533 QSI_DEF(SystemPerformanceInformation
)
535 ULONG IdleUser
, IdleKernel
;
536 PSYSTEM_PERFORMANCE_INFORMATION Spi
537 = (PSYSTEM_PERFORMANCE_INFORMATION
) Buffer
;
539 PEPROCESS TheIdleProcess
;
541 *ReqSize
= sizeof(SYSTEM_PERFORMANCE_INFORMATION
);
543 /* Check user buffer's size */
544 if (Size
< sizeof(SYSTEM_PERFORMANCE_INFORMATION
))
546 return STATUS_INFO_LENGTH_MISMATCH
;
549 TheIdleProcess
= PsIdleProcess
;
551 IdleKernel
= KeQueryRuntimeProcess(&TheIdleProcess
->Pcb
, &IdleUser
);
552 Spi
->IdleProcessTime
.QuadPart
= UInt32x32To64(IdleKernel
, KeMaximumIncrement
);
553 Spi
->IoReadTransferCount
= IoReadTransferCount
;
554 Spi
->IoWriteTransferCount
= IoWriteTransferCount
;
555 Spi
->IoOtherTransferCount
= IoOtherTransferCount
;
556 Spi
->IoReadOperationCount
= IoReadOperationCount
;
557 Spi
->IoWriteOperationCount
= IoWriteOperationCount
;
558 Spi
->IoOtherOperationCount
= IoOtherOperationCount
;
560 Spi
->AvailablePages
= MmStats
.NrFreePages
;
562 * Add up all the used "Committed" memory + pagefile.
563 * Not sure this is right. 8^\
565 Spi
->CommittedPages
= MiMemoryConsumers
[MC_PPOOL
].PagesUsed
+
566 MiMemoryConsumers
[MC_NPPOOL
].PagesUsed
+
567 MiMemoryConsumers
[MC_CACHE
].PagesUsed
+
568 MiMemoryConsumers
[MC_USER
].PagesUsed
+
571 * Add up the full system total + pagefile.
572 * All this make Taskmgr happy but not sure it is the right numbers.
573 * This too, fixes some of GlobalMemoryStatusEx numbers.
575 Spi
->CommitLimit
= MmStats
.NrTotalPages
+ MiFreeSwapPages
+ MiUsedSwapPages
;
577 Spi
->PeakCommitment
= 0; /* FIXME */
578 Spi
->PageFaultCount
= 0; /* FIXME */
579 Spi
->CopyOnWriteCount
= 0; /* FIXME */
580 Spi
->TransitionCount
= 0; /* FIXME */
581 Spi
->CacheTransitionCount
= 0; /* FIXME */
582 Spi
->DemandZeroCount
= 0; /* FIXME */
583 Spi
->PageReadCount
= 0; /* FIXME */
584 Spi
->PageReadIoCount
= 0; /* FIXME */
585 Spi
->CacheReadCount
= 0; /* FIXME */
586 Spi
->CacheIoCount
= 0; /* FIXME */
587 Spi
->DirtyPagesWriteCount
= 0; /* FIXME */
588 Spi
->DirtyWriteIoCount
= 0; /* FIXME */
589 Spi
->MappedPagesWriteCount
= 0; /* FIXME */
590 Spi
->MappedWriteIoCount
= 0; /* FIXME */
592 Spi
->PagedPoolPages
= MiMemoryConsumers
[MC_PPOOL
].PagesUsed
;
593 Spi
->PagedPoolAllocs
= 0; /* FIXME */
594 Spi
->PagedPoolFrees
= 0; /* FIXME */
595 Spi
->NonPagedPoolPages
= MiMemoryConsumers
[MC_NPPOOL
].PagesUsed
;
596 Spi
->NonPagedPoolAllocs
= 0; /* FIXME */
597 Spi
->NonPagedPoolFrees
= 0; /* FIXME */
599 Spi
->FreeSystemPtes
= 0; /* FIXME */
601 Spi
->ResidentSystemCodePage
= MmStats
.NrSystemPages
; /* FIXME */
603 Spi
->TotalSystemDriverPages
= 0; /* FIXME */
604 Spi
->TotalSystemCodePages
= 0; /* FIXME */
605 Spi
->NonPagedPoolLookasideHits
= 0; /* FIXME */
606 Spi
->PagedPoolLookasideHits
= 0; /* FIXME */
607 Spi
->Spare3Count
= 0; /* FIXME */
609 Spi
->ResidentSystemCachePage
= MiMemoryConsumers
[MC_CACHE
].PagesUsed
;
610 Spi
->ResidentPagedPoolPage
= MmPagedPoolSize
; /* FIXME */
612 Spi
->ResidentSystemDriverPage
= 0; /* FIXME */
613 Spi
->CcFastReadNoWait
= 0; /* FIXME */
614 Spi
->CcFastReadWait
= 0; /* FIXME */
615 Spi
->CcFastReadResourceMiss
= 0; /* FIXME */
616 Spi
->CcFastReadNotPossible
= 0; /* FIXME */
618 Spi
->CcFastMdlReadNoWait
= 0; /* FIXME */
619 Spi
->CcFastMdlReadWait
= 0; /* FIXME */
620 Spi
->CcFastMdlReadResourceMiss
= 0; /* FIXME */
621 Spi
->CcFastMdlReadNotPossible
= 0; /* FIXME */
623 Spi
->CcMapDataNoWait
= 0; /* FIXME */
624 Spi
->CcMapDataWait
= 0; /* FIXME */
625 Spi
->CcMapDataNoWaitMiss
= 0; /* FIXME */
626 Spi
->CcMapDataWaitMiss
= 0; /* FIXME */
628 Spi
->CcPinMappedDataCount
= 0; /* FIXME */
629 Spi
->CcPinReadNoWait
= 0; /* FIXME */
630 Spi
->CcPinReadWait
= 0; /* FIXME */
631 Spi
->CcPinReadNoWaitMiss
= 0; /* FIXME */
632 Spi
->CcPinReadWaitMiss
= 0; /* FIXME */
633 Spi
->CcCopyReadNoWait
= 0; /* FIXME */
634 Spi
->CcCopyReadWait
= 0; /* FIXME */
635 Spi
->CcCopyReadNoWaitMiss
= 0; /* FIXME */
636 Spi
->CcCopyReadWaitMiss
= 0; /* FIXME */
638 Spi
->CcMdlReadNoWait
= 0; /* FIXME */
639 Spi
->CcMdlReadWait
= 0; /* FIXME */
640 Spi
->CcMdlReadNoWaitMiss
= 0; /* FIXME */
641 Spi
->CcMdlReadWaitMiss
= 0; /* FIXME */
642 Spi
->CcReadAheadIos
= 0; /* FIXME */
643 Spi
->CcLazyWriteIos
= 0; /* FIXME */
644 Spi
->CcLazyWritePages
= 0; /* FIXME */
645 Spi
->CcDataFlushes
= 0; /* FIXME */
646 Spi
->CcDataPages
= 0; /* FIXME */
647 Spi
->ContextSwitches
= 0; /* FIXME */
648 Spi
->FirstLevelTbFills
= 0; /* FIXME */
649 Spi
->SecondLevelTbFills
= 0; /* FIXME */
650 Spi
->SystemCalls
= 0; /* FIXME */
652 return STATUS_SUCCESS
;
655 /* Class 3 - Time Of Day Information */
656 QSI_DEF(SystemTimeOfDayInformation
)
658 SYSTEM_TIMEOFDAY_INFORMATION Sti
;
659 LARGE_INTEGER CurrentTime
;
661 /* Set amount of written information to 0 */
664 /* Check user buffer's size */
665 if (Size
> sizeof(SYSTEM_TIMEOFDAY_INFORMATION
))
667 return STATUS_INFO_LENGTH_MISMATCH
;
670 /* Get current time */
671 KeQuerySystemTime(&CurrentTime
);
673 /* Zero local buffer */
674 RtlZeroMemory(&Sti
, sizeof(SYSTEM_TIMEOFDAY_INFORMATION
));
676 /* Fill local time structure */
677 Sti
.BootTime
= KeBootTime
;
678 Sti
.CurrentTime
= CurrentTime
;
679 Sti
.TimeZoneBias
.QuadPart
= ExpTimeZoneBias
.QuadPart
;
680 Sti
.TimeZoneId
= ExpTimeZoneId
;
683 /* Copy as much as requested by caller */
684 RtlCopyMemory(Buffer
, &Sti
, Size
);
686 /* Set amount of information we copied */
689 return STATUS_SUCCESS
;
692 /* Class 4 - Path Information */
693 QSI_DEF(SystemPathInformation
)
695 /* FIXME: QSI returns STATUS_BREAKPOINT. Why? */
696 DPRINT1("NtQuerySystemInformation - SystemPathInformation not implemented\n");
698 return STATUS_BREAKPOINT
;
701 /* Class 5 - Process Information */
702 QSI_DEF(SystemProcessInformation
)
704 PSYSTEM_PROCESS_INFORMATION SpiCurrent
;
705 PSYSTEM_THREAD_INFORMATION ThreadInfo
;
706 PEPROCESS Process
= NULL
, SystemProcess
;
707 PETHREAD CurrentThread
;
708 ANSI_STRING ImageName
;
710 USHORT ImageNameMaximumLength
; // image name len in bytes
711 USHORT ImageNameLength
;
712 PLIST_ENTRY CurrentEntry
;
713 ULONG TotalSize
= 0, ThreadsCount
;
714 ULONG TotalUser
, TotalKernel
;
716 NTSTATUS Status
= STATUS_SUCCESS
;
717 PUNICODE_STRING ProcessImageName
;
719 BOOLEAN Overflow
= FALSE
;
723 /* scan the process list */
725 PSYSTEM_PROCESS_INFORMATION Spi
726 = (PSYSTEM_PROCESS_INFORMATION
) Buffer
;
728 *ReqSize
= sizeof(SYSTEM_PROCESS_INFORMATION
);
730 /* Check for overflow */
731 if (Size
< sizeof(SYSTEM_PROCESS_INFORMATION
))
734 /* Zero user's buffer */
735 if (!Overflow
) RtlZeroMemory(Spi
, Size
);
737 SystemProcess
= PsIdleProcess
;
738 Process
= SystemProcess
;
739 Current
= (PUCHAR
) Spi
;
743 SpiCurrent
= (PSYSTEM_PROCESS_INFORMATION
) Current
;
746 CurrentEntry
= Process
->ThreadListHead
.Flink
;
747 while (CurrentEntry
!= &Process
->ThreadListHead
)
750 CurrentEntry
= CurrentEntry
->Flink
;
753 // size of the structure for every process
754 CurrentSize
= sizeof(SYSTEM_PROCESS_INFORMATION
) + sizeof(SYSTEM_THREAD_INFORMATION
) * ThreadsCount
;
756 Status
= SeLocateProcessImageName(Process
, &ProcessImageName
);
758 if (NT_SUCCESS(Status
) && (ProcessImageName
->Length
> 0))
760 szSrc
= (PWCHAR
)((PCHAR
)ProcessImageName
->Buffer
+ ProcessImageName
->Length
);
761 /* Loop the file name*/
762 while (szSrc
> ProcessImageName
->Buffer
)
764 /* Make sure this isn't a backslash */
765 if (*--szSrc
== OBJ_NAME_PATH_SEPARATOR
)
772 ImageNameLength
+= sizeof(WCHAR
);
776 if (!ImageNameLength
&& Process
!= PsIdleProcess
&& Process
->ImageFileName
)
778 ImageNameLength
= strlen(Process
->ImageFileName
) * sizeof(WCHAR
);
781 /* Round up the image name length as NT does */
782 if (ImageNameLength
> 0)
783 ImageNameMaximumLength
= ROUND_UP(ImageNameLength
+ sizeof(WCHAR
), 8);
785 ImageNameMaximumLength
= 0;
787 TotalSize
+= CurrentSize
+ ImageNameMaximumLength
;
789 /* Check for overflow */
790 if (TotalSize
> Size
)
793 /* Fill system information */
796 SpiCurrent
->NextEntryOffset
= CurrentSize
+ ImageNameMaximumLength
; // relative offset to the beginnnig of the next structure
797 SpiCurrent
->NumberOfThreads
= ThreadsCount
;
798 SpiCurrent
->CreateTime
= Process
->CreateTime
;
799 SpiCurrent
->ImageName
.Length
= ImageNameLength
;
800 SpiCurrent
->ImageName
.MaximumLength
= ImageNameMaximumLength
;
801 SpiCurrent
->ImageName
.Buffer
= (void*)(Current
+ CurrentSize
);
803 /* Copy name to the end of the struct */
804 if(Process
!= PsIdleProcess
)
808 RtlCopyMemory(SpiCurrent
->ImageName
.Buffer
, szSrc
, SpiCurrent
->ImageName
.Length
);
810 /* Release the memory allocated by SeLocateProcessImageName */
811 ExFreePool(ProcessImageName
);
813 else if (Process
->ImageFileName
)
815 RtlInitAnsiString(&ImageName
, Process
->ImageFileName
);
816 RtlAnsiStringToUnicodeString(&SpiCurrent
->ImageName
, &ImageName
, FALSE
);
821 RtlInitUnicodeString(&SpiCurrent
->ImageName
, NULL
);
824 SpiCurrent
->BasePriority
= Process
->Pcb
.BasePriority
;
825 SpiCurrent
->UniqueProcessId
= Process
->UniqueProcessId
;
826 SpiCurrent
->InheritedFromUniqueProcessId
= Process
->InheritedFromUniqueProcessId
;
827 SpiCurrent
->HandleCount
= ObGetProcessHandleCount(Process
);
828 SpiCurrent
->PeakVirtualSize
= Process
->PeakVirtualSize
;
829 SpiCurrent
->VirtualSize
= Process
->VirtualSize
;
830 SpiCurrent
->PageFaultCount
= Process
->Vm
.PageFaultCount
;
831 SpiCurrent
->PeakWorkingSetSize
= Process
->Vm
.PeakWorkingSetSize
;
832 SpiCurrent
->WorkingSetSize
= Process
->Vm
.WorkingSetSize
;
833 SpiCurrent
->QuotaPeakPagedPoolUsage
= Process
->QuotaPeak
[0];
834 SpiCurrent
->QuotaPagedPoolUsage
= Process
->QuotaUsage
[0];
835 SpiCurrent
->QuotaPeakNonPagedPoolUsage
= Process
->QuotaPeak
[1];
836 SpiCurrent
->QuotaNonPagedPoolUsage
= Process
->QuotaUsage
[1];
837 SpiCurrent
->PagefileUsage
= Process
->QuotaUsage
[2];
838 SpiCurrent
->PeakPagefileUsage
= Process
->QuotaPeak
[2];
839 SpiCurrent
->PrivatePageCount
= Process
->CommitCharge
;
840 ThreadInfo
= (PSYSTEM_THREAD_INFORMATION
)(SpiCurrent
+ 1);
842 CurrentEntry
= Process
->ThreadListHead
.Flink
;
843 while (CurrentEntry
!= &Process
->ThreadListHead
)
845 CurrentThread
= CONTAINING_RECORD(CurrentEntry
, ETHREAD
,
848 ThreadInfo
->KernelTime
.QuadPart
= UInt32x32To64(CurrentThread
->Tcb
.KernelTime
, KeMaximumIncrement
);
849 ThreadInfo
->UserTime
.QuadPart
= UInt32x32To64(CurrentThread
->Tcb
.UserTime
, KeMaximumIncrement
);
850 ThreadInfo
->CreateTime
.QuadPart
= CurrentThread
->CreateTime
.QuadPart
;
851 ThreadInfo
->WaitTime
= CurrentThread
->Tcb
.WaitTime
;
852 ThreadInfo
->StartAddress
= (PVOID
) CurrentThread
->StartAddress
;
853 ThreadInfo
->ClientId
= CurrentThread
->Cid
;
854 ThreadInfo
->Priority
= CurrentThread
->Tcb
.Priority
;
855 ThreadInfo
->BasePriority
= CurrentThread
->Tcb
.BasePriority
;
856 ThreadInfo
->ContextSwitches
= CurrentThread
->Tcb
.ContextSwitches
;
857 ThreadInfo
->ThreadState
= CurrentThread
->Tcb
.State
;
858 ThreadInfo
->WaitReason
= CurrentThread
->Tcb
.WaitReason
;
861 CurrentEntry
= CurrentEntry
->Flink
;
864 /* Query total user/kernel times of a process */
865 TotalKernel
= KeQueryRuntimeProcess(&Process
->Pcb
, &TotalUser
);
866 SpiCurrent
->UserTime
.QuadPart
= UInt32x32To64(TotalUser
, KeMaximumIncrement
);
867 SpiCurrent
->KernelTime
.QuadPart
= UInt32x32To64(TotalKernel
, KeMaximumIncrement
);
870 /* Handle idle process entry */
871 if (Process
== PsIdleProcess
) Process
= NULL
;
873 Process
= PsGetNextProcess(Process
);
875 if ((Process
== SystemProcess
) || (Process
== NULL
))
878 SpiCurrent
->NextEntryOffset
= 0;
882 Current
+= CurrentSize
+ ImageNameMaximumLength
;
883 } while ((Process
!= SystemProcess
) && (Process
!= NULL
));
886 ObDereferenceObject(Process
);
887 Status
= STATUS_SUCCESS
;
889 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
892 ObDereferenceObject(Process
);
893 Status
= _SEH2_GetExceptionCode();
898 Status
= STATUS_INFO_LENGTH_MISMATCH
;
900 *ReqSize
= TotalSize
;
904 /* Class 6 - Call Count Information */
905 QSI_DEF(SystemCallCountInformation
)
908 DPRINT1("NtQuerySystemInformation - SystemCallCountInformation not implemented\n");
909 return STATUS_NOT_IMPLEMENTED
;
912 /* Class 7 - Device Information */
913 QSI_DEF(SystemDeviceInformation
)
915 PSYSTEM_DEVICE_INFORMATION Sdi
916 = (PSYSTEM_DEVICE_INFORMATION
) Buffer
;
917 PCONFIGURATION_INFORMATION ConfigInfo
;
919 *ReqSize
= sizeof(SYSTEM_DEVICE_INFORMATION
);
921 /* Check user buffer's size */
922 if (Size
< sizeof(SYSTEM_DEVICE_INFORMATION
))
924 return STATUS_INFO_LENGTH_MISMATCH
;
927 ConfigInfo
= IoGetConfigurationInformation();
929 Sdi
->NumberOfDisks
= ConfigInfo
->DiskCount
;
930 Sdi
->NumberOfFloppies
= ConfigInfo
->FloppyCount
;
931 Sdi
->NumberOfCdRoms
= ConfigInfo
->CdRomCount
;
932 Sdi
->NumberOfTapes
= ConfigInfo
->TapeCount
;
933 Sdi
->NumberOfSerialPorts
= ConfigInfo
->SerialCount
;
934 Sdi
->NumberOfParallelPorts
= ConfigInfo
->ParallelCount
;
936 return STATUS_SUCCESS
;
939 /* Class 8 - Processor Performance Information */
940 QSI_DEF(SystemProcessorPerformanceInformation
)
942 PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION Spi
943 = (PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
) Buffer
;
947 LARGE_INTEGER CurrentTime
;
950 *ReqSize
= KeNumberProcessors
* sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
);
952 /* Check user buffer's size */
955 return STATUS_INFO_LENGTH_MISMATCH
;
958 CurrentTime
.QuadPart
= KeQueryInterruptTime();
959 for (i
= 0; i
< KeNumberProcessors
; i
++)
961 /* Get the PRCB on this processor */
962 Prcb
= KiProcessorBlock
[i
];
964 /* Calculate total user and kernel times */
965 TotalTime
= Prcb
->IdleThread
->KernelTime
+ Prcb
->IdleThread
->UserTime
;
966 Spi
->IdleTime
.QuadPart
= UInt32x32To64(TotalTime
, KeMaximumIncrement
);
967 Spi
->KernelTime
.QuadPart
= UInt32x32To64(Prcb
->KernelTime
, KeMaximumIncrement
);
968 Spi
->UserTime
.QuadPart
= UInt32x32To64(Prcb
->UserTime
, KeMaximumIncrement
);
969 Spi
->DpcTime
.QuadPart
= UInt32x32To64(Prcb
->DpcTime
, KeMaximumIncrement
);
970 Spi
->InterruptTime
.QuadPart
= UInt32x32To64(Prcb
->InterruptTime
, KeMaximumIncrement
);
971 Spi
->InterruptCount
= Prcb
->InterruptCount
;
975 return STATUS_SUCCESS
;
978 /* Class 9 - Flags Information */
979 QSI_DEF(SystemFlagsInformation
)
981 if (sizeof(SYSTEM_FLAGS_INFORMATION
) != Size
)
983 *ReqSize
= sizeof(SYSTEM_FLAGS_INFORMATION
);
984 return (STATUS_INFO_LENGTH_MISMATCH
);
986 ((PSYSTEM_FLAGS_INFORMATION
) Buffer
)->Flags
= NtGlobalFlag
;
987 return STATUS_SUCCESS
;
990 SSI_DEF(SystemFlagsInformation
)
992 if (sizeof(SYSTEM_FLAGS_INFORMATION
) != Size
)
994 return STATUS_INFO_LENGTH_MISMATCH
;
996 NtGlobalFlag
= ((PSYSTEM_FLAGS_INFORMATION
) Buffer
)->Flags
;
997 return STATUS_SUCCESS
;
1000 /* Class 10 - Call Time Information */
1001 QSI_DEF(SystemCallTimeInformation
)
1004 DPRINT1("NtQuerySystemInformation - SystemCallTimeInformation not implemented\n");
1005 return STATUS_NOT_IMPLEMENTED
;
1008 /* Class 11 - Module Information */
1009 QSI_DEF(SystemModuleInformation
)
1011 extern LIST_ENTRY PsLoadedModuleList
;
1012 return ExpQueryModuleInformation(&PsLoadedModuleList
,
1014 (PRTL_PROCESS_MODULES
)Buffer
,
1019 /* Class 12 - Locks Information */
1020 QSI_DEF(SystemLocksInformation
)
1023 DPRINT1("NtQuerySystemInformation - SystemLocksInformation not implemented\n");
1024 return STATUS_NOT_IMPLEMENTED
;
1027 /* Class 13 - Stack Trace Information */
1028 QSI_DEF(SystemStackTraceInformation
)
1031 DPRINT1("NtQuerySystemInformation - SystemStackTraceInformation not implemented\n");
1032 return STATUS_NOT_IMPLEMENTED
;
1035 /* Class 14 - Paged Pool Information */
1036 QSI_DEF(SystemPagedPoolInformation
)
1039 DPRINT1("NtQuerySystemInformation - SystemPagedPoolInformation not implemented\n");
1040 return STATUS_NOT_IMPLEMENTED
;
1043 /* Class 15 - Non Paged Pool Information */
1044 QSI_DEF(SystemNonPagedPoolInformation
)
1047 DPRINT1("NtQuerySystemInformation - SystemNonPagedPoolInformation not implemented\n");
1048 return STATUS_NOT_IMPLEMENTED
;
1052 /* Class 16 - Handle Information */
1053 QSI_DEF(SystemHandleInformation
)
1055 PEPROCESS pr
, syspr
;
1056 ULONG curSize
, i
= 0;
1059 PSYSTEM_HANDLE_INFORMATION Shi
=
1060 (PSYSTEM_HANDLE_INFORMATION
) Buffer
;
1062 DPRINT("NtQuerySystemInformation - SystemHandleInformation\n");
1064 if (Size
< sizeof(SYSTEM_HANDLE_INFORMATION
))
1066 *ReqSize
= sizeof(SYSTEM_HANDLE_INFORMATION
);
1067 return STATUS_INFO_LENGTH_MISMATCH
;
1070 DPRINT("SystemHandleInformation 1\n");
1072 /* First Calc Size from Count. */
1073 syspr
= PsGetNextProcess(NULL
);
1078 hCount
= hCount
+ ObGetProcessHandleCount(pr
);
1079 pr
= PsGetNextProcess(pr
);
1081 if ((pr
== syspr
) || (pr
== NULL
)) break;
1083 while ((pr
!= syspr
) && (pr
!= NULL
));
1087 ObDereferenceObject(pr
);
1090 DPRINT("SystemHandleInformation 2\n");
1092 curSize
= sizeof(SYSTEM_HANDLE_INFORMATION
) +
1093 ((sizeof(SYSTEM_HANDLE_TABLE_ENTRY_INFO
) * hCount
) -
1094 (sizeof(SYSTEM_HANDLE_TABLE_ENTRY_INFO
)));
1096 Shi
->NumberOfHandles
= hCount
;
1101 return (STATUS_INFO_LENGTH_MISMATCH
);
1104 DPRINT("SystemHandleInformation 3\n");
1106 /* Now get Handles from all processs. */
1107 syspr
= PsGetNextProcess(NULL
);
1112 int Count
= 0, HandleCount
;
1114 HandleCount
= ObGetProcessHandleCount(pr
);
1116 for (Count
= 0; HandleCount
> 0 ; HandleCount
--)
1118 Shi
->Handles
[i
].UniqueProcessId
= (USHORT
)(ULONG
)pr
->UniqueProcessId
;
1123 pr
= PsGetNextProcess(pr
);
1125 if ((pr
== syspr
) || (pr
== NULL
)) break;
1127 while ((pr
!= syspr
) && (pr
!= NULL
));
1129 if(pr
!= NULL
) ObDereferenceObject(pr
);
1131 DPRINT("SystemHandleInformation 4\n");
1132 return STATUS_SUCCESS
;
1136 SSI_DEF(SystemHandleInformation)
1139 return STATUS_SUCCESS;
1143 /* Class 17 - Information */
1144 QSI_DEF(SystemObjectInformation
)
1147 DPRINT1("NtQuerySystemInformation - SystemObjectInformation not implemented\n");
1148 return STATUS_NOT_IMPLEMENTED
;
1151 /* Class 18 - Information */
1152 QSI_DEF(SystemPageFileInformation
)
1154 UNICODE_STRING FileName
; /* FIXME */
1155 SYSTEM_PAGEFILE_INFORMATION
*Spfi
= (SYSTEM_PAGEFILE_INFORMATION
*) Buffer
;
1157 if (Size
< sizeof(SYSTEM_PAGEFILE_INFORMATION
))
1159 * ReqSize
= sizeof(SYSTEM_PAGEFILE_INFORMATION
);
1160 return STATUS_INFO_LENGTH_MISMATCH
;
1163 RtlInitUnicodeString(&FileName
, NULL
); /* FIXME */
1166 Spfi
->NextEntryOffset
= 0;
1168 Spfi
->TotalSize
= MiFreeSwapPages
+ MiUsedSwapPages
;
1169 Spfi
->TotalInUse
= MiUsedSwapPages
;
1170 Spfi
->PeakUsage
= MiUsedSwapPages
; /* FIXME */
1171 Spfi
->PageFileName
= FileName
;
1172 return STATUS_SUCCESS
;
1175 /* Class 19 - Vdm Instemul Information */
1176 QSI_DEF(SystemVdmInstemulInformation
)
1179 DPRINT1("NtQuerySystemInformation - SystemVdmInstemulInformation not implemented\n");
1180 return STATUS_NOT_IMPLEMENTED
;
1183 /* Class 20 - Vdm Bop Information */
1184 QSI_DEF(SystemVdmBopInformation
)
1187 DPRINT1("NtQuerySystemInformation - SystemVdmBopInformation not implemented\n");
1188 return STATUS_NOT_IMPLEMENTED
;
1191 /* Class 21 - File Cache Information */
1192 QSI_DEF(SystemFileCacheInformation
)
1194 SYSTEM_FILECACHE_INFORMATION
*Sci
= (SYSTEM_FILECACHE_INFORMATION
*) Buffer
;
1196 if (Size
< sizeof(SYSTEM_FILECACHE_INFORMATION
))
1198 *ReqSize
= sizeof(SYSTEM_FILECACHE_INFORMATION
);
1199 return STATUS_INFO_LENGTH_MISMATCH
;
1202 RtlZeroMemory(Sci
, sizeof(SYSTEM_FILECACHE_INFORMATION
));
1204 /* Return the Byte size not the page size. */
1206 MiMemoryConsumers
[MC_CACHE
].PagesUsed
* PAGE_SIZE
;
1208 MiMemoryConsumers
[MC_CACHE
].PagesUsed
* PAGE_SIZE
; /* FIXME */
1209 /* Taskmgr multiplies this one by page size right away */
1210 Sci
->CurrentSizeIncludingTransitionInPages
=
1211 MiMemoryConsumers
[MC_CACHE
].PagesUsed
; /* FIXME: Should be */
1212 /* system working set and standby pages. */
1213 Sci
->PageFaultCount
= 0; /* FIXME */
1214 Sci
->MinimumWorkingSet
= 0; /* FIXME */
1215 Sci
->MaximumWorkingSet
= 0; /* FIXME */
1217 return STATUS_SUCCESS
;
1220 SSI_DEF(SystemFileCacheInformation
)
1222 if (Size
< sizeof(SYSTEM_FILECACHE_INFORMATION
))
1224 return STATUS_INFO_LENGTH_MISMATCH
;
1227 DPRINT1("NtSetSystemInformation - SystemFileCacheInformation not implemented\n");
1228 return STATUS_NOT_IMPLEMENTED
;
1231 /* Class 22 - Pool Tag Information */
1232 QSI_DEF(SystemPoolTagInformation
)
1235 DPRINT1("NtQuerySystemInformation - SystemPoolTagInformation not implemented\n");
1236 return STATUS_NOT_IMPLEMENTED
;
1239 /* Class 23 - Interrupt Information for all processors */
1240 QSI_DEF(SystemInterruptInformation
)
1246 PSYSTEM_INTERRUPT_INFORMATION sii
= (PSYSTEM_INTERRUPT_INFORMATION
)Buffer
;
1248 if(Size
< KeNumberProcessors
* sizeof(SYSTEM_INTERRUPT_INFORMATION
))
1250 return STATUS_INFO_LENGTH_MISMATCH
;
1253 ti
= KeQueryTimeIncrement();
1255 for (i
= 0; i
< KeNumberProcessors
; i
++)
1257 Prcb
= KiProcessorBlock
[i
];
1258 Pcr
= CONTAINING_RECORD(Prcb
, KPCR
, Prcb
);
1259 #ifdef _M_ARM // This code should probably be done differently
1260 sii
->ContextSwitches
= Pcr
->ContextSwitches
;
1262 sii
->ContextSwitches
= ((PKIPCR
)Pcr
)->ContextSwitches
;
1264 sii
->DpcCount
= Prcb
->DpcData
[0].DpcCount
;
1265 sii
->DpcRate
= Prcb
->DpcRequestRate
;
1266 sii
->TimeIncrement
= ti
;
1267 sii
->DpcBypassCount
= 0;
1268 sii
->ApcBypassCount
= 0;
1272 return STATUS_SUCCESS
;
1275 /* Class 24 - DPC Behaviour Information */
1276 QSI_DEF(SystemDpcBehaviourInformation
)
1279 DPRINT1("NtQuerySystemInformation - SystemDpcBehaviourInformation not implemented\n");
1280 return STATUS_NOT_IMPLEMENTED
;
1283 SSI_DEF(SystemDpcBehaviourInformation
)
1286 DPRINT1("NtSetSystemInformation - SystemDpcBehaviourInformation not implemented\n");
1287 return STATUS_NOT_IMPLEMENTED
;
1290 /* Class 25 - Full Memory Information */
1291 QSI_DEF(SystemFullMemoryInformation
)
1293 PULONG Spi
= (PULONG
) Buffer
;
1295 PEPROCESS TheIdleProcess
;
1297 *ReqSize
= sizeof(ULONG
);
1299 if (sizeof(ULONG
) != Size
)
1301 return STATUS_INFO_LENGTH_MISMATCH
;
1304 DPRINT("SystemFullMemoryInformation\n");
1306 TheIdleProcess
= PsIdleProcess
;
1308 DPRINT("PID: %d, KernelTime: %u PFFree: %d PFUsed: %d\n",
1309 TheIdleProcess
->UniqueProcessId
,
1310 TheIdleProcess
->Pcb
.KernelTime
,
1315 MmPrintMemoryStatistic();
1318 *Spi
= MiMemoryConsumers
[MC_USER
].PagesUsed
;
1320 return STATUS_SUCCESS
;
1323 /* Class 26 - Load Image */
1324 SSI_DEF(SystemLoadGdiDriverInformation
)
1326 PSYSTEM_GDI_DRIVER_INFORMATION DriverInfo
= (PVOID
)Buffer
;
1327 KPROCESSOR_MODE PreviousMode
= KeGetPreviousMode();
1328 UNICODE_STRING ImageName
;
1330 PLDR_DATA_TABLE_ENTRY ModuleObject
;
1331 ULONG_PTR EntryPoint
;
1334 PIMAGE_NT_HEADERS NtHeader
;
1337 if (Size
!= sizeof(SYSTEM_GDI_DRIVER_INFORMATION
))
1339 /* Incorrect buffer length, fail */
1340 return STATUS_INFO_LENGTH_MISMATCH
;
1343 /* Only kernel-mode can call this function */
1344 if (PreviousMode
!= KernelMode
) return STATUS_PRIVILEGE_NOT_HELD
;
1346 /* Load the driver */
1347 ImageName
= DriverInfo
->DriverName
;
1348 Status
= MmLoadSystemImage(&ImageName
,
1352 (PVOID
)&ModuleObject
,
1354 if (!NT_SUCCESS(Status
)) return Status
;
1356 /* Return the export pointer */
1357 DriverInfo
->ExportSectionPointer
=
1358 RtlImageDirectoryEntryToData(ImageBase
,
1360 IMAGE_DIRECTORY_ENTRY_EXPORT
,
1363 /* Get the entrypoint */
1364 NtHeader
= RtlImageNtHeader(ImageBase
);
1365 EntryPoint
= NtHeader
->OptionalHeader
.AddressOfEntryPoint
;
1366 EntryPoint
+= (ULONG_PTR
)ImageBase
;
1368 /* Save other data */
1369 DriverInfo
->ImageAddress
= ImageBase
;
1370 DriverInfo
->SectionPointer
= NULL
;
1371 DriverInfo
->EntryPoint
= (PVOID
)EntryPoint
;
1372 DriverInfo
->ImageLength
= NtHeader
->OptionalHeader
.SizeOfImage
;
1375 return STATUS_SUCCESS
;
1378 /* Class 27 - Unload Image */
1379 SSI_DEF(SystemUnloadGdiDriverInformation
)
1381 PLDR_DATA_TABLE_ENTRY LdrEntry
;
1382 PLIST_ENTRY NextEntry
;
1383 PVOID BaseAddr
= *((PVOID
*)Buffer
);
1385 if(Size
!= sizeof(PVOID
))
1386 return STATUS_INFO_LENGTH_MISMATCH
;
1388 if(KeGetPreviousMode() != KernelMode
)
1389 return STATUS_PRIVILEGE_NOT_HELD
;
1391 // Scan the module list
1392 NextEntry
= PsLoadedModuleList
.Flink
;
1393 while(NextEntry
!= &PsLoadedModuleList
)
1395 LdrEntry
= CONTAINING_RECORD(NextEntry
,
1396 LDR_DATA_TABLE_ENTRY
,
1399 if (LdrEntry
->DllBase
== BaseAddr
)
1405 NextEntry
= NextEntry
->Flink
;
1408 // Check if we found the image
1409 if(NextEntry
!= &PsLoadedModuleList
)
1411 return MmUnloadSystemImage(LdrEntry
);
1415 DPRINT1("Image 0x%x not found.\n", BaseAddr
);
1416 return STATUS_DLL_NOT_FOUND
;
1421 /* Class 28 - Time Adjustment Information */
1422 QSI_DEF(SystemTimeAdjustmentInformation
)
1424 PSYSTEM_QUERY_TIME_ADJUST_INFORMATION TimeInfo
=
1425 (PSYSTEM_QUERY_TIME_ADJUST_INFORMATION
)Buffer
;
1427 /* Check if enough storage was provided */
1428 if (sizeof(SYSTEM_QUERY_TIME_ADJUST_INFORMATION
) > Size
)
1430 * ReqSize
= sizeof(SYSTEM_QUERY_TIME_ADJUST_INFORMATION
);
1431 return STATUS_INFO_LENGTH_MISMATCH
;
1434 /* Give time values to our caller */
1435 TimeInfo
->TimeIncrement
= KeMaximumIncrement
;
1436 TimeInfo
->TimeAdjustment
= KeTimeAdjustment
;
1437 TimeInfo
->Enable
= TRUE
;
1439 return STATUS_SUCCESS
;
1442 SSI_DEF(SystemTimeAdjustmentInformation
)
1444 KPROCESSOR_MODE PreviousMode
= KeGetPreviousMode();
1445 /*PSYSTEM_SET_TIME_ADJUST_INFORMATION TimeInfo =
1446 (PSYSTEM_SET_TIME_ADJUST_INFORMATION)Buffer;*/
1448 /* Check size of a buffer, it must match our expectations */
1449 if (sizeof(SYSTEM_SET_TIME_ADJUST_INFORMATION
) != Size
)
1450 return STATUS_INFO_LENGTH_MISMATCH
;
1452 /* Check who is calling */
1453 if (PreviousMode
!= KernelMode
)
1455 /* Check access rights */
1456 if (!SeSinglePrivilegeCheck(SeSystemtimePrivilege
, PreviousMode
))
1458 return STATUS_PRIVILEGE_NOT_HELD
;
1462 /* TODO: Set time adjustment information */
1463 DPRINT1("Setting of SystemTimeAdjustmentInformation is not implemented yet!\n");
1464 return STATUS_NOT_IMPLEMENTED
;
1467 /* Class 29 - Summary Memory Information */
1468 QSI_DEF(SystemSummaryMemoryInformation
)
1471 DPRINT1("NtQuerySystemInformation - SystemSummaryMemoryInformation not implemented\n");
1472 return STATUS_NOT_IMPLEMENTED
;
1475 /* Class 30 - Next Event Id Information */
1476 QSI_DEF(SystemNextEventIdInformation
)
1479 DPRINT1("NtQuerySystemInformation - SystemNextEventIdInformation not implemented\n");
1480 return STATUS_NOT_IMPLEMENTED
;
1483 /* Class 31 - Event Ids Information */
1484 QSI_DEF(SystemEventIdsInformation
)
1487 DPRINT1("NtQuerySystemInformation - SystemEventIdsInformation not implemented\n");
1488 return STATUS_NOT_IMPLEMENTED
;
1491 /* Class 32 - Crash Dump Information */
1492 QSI_DEF(SystemCrashDumpInformation
)
1495 DPRINT1("NtQuerySystemInformation - SystemCrashDumpInformation not implemented\n");
1496 return STATUS_NOT_IMPLEMENTED
;
1499 /* Class 33 - Exception Information */
1500 QSI_DEF(SystemExceptionInformation
)
1503 DPRINT1("NtQuerySystemInformation - SystemExceptionInformation not implemented\n");
1504 return STATUS_NOT_IMPLEMENTED
;
1507 /* Class 34 - Crash Dump State Information */
1508 QSI_DEF(SystemCrashDumpStateInformation
)
1511 DPRINT1("NtQuerySystemInformation - SystemCrashDumpStateInformation not implemented\n");
1512 return STATUS_NOT_IMPLEMENTED
;
1515 /* Class 35 - Kernel Debugger Information */
1516 QSI_DEF(SystemKernelDebuggerInformation
)
1518 PSYSTEM_KERNEL_DEBUGGER_INFORMATION skdi
= (PSYSTEM_KERNEL_DEBUGGER_INFORMATION
) Buffer
;
1520 *ReqSize
= sizeof(SYSTEM_KERNEL_DEBUGGER_INFORMATION
);
1521 if (Size
< sizeof(SYSTEM_KERNEL_DEBUGGER_INFORMATION
))
1523 return STATUS_INFO_LENGTH_MISMATCH
;
1526 skdi
->KernelDebuggerEnabled
= KD_DEBUGGER_ENABLED
;
1527 skdi
->KernelDebuggerNotPresent
= KD_DEBUGGER_NOT_PRESENT
;
1529 return STATUS_SUCCESS
;
1532 /* Class 36 - Context Switch Information */
1533 QSI_DEF(SystemContextSwitchInformation
)
1536 DPRINT1("NtQuerySystemInformation - SystemContextSwitchInformation not implemented\n");
1537 return STATUS_NOT_IMPLEMENTED
;
1540 /* Class 37 - Registry Quota Information */
1541 QSI_DEF(SystemRegistryQuotaInformation
)
1543 PSYSTEM_REGISTRY_QUOTA_INFORMATION srqi
= (PSYSTEM_REGISTRY_QUOTA_INFORMATION
) Buffer
;
1545 *ReqSize
= sizeof(SYSTEM_REGISTRY_QUOTA_INFORMATION
);
1546 if (Size
< sizeof(SYSTEM_REGISTRY_QUOTA_INFORMATION
))
1548 return STATUS_INFO_LENGTH_MISMATCH
;
1551 DPRINT1("Faking max registry size of 32 MB\n");
1552 srqi
->RegistryQuotaAllowed
= 0x2000000;
1553 srqi
->RegistryQuotaUsed
= 0x200000;
1554 srqi
->PagedPoolSize
= 0x200000;
1556 return STATUS_SUCCESS
;
1559 SSI_DEF(SystemRegistryQuotaInformation
)
1562 DPRINT1("NtSetSystemInformation - SystemRegistryQuotaInformation not implemented\n");
1563 return STATUS_NOT_IMPLEMENTED
;
1566 /* Class 38 - Load And Call Image */
1567 SSI_DEF(SystemExtendServiceTableInformation
)
1569 UNICODE_STRING ImageName
;
1570 KPROCESSOR_MODE PreviousMode
= KeGetPreviousMode();
1571 PLDR_DATA_TABLE_ENTRY ModuleObject
;
1573 PIMAGE_NT_HEADERS NtHeader
;
1574 DRIVER_OBJECT Win32k
;
1575 PDRIVER_INITIALIZE DriverInit
;
1577 ULONG_PTR EntryPoint
;
1579 /* Validate the size */
1580 if (Size
!= sizeof(UNICODE_STRING
)) return STATUS_INFO_LENGTH_MISMATCH
;
1582 /* Check who is calling */
1583 if (PreviousMode
!= KernelMode
)
1585 /* Make sure we can load drivers */
1586 if (!SeSinglePrivilegeCheck(SeLoadDriverPrivilege
, UserMode
))
1588 /* FIXME: We can't, fail */
1589 //return STATUS_PRIVILEGE_NOT_HELD;
1593 /* Probe and capture the driver name */
1594 ProbeAndCaptureUnicodeString(&ImageName
, PreviousMode
, Buffer
);
1596 /* Load the image */
1597 Status
= MmLoadSystemImage(&ImageName
,
1601 (PVOID
)&ModuleObject
,
1604 /* Release String */
1605 ReleaseCapturedUnicodeString(&ImageName
, PreviousMode
);
1607 if (!NT_SUCCESS(Status
)) return Status
;
1609 /* Get the headers */
1610 NtHeader
= RtlImageNtHeader(ImageBase
);
1614 MmUnloadSystemImage(ModuleObject
);
1615 return STATUS_INVALID_IMAGE_FORMAT
;
1618 /* Get the entrypoint */
1619 EntryPoint
= NtHeader
->OptionalHeader
.AddressOfEntryPoint
;
1620 EntryPoint
+= (ULONG_PTR
)ImageBase
;
1621 DriverInit
= (PDRIVER_INITIALIZE
)EntryPoint
;
1623 /* Create a dummy device */
1624 RtlZeroMemory(&Win32k
, sizeof(Win32k
));
1625 ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL
);
1626 Win32k
.DriverStart
= ImageBase
;
1629 Status
= (DriverInit
)(&Win32k
, NULL
);
1630 ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL
);
1632 /* Unload if we failed */
1633 if (!NT_SUCCESS(Status
)) MmUnloadSystemImage(ModuleObject
);
1637 /* Class 39 - Priority Separation */
1638 SSI_DEF(SystemPrioritySeperation
)
1641 DPRINT1("NtSetSystemInformation - SystemPrioritySeperation not implemented\n");
1642 return STATUS_NOT_IMPLEMENTED
;
1645 /* Class 40 - Plug Play Bus Information */
1646 QSI_DEF(SystemPlugPlayBusInformation
)
1649 DPRINT1("NtQuerySystemInformation - SystemPlugPlayBusInformation not implemented\n");
1650 return STATUS_NOT_IMPLEMENTED
;
1653 /* Class 41 - Dock Information */
1654 QSI_DEF(SystemDockInformation
)
1657 DPRINT1("NtQuerySystemInformation - SystemDockInformation not implemented\n");
1658 return STATUS_NOT_IMPLEMENTED
;
1661 /* Class 42 - Power Information */
1662 QSI_DEF(SystemPowerInformation
)
1665 DPRINT1("NtQuerySystemInformation - SystemPowerInformation not implemented\n");
1666 return STATUS_NOT_IMPLEMENTED
;
1669 /* Class 43 - Processor Speed Information */
1670 QSI_DEF(SystemProcessorSpeedInformation
)
1673 DPRINT1("NtQuerySystemInformation - SystemProcessorSpeedInformation not implemented\n");
1674 return STATUS_NOT_IMPLEMENTED
;
1677 /* Class 44 - Current Time Zone Information */
1678 QSI_DEF(SystemCurrentTimeZoneInformation
)
1680 *ReqSize
= sizeof(TIME_ZONE_INFORMATION
);
1682 if (sizeof(TIME_ZONE_INFORMATION
) != Size
)
1684 return STATUS_INFO_LENGTH_MISMATCH
;
1687 /* Copy the time zone information struct */
1690 sizeof(TIME_ZONE_INFORMATION
));
1692 return STATUS_SUCCESS
;
1696 SSI_DEF(SystemCurrentTimeZoneInformation
)
1698 /* Check user buffer's size */
1699 if (Size
< sizeof(TIME_ZONE_INFORMATION
))
1701 return STATUS_INFO_LENGTH_MISMATCH
;
1704 return ExpSetTimeZoneInformation((PTIME_ZONE_INFORMATION
)Buffer
);
1708 /* Class 45 - Lookaside Information */
1709 QSI_DEF(SystemLookasideInformation
)
1712 DPRINT1("NtQuerySystemInformation - SystemLookasideInformation not implemented\n");
1713 return STATUS_NOT_IMPLEMENTED
;
1717 /* Class 46 - Set time slip event */
1718 SSI_DEF(SystemSetTimeSlipEvent
)
1721 DPRINT1("NtSetSystemInformation - SystemSetTimSlipEvent not implemented\n");
1722 return STATUS_NOT_IMPLEMENTED
;
1726 /* Class 47 - Create a new session (TSE) */
1727 SSI_DEF(SystemCreateSession
)
1730 DPRINT1("NtSetSystemInformation - SystemCreateSession not implemented\n");
1731 return STATUS_NOT_IMPLEMENTED
;
1735 /* Class 48 - Delete an existing session (TSE) */
1736 SSI_DEF(SystemDeleteSession
)
1739 DPRINT1("NtSetSystemInformation - SystemDeleteSession not implemented\n");
1740 return STATUS_NOT_IMPLEMENTED
;
1744 /* Class 49 - UNKNOWN */
1745 QSI_DEF(SystemInvalidInfoClass4
)
1748 DPRINT1("NtQuerySystemInformation - SystemInvalidInfoClass4 not implemented\n");
1749 return STATUS_NOT_IMPLEMENTED
;
1753 /* Class 50 - System range start address */
1754 QSI_DEF(SystemRangeStartInformation
)
1757 DPRINT1("NtQuerySystemInformation - SystemRangeStartInformation not implemented\n");
1758 return STATUS_NOT_IMPLEMENTED
;
1762 /* Class 51 - Driver verifier information */
1763 QSI_DEF(SystemVerifierInformation
)
1766 DPRINT1("NtQuerySystemInformation - SystemVerifierInformation not implemented\n");
1767 return STATUS_NOT_IMPLEMENTED
;
1771 SSI_DEF(SystemVerifierInformation
)
1774 DPRINT1("NtSetSystemInformation - SystemVerifierInformation not implemented\n");
1775 return STATUS_NOT_IMPLEMENTED
;
1779 /* Class 52 - Add a driver verifier */
1780 SSI_DEF(SystemAddVerifier
)
1783 DPRINT1("NtSetSystemInformation - SystemAddVerifier not implemented\n");
1784 return STATUS_NOT_IMPLEMENTED
;
1788 /* Class 53 - A session's processes */
1789 QSI_DEF(SystemSessionProcessesInformation
)
1792 DPRINT1("NtQuerySystemInformation - SystemSessionProcessInformation not implemented\n");
1793 return STATUS_NOT_IMPLEMENTED
;
1797 /* Query/Set Calls Table */
1801 NTSTATUS (* Query
) (PVOID
,ULONG
,PULONG
);
1802 NTSTATUS (* Set
) (PVOID
,ULONG
);
1809 // XX unknown behaviour
1811 #define SI_QS(n) {QSI_USE(n),SSI_USE(n)}
1812 #define SI_QX(n) {QSI_USE(n),NULL}
1813 #define SI_XS(n) {NULL,SSI_USE(n)}
1814 #define SI_XX(n) {NULL,NULL}
1820 SI_QX(SystemBasicInformation
),
1821 SI_QX(SystemProcessorInformation
),
1822 SI_QX(SystemPerformanceInformation
),
1823 SI_QX(SystemTimeOfDayInformation
),
1824 SI_QX(SystemPathInformation
), /* should be SI_XX */
1825 SI_QX(SystemProcessInformation
),
1826 SI_QX(SystemCallCountInformation
),
1827 SI_QX(SystemDeviceInformation
),
1828 SI_QX(SystemProcessorPerformanceInformation
),
1829 SI_QS(SystemFlagsInformation
),
1830 SI_QX(SystemCallTimeInformation
), /* should be SI_XX */
1831 SI_QX(SystemModuleInformation
),
1832 SI_QX(SystemLocksInformation
),
1833 SI_QX(SystemStackTraceInformation
), /* should be SI_XX */
1834 SI_QX(SystemPagedPoolInformation
), /* should be SI_XX */
1835 SI_QX(SystemNonPagedPoolInformation
), /* should be SI_XX */
1836 SI_QX(SystemHandleInformation
),
1837 SI_QX(SystemObjectInformation
),
1838 SI_QX(SystemPageFileInformation
),
1839 SI_QX(SystemVdmInstemulInformation
),
1840 SI_QX(SystemVdmBopInformation
), /* it should be SI_XX */
1841 SI_QS(SystemFileCacheInformation
),
1842 SI_QX(SystemPoolTagInformation
),
1843 SI_QX(SystemInterruptInformation
),
1844 SI_QS(SystemDpcBehaviourInformation
),
1845 SI_QX(SystemFullMemoryInformation
), /* it should be SI_XX */
1846 SI_XS(SystemLoadGdiDriverInformation
),
1847 SI_XS(SystemUnloadGdiDriverInformation
),
1848 SI_QS(SystemTimeAdjustmentInformation
),
1849 SI_QX(SystemSummaryMemoryInformation
), /* it should be SI_XX */
1850 SI_QX(SystemNextEventIdInformation
), /* it should be SI_XX */
1851 SI_QX(SystemEventIdsInformation
), /* it should be SI_XX */
1852 SI_QX(SystemCrashDumpInformation
),
1853 SI_QX(SystemExceptionInformation
),
1854 SI_QX(SystemCrashDumpStateInformation
),
1855 SI_QX(SystemKernelDebuggerInformation
),
1856 SI_QX(SystemContextSwitchInformation
),
1857 SI_QS(SystemRegistryQuotaInformation
),
1858 SI_XS(SystemExtendServiceTableInformation
),
1859 SI_XS(SystemPrioritySeperation
),
1860 SI_QX(SystemPlugPlayBusInformation
), /* it should be SI_XX */
1861 SI_QX(SystemDockInformation
), /* it should be SI_XX */
1862 SI_QX(SystemPowerInformation
), /* it should be SI_XX */
1863 SI_QX(SystemProcessorSpeedInformation
), /* it should be SI_XX */
1864 SI_QS(SystemCurrentTimeZoneInformation
), /* it should be SI_QX */
1865 SI_QX(SystemLookasideInformation
),
1866 SI_XS(SystemSetTimeSlipEvent
),
1867 SI_XS(SystemCreateSession
),
1868 SI_XS(SystemDeleteSession
),
1869 SI_QX(SystemInvalidInfoClass4
), /* it should be SI_XX */
1870 SI_QX(SystemRangeStartInformation
),
1871 SI_QS(SystemVerifierInformation
),
1872 SI_XS(SystemAddVerifier
),
1873 SI_QX(SystemSessionProcessesInformation
)
1876 C_ASSERT(SystemBasicInformation
== 0);
1877 #define MIN_SYSTEM_INFO_CLASS (SystemBasicInformation)
1878 #define MAX_SYSTEM_INFO_CLASS (sizeof(CallQS) / sizeof(CallQS[0]))
1884 NtQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInformationClass
,
1885 OUT PVOID SystemInformation
,
1887 OUT PULONG UnsafeResultLength
)
1889 KPROCESSOR_MODE PreviousMode
;
1891 NTSTATUS FStatus
= STATUS_NOT_IMPLEMENTED
;
1895 PreviousMode
= ExGetPreviousMode();
1899 if (PreviousMode
!= KernelMode
)
1901 /* SystemKernelDebuggerInformation needs only BOOLEAN alignment */
1902 ProbeForWrite(SystemInformation
, Length
, 1);
1903 if (UnsafeResultLength
!= NULL
)
1904 ProbeForWriteUlong(UnsafeResultLength
);
1908 * Check the request is valid.
1910 if (SystemInformationClass
>= MAX_SYSTEM_INFO_CLASS
)
1912 _SEH2_YIELD(return STATUS_INVALID_INFO_CLASS
);
1915 if (NULL
!= CallQS
[SystemInformationClass
].Query
)
1918 * Hand the request to a subhandler.
1920 FStatus
= CallQS
[SystemInformationClass
].Query(SystemInformation
,
1923 if (UnsafeResultLength
!= NULL
)
1925 if (PreviousMode
!= KernelMode
)
1927 *UnsafeResultLength
= ResultLength
;
1931 *UnsafeResultLength
= ResultLength
;
1936 _SEH2_EXCEPT(ExSystemExceptionFilter())
1938 FStatus
= _SEH2_GetExceptionCode();
1948 NtSetSystemInformation (IN SYSTEM_INFORMATION_CLASS SystemInformationClass
,
1949 IN PVOID SystemInformation
,
1950 IN ULONG SystemInformationLength
)
1955 * If called from user mode, check
1956 * possible unsafe arguments.
1959 if (KernelMode
!= KeGetPreviousMode())
1963 // SystemInformation,
1973 * Check the request is valid.
1975 if ((SystemInformationClass
>= MIN_SYSTEM_INFO_CLASS
) &&
1976 (SystemInformationClass
< MAX_SYSTEM_INFO_CLASS
))
1978 if (NULL
!= CallQS
[SystemInformationClass
].Set
)
1981 * Hand the request to a subhandler.
1983 return CallQS
[SystemInformationClass
].Set(SystemInformation
,
1984 SystemInformationLength
);
1988 return STATUS_INVALID_INFO_CLASS
;
1994 NtFlushInstructionCache(IN HANDLE ProcessHandle
,
1995 IN PVOID BaseAddress
,
1996 IN ULONG NumberOfBytesToFlush
)
2000 #if defined(_M_IX86)
2002 #elif defined(_M_PPC)
2003 __asm__
__volatile__("tlbsync");
2004 #elif defined(_M_MIPS)
2005 DPRINT1("NtFlushInstructionCache() is not implemented\n");
2007 #elif defined(_M_ARM)
2008 __asm__
__volatile__("mov r1, #0; mcr p15, 0, r1, c7, c5, 0");
2010 #error Unknown architecture
2012 return STATUS_SUCCESS
;
2017 NtGetCurrentProcessorNumber(VOID
)
2019 /* Just return the CPU */
2020 return KeGetCurrentProcessorNumber();