2 * PROJECT: ReactOS Win32 Base API
3 * LICENSE: See COPYING in the top level directory
4 * FILE: dll/win32/kernel32/client/sysinfo.c
5 * PURPOSE: System Information Functions
6 * PROGRAMMERS: Emanuele Aliberti
7 * Christoph von Wittich
12 /* INCLUDES *******************************************************************/
19 #define PV_NT351 0x00030033
21 /* PRIVATE FUNCTIONS **********************************************************/
25 GetSystemInfoInternal(IN PSYSTEM_BASIC_INFORMATION BasicInfo
,
26 IN PSYSTEM_PROCESSOR_INFORMATION ProcInfo
,
27 OUT LPSYSTEM_INFO SystemInfo
)
29 RtlZeroMemory(SystemInfo
, sizeof (SYSTEM_INFO
));
30 SystemInfo
->wProcessorArchitecture
= ProcInfo
->ProcessorArchitecture
;
31 SystemInfo
->wReserved
= 0;
32 SystemInfo
->dwPageSize
= BasicInfo
->PageSize
;
33 SystemInfo
->lpMinimumApplicationAddress
= (PVOID
)BasicInfo
->MinimumUserModeAddress
;
34 SystemInfo
->lpMaximumApplicationAddress
= (PVOID
)BasicInfo
->MaximumUserModeAddress
;
35 SystemInfo
->dwActiveProcessorMask
= BasicInfo
->ActiveProcessorsAffinityMask
;
36 SystemInfo
->dwNumberOfProcessors
= BasicInfo
->NumberOfProcessors
;
37 SystemInfo
->wProcessorLevel
= ProcInfo
->ProcessorLevel
;
38 SystemInfo
->wProcessorRevision
= ProcInfo
->ProcessorRevision
;
39 SystemInfo
->dwAllocationGranularity
= BasicInfo
->AllocationGranularity
;
41 switch (ProcInfo
->ProcessorArchitecture
)
43 case PROCESSOR_ARCHITECTURE_INTEL
:
44 switch (ProcInfo
->ProcessorLevel
)
47 SystemInfo
->dwProcessorType
= PROCESSOR_INTEL_386
;
50 SystemInfo
->dwProcessorType
= PROCESSOR_INTEL_486
;
53 SystemInfo
->dwProcessorType
= PROCESSOR_INTEL_PENTIUM
;
57 case PROCESSOR_ARCHITECTURE_AMD64
:
58 SystemInfo
->dwProcessorType
= PROCESSOR_AMD_X8664
;
61 case PROCESSOR_ARCHITECTURE_IA64
:
62 SystemInfo
->dwProcessorType
= PROCESSOR_INTEL_IA64
;
66 SystemInfo
->dwProcessorType
= 0;
70 if (PV_NT351
> GetProcessVersion(0))
72 SystemInfo
->wProcessorLevel
= 0;
73 SystemInfo
->wProcessorRevision
= 0;
77 /* PUBLIC FUNCTIONS ***********************************************************/
84 GetLargePageMinimum(VOID
)
86 return SharedUserData
->LargePageMinimum
;
94 GetSystemInfo(IN LPSYSTEM_INFO lpSystemInfo
)
96 SYSTEM_BASIC_INFORMATION BasicInfo
;
97 SYSTEM_PROCESSOR_INFORMATION ProcInfo
;
100 Status
= NtQuerySystemInformation(SystemBasicInformation
,
104 if (!NT_SUCCESS(Status
)) return;
106 Status
= NtQuerySystemInformation(SystemProcessorInformation
,
110 if (!NT_SUCCESS(Status
)) return;
112 GetSystemInfoInternal(&BasicInfo
, &ProcInfo
, lpSystemInfo
);
120 IsProcessorFeaturePresent(IN DWORD ProcessorFeature
)
122 if (ProcessorFeature
>= PROCESSOR_FEATURE_MAX
) return FALSE
;
123 return ((BOOL
)SharedUserData
->ProcessorFeatures
[ProcessorFeature
]);
131 GetSystemRegistryQuota(OUT PDWORD pdwQuotaAllowed
,
132 OUT PDWORD pdwQuotaUsed
)
134 SYSTEM_REGISTRY_QUOTA_INFORMATION QuotaInfo
;
138 Status
= NtQuerySystemInformation(SystemRegistryQuotaInformation
,
142 if (NT_SUCCESS(Status
))
144 if (pdwQuotaAllowed
) *pdwQuotaAllowed
= QuotaInfo
.RegistryQuotaAllowed
;
145 if (pdwQuotaUsed
) *pdwQuotaUsed
= QuotaInfo
.RegistryQuotaUsed
;
149 BaseSetLastNTError(Status
);
158 GetNativeSystemInfo(IN LPSYSTEM_INFO lpSystemInfo
)
160 SYSTEM_BASIC_INFORMATION BasicInfo
;
161 SYSTEM_PROCESSOR_INFORMATION ProcInfo
;
164 /* FIXME: Should be SystemNativeBasicInformation */
165 Status
= NtQuerySystemInformation(SystemBasicInformation
,
169 if (!NT_SUCCESS(Status
)) return;
171 /* FIXME: Should be SystemNativeProcessorInformation */
172 Status
= NtQuerySystemInformation(SystemProcessorInformation
,
176 if (!NT_SUCCESS(Status
)) return;
178 GetSystemInfoInternal(&BasicInfo
, &ProcInfo
, lpSystemInfo
);
186 GetLogicalProcessorInformation(OUT PSYSTEM_LOGICAL_PROCESSOR_INFORMATION Buffer
,
187 IN OUT PDWORD ReturnLength
)
193 SetLastError(ERROR_INVALID_PARAMETER
);
197 Status
= NtQuerySystemInformation(SystemLogicalProcessorInformation
,
202 /* Normalize the error to what Win32 expects */
203 if (Status
== STATUS_INFO_LENGTH_MISMATCH
) Status
= STATUS_BUFFER_TOO_SMALL
;
204 if (!NT_SUCCESS(Status
))
206 BaseSetLastNTError(Status
);
218 GetNumaHighestNodeNumber(OUT PULONG HighestNodeNumber
)
222 ULONG PartialInfo
[2]; // First two members of SYSTEM_NUMA_INFORMATION
224 /* Query partial NUMA info */
225 Status
= NtQuerySystemInformation(SystemNumaProcessorMap
,
229 if (!NT_SUCCESS(Status
))
231 BaseSetLastNTError(Status
);
235 if (Length
< sizeof(ULONG
))
237 SetLastError(ERROR_INVALID_PARAMETER
);
241 /* First member of the struct is the highest node number */
242 *HighestNodeNumber
= PartialInfo
[0];
251 GetNumaNodeProcessorMask(IN UCHAR Node
,
252 OUT PULONGLONG ProcessorMask
)
255 SYSTEM_NUMA_INFORMATION NumaInformation
;
258 /* Query NUMA information */
259 Status
= NtQuerySystemInformation(SystemNumaProcessorMap
,
261 sizeof(NumaInformation
),
263 if (!NT_SUCCESS(Status
))
265 BaseSetLastNTError(Status
);
269 /* Validate input node number */
270 if (Node
> NumaInformation
.HighestNodeNumber
)
272 SetLastError(ERROR_INVALID_PARAMETER
);
276 /* Return mask for that node */
277 *ProcessorMask
= NumaInformation
.ActiveProcessorsAffinityMask
[Node
];
286 GetNumaProcessorNode(IN UCHAR Processor
,
287 OUT PUCHAR NodeNumber
)
290 SYSTEM_NUMA_INFORMATION NumaInformation
;
295 /* Can't handle processor number >= 32 */
296 if (Processor
>= MAXIMUM_PROCESSORS
)
299 SetLastError(ERROR_INVALID_PARAMETER
);
303 /* Query NUMA information */
304 Status
= NtQuerySystemInformation(SystemNumaProcessorMap
,
306 sizeof(NumaInformation
),
308 if (!NT_SUCCESS(Status
))
311 BaseSetLastNTError(Status
);
317 Proc
= 1ULL << Processor
;
318 while ((Proc
& NumaInformation
.ActiveProcessorsAffinityMask
[Node
]) == 0ULL)
322 if (Node
> NumaInformation
.HighestNodeNumber
)
325 SetLastError(ERROR_INVALID_PARAMETER
);
330 /* Return found node */
340 GetNumaAvailableMemoryNode(IN UCHAR Node
,
341 OUT PULONGLONG AvailableBytes
)
344 SYSTEM_NUMA_INFORMATION NumaInformation
;
347 /* Query NUMA information */
348 Status
= NtQuerySystemInformation(SystemNumaAvailableMemory
,
350 sizeof(NumaInformation
),
352 if (!NT_SUCCESS(Status
))
354 BaseSetLastNTError(Status
);
358 /* Validate input node number */
359 if (Node
> NumaInformation
.HighestNodeNumber
)
361 SetLastError(ERROR_INVALID_PARAMETER
);
365 /* Return available memory for that node */
366 *AvailableBytes
= NumaInformation
.AvailableMemory
[Node
];
375 GetFirmwareEnvironmentVariableW(IN LPCWSTR lpName
,
389 SetFirmwareEnvironmentVariableW(IN LPCWSTR lpName
,
403 GetFirmwareEnvironmentVariableA(IN LPCSTR lpName
,
417 SetFirmwareEnvironmentVariableA(IN LPCSTR lpName
,
431 EnumSystemFirmwareTables(IN DWORD FirmwareTableProviderSignature
,
432 OUT PVOID pFirmwareTableBuffer
,
444 GetSystemFirmwareTable(IN DWORD FirmwareTableProviderSignature
,
445 IN DWORD FirmwareTableID
,
446 OUT PVOID pFirmwareTableBuffer
,
458 GetSystemFileCacheSize(OUT PSIZE_T lpMinimumFileCacheSize
,
459 OUT PSIZE_T lpMaximumFileCacheSize
,
471 SetSystemFileCacheSize(IN SIZE_T MinimumFileCacheSize
,
472 IN SIZE_T MaximumFileCacheSize
,