ReactOS 0.4.15-dev-5667-ged97270
sysinfo.c
Go to the documentation of this file.
1/*
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
8 * Thomas Weidenmueller
9 * Gunnar Andre Dalsnes
10 * Stanislav Motylkov (x86corez@gmail.com)
11 * Mark Jansen (mark.jansen@reactos.org)
12 */
13
14/* INCLUDES *******************************************************************/
15
16#include <k32.h>
17
18#define NDEBUG
19#include <debug.h>
20
21#define PV_NT351 0x00030033
22
23/* PRIVATE FUNCTIONS **********************************************************/
24
25VOID
29 OUT LPSYSTEM_INFO SystemInfo)
30{
31 RtlZeroMemory(SystemInfo, sizeof (SYSTEM_INFO));
32 SystemInfo->wProcessorArchitecture = ProcInfo->ProcessorArchitecture;
33 SystemInfo->wReserved = 0;
34 SystemInfo->dwPageSize = BasicInfo->PageSize;
35 SystemInfo->lpMinimumApplicationAddress = (PVOID)BasicInfo->MinimumUserModeAddress;
36 SystemInfo->lpMaximumApplicationAddress = (PVOID)BasicInfo->MaximumUserModeAddress;
37 SystemInfo->dwActiveProcessorMask = BasicInfo->ActiveProcessorsAffinityMask;
38 SystemInfo->dwNumberOfProcessors = BasicInfo->NumberOfProcessors;
39 SystemInfo->wProcessorLevel = ProcInfo->ProcessorLevel;
40 SystemInfo->wProcessorRevision = ProcInfo->ProcessorRevision;
41 SystemInfo->dwAllocationGranularity = BasicInfo->AllocationGranularity;
42
43 switch (ProcInfo->ProcessorArchitecture)
44 {
46 switch (ProcInfo->ProcessorLevel)
47 {
48 case 3:
49 SystemInfo->dwProcessorType = PROCESSOR_INTEL_386;
50 break;
51 case 4:
52 SystemInfo->dwProcessorType = PROCESSOR_INTEL_486;
53 break;
54 default:
55 SystemInfo->dwProcessorType = PROCESSOR_INTEL_PENTIUM;
56 }
57 break;
58
60 SystemInfo->dwProcessorType = PROCESSOR_AMD_X8664;
61 break;
62
64 SystemInfo->dwProcessorType = PROCESSOR_INTEL_IA64;
65 break;
66
67 default:
68 SystemInfo->dwProcessorType = 0;
69 break;
70 }
71
73 {
74 SystemInfo->wProcessorLevel = 0;
75 SystemInfo->wProcessorRevision = 0;
76 }
77}
78
79static
80UINT
81BaseQuerySystemFirmware(IN DWORD FirmwareTableProviderSignature,
83 OUT PVOID pFirmwareTableBuffer,
86{
87 SYSTEM_FIRMWARE_TABLE_INFORMATION* SysFirmwareInfo;
91
92 SysFirmwareInfo = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, TotalSize);
93 if (!SysFirmwareInfo)
94 {
96 return 0;
97 }
99 {
100 SysFirmwareInfo->ProviderSignature = FirmwareTableProviderSignature;
101 SysFirmwareInfo->TableID = FirmwareTableID;
102 SysFirmwareInfo->Action = Action;
103 SysFirmwareInfo->TableBufferLength = BufferSize;
104
106
108 Result = SysFirmwareInfo->TableBufferLength;
109
110 if (NT_SUCCESS(Status) && pFirmwareTableBuffer)
111 {
112 RtlCopyMemory(pFirmwareTableBuffer, SysFirmwareInfo->TableBuffer, SysFirmwareInfo->TableBufferLength);
113 }
114 }
116 {
117 RtlFreeHeap(RtlGetProcessHeap(), 0, SysFirmwareInfo);
118 }
119 _SEH2_END;
120
122 return Result;
123}
124
125/* PUBLIC FUNCTIONS ***********************************************************/
126
127/*
128 * @implemented
129 */
130SIZE_T
131WINAPI
133{
134 return SharedUserData->LargePageMinimum;
135}
136
137/*
138 * @implemented
139 */
140VOID
141WINAPI
143{
144 SYSTEM_BASIC_INFORMATION BasicInfo;
147
149 &BasicInfo,
150 sizeof(BasicInfo),
151 0);
152 if (!NT_SUCCESS(Status)) return;
153
155 &ProcInfo,
156 sizeof(ProcInfo),
157 0);
158 if (!NT_SUCCESS(Status)) return;
159
160 GetSystemInfoInternal(&BasicInfo, &ProcInfo, lpSystemInfo);
161}
162
163/*
164 * @implemented
165 */
166BOOL
167WINAPI
169{
170 if (ProcessorFeature >= PROCESSOR_FEATURE_MAX) return FALSE;
171 return ((BOOL)SharedUserData->ProcessorFeatures[ProcessorFeature]);
172}
173
174/*
175 * @implemented
176 */
177BOOL
178WINAPI
180 OUT PDWORD pdwQuotaUsed)
181{
185
187 &QuotaInfo,
188 sizeof(QuotaInfo),
189 &BytesWritten);
190 if (NT_SUCCESS(Status))
191 {
192 if (pdwQuotaAllowed) *pdwQuotaAllowed = QuotaInfo.RegistryQuotaAllowed;
193 if (pdwQuotaUsed) *pdwQuotaUsed = QuotaInfo.RegistryQuotaUsed;
194 return TRUE;
195 }
196
198 return FALSE;
199}
200
201/*
202 * @implemented
203 */
204VOID
205WINAPI
207{
208 SYSTEM_BASIC_INFORMATION BasicInfo;
211
212 Status = RtlGetNativeSystemInformation(SystemBasicInformation,
213 &BasicInfo,
214 sizeof(BasicInfo),
215 0);
216 if (!NT_SUCCESS(Status)) return;
217
218 Status = RtlGetNativeSystemInformation(SystemProcessorInformation,
219 &ProcInfo,
220 sizeof(ProcInfo),
221 0);
222 if (!NT_SUCCESS(Status)) return;
223
224 GetSystemInfoInternal(&BasicInfo, &ProcInfo, lpSystemInfo);
225}
226
227/*
228 * @implemented
229 */
230BOOL
231WINAPI
234{
236
237 if (!ReturnLength)
238 {
240 return FALSE;
241 }
242
244 Buffer,
247
248 /* Normalize the error to what Win32 expects */
250 if (!NT_SUCCESS(Status))
251 {
253 return FALSE;
254 }
255
256 return TRUE;
257}
258
259/*
260 * @implemented
261 */
262BOOL
263WINAPI
265{
268 ULONG PartialInfo[2]; // First two members of SYSTEM_NUMA_INFORMATION
269
270 /* Query partial NUMA info */
272 PartialInfo,
273 sizeof(PartialInfo),
274 &Length);
275 if (!NT_SUCCESS(Status))
276 {
278 return FALSE;
279 }
280
281 if (Length < sizeof(ULONG))
282 {
284 return FALSE;
285 }
286
287 /* First member of the struct is the highest node number */
288 *HighestNodeNumber = PartialInfo[0];
289 return TRUE;
290}
291
292/*
293 * @implemented
294 */
295BOOL
296WINAPI
298 OUT PULONGLONG ProcessorMask)
299{
301 SYSTEM_NUMA_INFORMATION NumaInformation;
303
304 /* Query NUMA information */
306 &NumaInformation,
307 sizeof(NumaInformation),
308 &Length);
309 if (!NT_SUCCESS(Status))
310 {
312 return FALSE;
313 }
314
315 /* Validate input node number */
316 if (Node > NumaInformation.HighestNodeNumber)
317 {
319 return FALSE;
320 }
321
322 /* Return mask for that node */
323 *ProcessorMask = NumaInformation.ActiveProcessorsAffinityMask[Node];
324 return TRUE;
325}
326
327/*
328 * @implemented
329 */
330BOOL
331WINAPI
334{
336 SYSTEM_NUMA_INFORMATION NumaInformation;
338 ULONG Node;
339 ULONGLONG Proc;
340
341 /* Can't handle processor number >= 32 */
343 {
344 *NodeNumber = -1;
346 return FALSE;
347 }
348
349 /* Query NUMA information */
351 &NumaInformation,
352 sizeof(NumaInformation),
353 &Length);
354 if (!NT_SUCCESS(Status))
355 {
356 *NodeNumber = -1;
358 return FALSE;
359 }
360
361 /* Find ourselves */
362 Node = 0;
363 Proc = 1ULL << Processor;
364 while ((Proc & NumaInformation.ActiveProcessorsAffinityMask[Node]) == 0ULL)
365 {
366 ++Node;
367 /* Out of options */
368 if (Node > NumaInformation.HighestNodeNumber)
369 {
370 *NodeNumber = -1;
372 return FALSE;
373 }
374 }
375
376 /* Return found node */
377 *NodeNumber = Node;
378 return TRUE;
379}
380
381/*
382 * @implemented
383 */
384BOOL
385WINAPI
387 OUT PULONGLONG AvailableBytes)
388{
390 SYSTEM_NUMA_INFORMATION NumaInformation;
392
393 /* Query NUMA information */
395 &NumaInformation,
396 sizeof(NumaInformation),
397 &Length);
398 if (!NT_SUCCESS(Status))
399 {
401 return FALSE;
402 }
403
404 /* Validate input node number */
405 if (Node > NumaInformation.HighestNodeNumber)
406 {
408 return FALSE;
409 }
410
411 /* Return available memory for that node */
412 *AvailableBytes = NumaInformation.AvailableMemory[Node];
413 return TRUE;
414}
415
416/*
417 * @unimplemented
418 */
419DWORD
420WINAPI
422 IN LPCWSTR lpGuid,
424 IN DWORD nSize)
425{
426 STUB;
427 return 0;
428}
429
430/*
431 * @unimplemented
432 */
433BOOL
434WINAPI
436 IN LPCWSTR lpGuid,
438 IN DWORD nSize)
439{
440 STUB;
441 return 0;
442}
443
444/*
445 * @unimplemented
446 */
447DWORD
448WINAPI
450 IN LPCSTR lpGuid,
452 IN DWORD nSize)
453{
454 STUB;
455 return 0;
456}
457
458/*
459 * @unimplemented
460 */
461BOOL
462WINAPI
464 IN LPCSTR lpGuid,
466 IN DWORD nSize)
467{
468 STUB;
469 return 0;
470}
471
499UINT
500WINAPI
501EnumSystemFirmwareTables(IN DWORD FirmwareTableProviderSignature,
502 OUT PVOID pFirmwareTableBuffer,
504{
505 return BaseQuerySystemFirmware(FirmwareTableProviderSignature,
506 0,
507 pFirmwareTableBuffer,
510}
511
546UINT
547WINAPI
548GetSystemFirmwareTable(IN DWORD FirmwareTableProviderSignature,
550 OUT PVOID pFirmwareTableBuffer,
552{
553 return BaseQuerySystemFirmware(FirmwareTableProviderSignature,
555 pFirmwareTableBuffer,
558}
559
560/*
561 * @unimplemented
562 */
563BOOL
564WINAPI
565GetSystemFileCacheSize(OUT PSIZE_T lpMinimumFileCacheSize,
566 OUT PSIZE_T lpMaximumFileCacheSize,
567 OUT PDWORD lpFlags)
568{
569 STUB;
570 return FALSE;
571}
572
573/*
574 * @unimplemented
575 */
576BOOL
577WINAPI
578SetSystemFileCacheSize(IN SIZE_T MinimumFileCacheSize,
579 IN SIZE_T MaximumFileCacheSize,
580 IN DWORD Flags)
581{
582 STUB;
583 return FALSE;
584}
585
586/*
587 * @unimplemented
588 */
589LONG
590WINAPI
592 BYTE *Buffer)
593{
594 STUB;
596}
unsigned int UINT32
ULONG ReturnedSize
_In_ ULONG FirmwareTableID
Definition: aux_klib.h:91
LONG NTSTATUS
Definition: precomp.h:26
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
Definition: bufpool.h:45
#define BufferSize
Definition: mmc.h:75
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
union node Node
Definition: types.h:1255
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
DWORD WINAPI GetProcessVersion(IN DWORD ProcessId)
Definition: proc.c:1760
BOOL WINAPI SetFirmwareEnvironmentVariableW(IN LPCWSTR lpName, IN LPCWSTR lpGuid, IN PVOID pValue, IN DWORD nSize)
Definition: sysinfo.c:435
BOOL WINAPI SetSystemFileCacheSize(IN SIZE_T MinimumFileCacheSize, IN SIZE_T MaximumFileCacheSize, IN DWORD Flags)
Definition: sysinfo.c:578
VOID WINAPI GetNativeSystemInfo(IN LPSYSTEM_INFO lpSystemInfo)
Definition: sysinfo.c:206
BOOL WINAPI GetNumaNodeProcessorMask(IN UCHAR Node, OUT PULONGLONG ProcessorMask)
Definition: sysinfo.c:297
BOOL WINAPI GetNumaProcessorNode(IN UCHAR Processor, OUT PUCHAR NodeNumber)
Definition: sysinfo.c:332
static UINT BaseQuerySystemFirmware(IN DWORD FirmwareTableProviderSignature, IN DWORD FirmwareTableID, OUT PVOID pFirmwareTableBuffer, IN DWORD BufferSize, IN SYSTEM_FIRMWARE_TABLE_ACTION Action)
Definition: sysinfo.c:81
LONG WINAPI GetCurrentPackageId(UINT32 *BufferLength, BYTE *Buffer)
Definition: sysinfo.c:591
BOOL WINAPI GetSystemRegistryQuota(OUT PDWORD pdwQuotaAllowed, OUT PDWORD pdwQuotaUsed)
Definition: sysinfo.c:179
BOOL WINAPI GetSystemFileCacheSize(OUT PSIZE_T lpMinimumFileCacheSize, OUT PSIZE_T lpMaximumFileCacheSize, OUT PDWORD lpFlags)
Definition: sysinfo.c:565
DWORD WINAPI GetFirmwareEnvironmentVariableA(IN LPCSTR lpName, IN LPCSTR lpGuid, IN PVOID pValue, IN DWORD nSize)
Definition: sysinfo.c:449
DWORD WINAPI GetFirmwareEnvironmentVariableW(IN LPCWSTR lpName, IN LPCWSTR lpGuid, IN PVOID pValue, IN DWORD nSize)
Definition: sysinfo.c:421
BOOL WINAPI GetNumaAvailableMemoryNode(IN UCHAR Node, OUT PULONGLONG AvailableBytes)
Definition: sysinfo.c:386
#define PV_NT351
Definition: sysinfo.c:21
UINT WINAPI EnumSystemFirmwareTables(IN DWORD FirmwareTableProviderSignature, OUT PVOID pFirmwareTableBuffer, IN DWORD BufferSize)
Definition: sysinfo.c:501
SIZE_T WINAPI GetLargePageMinimum(VOID)
Definition: sysinfo.c:132
BOOL WINAPI GetLogicalProcessorInformation(OUT PSYSTEM_LOGICAL_PROCESSOR_INFORMATION Buffer, IN OUT PDWORD ReturnLength)
Definition: sysinfo.c:232
VOID WINAPI GetSystemInfo(IN LPSYSTEM_INFO lpSystemInfo)
Definition: sysinfo.c:142
BOOL WINAPI SetFirmwareEnvironmentVariableA(IN LPCSTR lpName, IN LPCSTR lpGuid, IN PVOID pValue, IN DWORD nSize)
Definition: sysinfo.c:463
VOID WINAPI GetSystemInfoInternal(IN PSYSTEM_BASIC_INFORMATION BasicInfo, IN PSYSTEM_PROCESSOR_INFORMATION ProcInfo, OUT LPSYSTEM_INFO SystemInfo)
Definition: sysinfo.c:27
BOOL WINAPI IsProcessorFeaturePresent(IN DWORD ProcessorFeature)
Definition: sysinfo.c:168
UINT WINAPI GetSystemFirmwareTable(IN DWORD FirmwareTableProviderSignature, IN DWORD FirmwareTableID, OUT PVOID pFirmwareTableBuffer, IN DWORD BufferSize)
Definition: sysinfo.c:548
BOOL WINAPI GetNumaHighestNodeNumber(OUT PULONG HighestNodeNumber)
Definition: sysinfo.c:264
IN CINT OUT PVOID IN ULONG OUT PULONG ReturnLength
Definition: dumpinfo.c:43
#define _SEH2_FINALLY
Definition: filesup.c:21
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
#define MAXIMUM_PROCESSORS
Definition: rwlock.h:5
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
@ SystemProcessorInformation
Definition: ntddk_ex.h:12
@ SystemBasicInformation
Definition: ntddk_ex.h:11
@ SystemRegistryQuotaInformation
Definition: ntddk_ex.h:48
PWCHAR pValue
Status
Definition: gdiplustypes.h:25
#define STUB
Definition: kernel32.h:27
#define ULL(a, b)
Definition: format_msg.c:27
unsigned int UINT
Definition: ndis.h:50
@ SystemFirmwareTableInformation
Definition: extypes.h:293
@ SystemLogicalProcessorInformation
Definition: extypes.h:290
@ SystemNumaProcessorMap
Definition: extypes.h:272
@ SystemNumaAvailableMemory
Definition: extypes.h:277
#define PROCESSOR_ARCHITECTURE_IA64
Definition: ketypes.h:111
#define PROCESSOR_ARCHITECTURE_AMD64
Definition: ketypes.h:114
#define PROCESSOR_ARCHITECTURE_INTEL
Definition: ketypes.h:105
__GNU_EXTENSION typedef unsigned __int64 * PULONGLONG
Definition: ntbasedef.h:383
@ SystemFirmwareTable_Enumerate
@ SystemFirmwareTable_Get
enum _SYSTEM_FIRMWARE_TABLE_ACTION SYSTEM_FIRMWARE_TABLE_ACTION
struct _SYSTEM_FIRMWARE_TABLE_INFORMATION SYSTEM_FIRMWARE_TABLE_INFORMATION
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
DWORD * PDWORD
Definition: pedump.c:68
long LONG
Definition: pedump.c:60
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define SharedUserData
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
NTSYSAPI NTSTATUS NTAPI NtQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInfoClass, OUT PVOID SystemInfoBuffer, IN ULONG SystemInfoBufferSize, OUT PULONG BytesReturned OPTIONAL)
SYSTEM_FIRMWARE_TABLE_ACTION Action
ULONGLONG ActiveProcessorsAffinityMask[MAXIMUM_NUMA_NODES]
Definition: extypes.h:1400
ULONGLONG AvailableMemory[MAXIMUM_NUMA_NODES]
Definition: extypes.h:1401
ULONG_PTR * PSIZE_T
Definition: typedefs.h:80
uint32_t * PULONG
Definition: typedefs.h:59
void * PVOID
Definition: typedefs.h:50
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define IN
Definition: typedefs.h:39
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
uint64_t ULONGLONG
Definition: typedefs.h:67
#define OUT
Definition: typedefs.h:40
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
Definition: dlist.c:348
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3771
_In_ WDFIOTARGET _In_ _Strict_type_match_ WDF_IO_TARGET_SENT_IO_ACTION Action
Definition: wdfiotarget.h:510
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesWritten
Definition: wdfiotarget.h:960
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254
_In_ LPCSTR lpName
Definition: winbase.h:2776
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2062
#define WINAPI
Definition: msvc.h:6
#define APPMODEL_ERROR_NO_PACKAGE
Definition: winerror.h:2337
#define PROCESSOR_INTEL_PENTIUM
Definition: winnt_old.h:425
#define PROCESSOR_INTEL_386
Definition: winnt_old.h:423
#define PROCESSOR_AMD_X8664
Definition: winnt_old.h:434
#define PROCESSOR_INTEL_IA64
Definition: winnt_old.h:428
#define PROCESSOR_INTEL_486
Definition: winnt_old.h:424
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
_Out_ PUSHORT NodeNumber
Definition: iofuncs.h:2574
_In_ UCHAR Processor
Definition: kefuncs.h:684
#define PROCESSOR_FEATURE_MAX
const char * LPCSTR
Definition: xmlstorage.h:183
unsigned char UCHAR
Definition: xmlstorage.h:181
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
unsigned char BYTE
Definition: xxhash.c:193