ReactOS  0.4.12-dev-708-g95ed44e
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 
25 VOID
26 WINAPI
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 
72  if (PV_NT351 > GetProcessVersion(0))
73  {
74  SystemInfo->wProcessorLevel = 0;
75  SystemInfo->wProcessorRevision = 0;
76  }
77 }
78 
79 static
80 UINT
81 BaseQuerySystemFirmware(IN DWORD FirmwareTableProviderSignature,
82  IN DWORD FirmwareTableID,
83  OUT PVOID pFirmwareTableBuffer,
86 {
87  SYSTEM_FIRMWARE_TABLE_INFORMATION* SysFirmwareInfo;
88  ULONG Result = 0, ReturnedSize;
91 
92  SysFirmwareInfo = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, TotalSize);
93  if (!SysFirmwareInfo)
94  {
96  return 0;
97  }
98  _SEH2_TRY
99  {
100  SysFirmwareInfo->ProviderSignature = FirmwareTableProviderSignature;
101  SysFirmwareInfo->TableID = FirmwareTableID;
102  SysFirmwareInfo->Action = Action;
103  SysFirmwareInfo->TableBufferLength = BufferSize;
104 
105  Status = NtQuerySystemInformation(SystemFirmwareTableInformation, SysFirmwareInfo, TotalSize, &ReturnedSize);
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  */
130 SIZE_T
131 WINAPI
133 {
134  return SharedUserData->LargePageMinimum;
135 }
136 
137 /*
138  * @implemented
139  */
140 VOID
141 WINAPI
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  */
166 BOOL
167 WINAPI
169 {
170  if (ProcessorFeature >= PROCESSOR_FEATURE_MAX) return FALSE;
171  return ((BOOL)SharedUserData->ProcessorFeatures[ProcessorFeature]);
172 }
173 
174 /*
175  * @implemented
176  */
177 BOOL
178 WINAPI
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  */
204 VOID
205 WINAPI
207 {
208  SYSTEM_BASIC_INFORMATION BasicInfo;
211 
212  /* FIXME: Should be SystemNativeBasicInformation */
214  &BasicInfo,
215  sizeof(BasicInfo),
216  0);
217  if (!NT_SUCCESS(Status)) return;
218 
219  /* FIXME: Should be SystemNativeProcessorInformation */
221  &ProcInfo,
222  sizeof(ProcInfo),
223  0);
224  if (!NT_SUCCESS(Status)) return;
225 
226  GetSystemInfoInternal(&BasicInfo, &ProcInfo, lpSystemInfo);
227 }
228 
229 /*
230  * @implemented
231  */
232 BOOL
233 WINAPI
236 {
238 
239  if (!ReturnLength)
240  {
242  return FALSE;
243  }
244 
246  Buffer,
247  *ReturnLength,
248  ReturnLength);
249 
250  /* Normalize the error to what Win32 expects */
252  if (!NT_SUCCESS(Status))
253  {
255  return FALSE;
256  }
257 
258  return TRUE;
259 }
260 
261 /*
262  * @implemented
263  */
264 BOOL
265 WINAPI
267 {
269  ULONG Length;
270  ULONG PartialInfo[2]; // First two members of SYSTEM_NUMA_INFORMATION
271 
272  /* Query partial NUMA info */
274  PartialInfo,
275  sizeof(PartialInfo),
276  &Length);
277  if (!NT_SUCCESS(Status))
278  {
280  return FALSE;
281  }
282 
283  if (Length < sizeof(ULONG))
284  {
286  return FALSE;
287  }
288 
289  /* First member of the struct is the highest node number */
290  *HighestNodeNumber = PartialInfo[0];
291  return TRUE;
292 }
293 
294 /*
295  * @implemented
296  */
297 BOOL
298 WINAPI
300  OUT PULONGLONG ProcessorMask)
301 {
303  SYSTEM_NUMA_INFORMATION NumaInformation;
304  ULONG Length;
305 
306  /* Query NUMA information */
308  &NumaInformation,
309  sizeof(NumaInformation),
310  &Length);
311  if (!NT_SUCCESS(Status))
312  {
314  return FALSE;
315  }
316 
317  /* Validate input node number */
318  if (Node > NumaInformation.HighestNodeNumber)
319  {
321  return FALSE;
322  }
323 
324  /* Return mask for that node */
325  *ProcessorMask = NumaInformation.ActiveProcessorsAffinityMask[Node];
326  return TRUE;
327 }
328 
329 /*
330  * @implemented
331  */
332 BOOL
333 WINAPI
336 {
338  SYSTEM_NUMA_INFORMATION NumaInformation;
339  ULONG Length;
340  ULONG Node;
341  ULONGLONG Proc;
342 
343  /* Can't handle processor number >= 32 */
345  {
346  *NodeNumber = -1;
348  return FALSE;
349  }
350 
351  /* Query NUMA information */
353  &NumaInformation,
354  sizeof(NumaInformation),
355  &Length);
356  if (!NT_SUCCESS(Status))
357  {
358  *NodeNumber = -1;
360  return FALSE;
361  }
362 
363  /* Find ourselves */
364  Node = 0;
365  Proc = 1ULL << Processor;
366  while ((Proc & NumaInformation.ActiveProcessorsAffinityMask[Node]) == 0ULL)
367  {
368  ++Node;
369  /* Out of options */
370  if (Node > NumaInformation.HighestNodeNumber)
371  {
372  *NodeNumber = -1;
374  return FALSE;
375  }
376  }
377 
378  /* Return found node */
379  *NodeNumber = Node;
380  return TRUE;
381 }
382 
383 /*
384  * @implemented
385  */
386 BOOL
387 WINAPI
389  OUT PULONGLONG AvailableBytes)
390 {
392  SYSTEM_NUMA_INFORMATION NumaInformation;
393  ULONG Length;
394 
395  /* Query NUMA information */
397  &NumaInformation,
398  sizeof(NumaInformation),
399  &Length);
400  if (!NT_SUCCESS(Status))
401  {
403  return FALSE;
404  }
405 
406  /* Validate input node number */
407  if (Node > NumaInformation.HighestNodeNumber)
408  {
410  return FALSE;
411  }
412 
413  /* Return available memory for that node */
414  *AvailableBytes = NumaInformation.AvailableMemory[Node];
415  return TRUE;
416 }
417 
418 /*
419  * @unimplemented
420  */
421 DWORD
422 WINAPI
424  IN LPCWSTR lpGuid,
425  IN PVOID pValue,
426  IN DWORD nSize)
427 {
428  STUB;
429  return 0;
430 }
431 
432 /*
433  * @unimplemented
434  */
435 BOOL
436 WINAPI
438  IN LPCWSTR lpGuid,
439  IN PVOID pValue,
440  IN DWORD nSize)
441 {
442  STUB;
443  return 0;
444 }
445 
446 /*
447  * @unimplemented
448  */
449 DWORD
450 WINAPI
452  IN LPCSTR lpGuid,
453  IN PVOID pValue,
454  IN DWORD nSize)
455 {
456  STUB;
457  return 0;
458 }
459 
460 /*
461  * @unimplemented
462  */
463 BOOL
464 WINAPI
466  IN LPCSTR lpGuid,
467  IN PVOID pValue,
468  IN DWORD nSize)
469 {
470  STUB;
471  return 0;
472 }
473 
501 UINT
502 WINAPI
503 EnumSystemFirmwareTables(IN DWORD FirmwareTableProviderSignature,
504  OUT PVOID pFirmwareTableBuffer,
506 {
507  return BaseQuerySystemFirmware(FirmwareTableProviderSignature,
508  0,
509  pFirmwareTableBuffer,
510  BufferSize,
512 }
513 
548 UINT
549 WINAPI
550 GetSystemFirmwareTable(IN DWORD FirmwareTableProviderSignature,
551  IN DWORD FirmwareTableID,
552  OUT PVOID pFirmwareTableBuffer,
554 {
555  return BaseQuerySystemFirmware(FirmwareTableProviderSignature,
556  FirmwareTableID,
557  pFirmwareTableBuffer,
558  BufferSize,
560 }
561 
562 /*
563  * @unimplemented
564  */
565 BOOL
566 WINAPI
567 GetSystemFileCacheSize(OUT PSIZE_T lpMinimumFileCacheSize,
568  OUT PSIZE_T lpMaximumFileCacheSize,
569  OUT PDWORD lpFlags)
570 {
571  STUB;
572  return FALSE;
573 }
574 
575 /*
576  * @unimplemented
577  */
578 BOOL
579 WINAPI
580 SetSystemFileCacheSize(IN SIZE_T MinimumFileCacheSize,
581  IN SIZE_T MaximumFileCacheSize,
582  IN DWORD Flags)
583 {
584  STUB;
585  return FALSE;
586 }
#define MAXIMUM_PROCESSORS
Definition: rwlock.h:5
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
ULONGLONG AvailableMemory[MAXIMUM_NUMA_NODES]
Definition: extypes.h:1397
IN CINT OUT PVOID IN ULONG OUT PULONG ReturnLength
Definition: dumpinfo.c:39
#define IN
Definition: typedefs.h:38
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesWritten
Definition: fltkernel.h:1293
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
BOOL WINAPI GetNumaAvailableMemoryNode(IN UCHAR Node, OUT PULONGLONG AvailableBytes)
Definition: sysinfo.c:388
BOOL WINAPI SetFirmwareEnvironmentVariableW(IN LPCWSTR lpName, IN LPCWSTR lpGuid, IN PVOID pValue, IN DWORD nSize)
Definition: sysinfo.c:437
UINT WINAPI GetSystemFirmwareTable(IN DWORD FirmwareTableProviderSignature, IN DWORD FirmwareTableID, OUT PVOID pFirmwareTableBuffer, IN DWORD BufferSize)
Definition: sysinfo.c:550
VOID WINAPI GetNativeSystemInfo(IN LPSYSTEM_INFO lpSystemInfo)
Definition: sysinfo.c:206
unsigned char * PUCHAR
Definition: retypes.h:3
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2024
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:603
_In_ LPCSTR lpName
Definition: winbase.h:2729
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
_In_ UCHAR Processor
Definition: kefuncs.h:695
BOOL WINAPI SetFirmwareEnvironmentVariableA(IN LPCSTR lpName, IN LPCSTR lpGuid, IN PVOID pValue, IN DWORD nSize)
Definition: sysinfo.c:465
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:64
_SEH2_TRY
Definition: create.c:4250
#define PROCESSOR_ARCHITECTURE_IA64
Definition: ketypes.h:111
_Out_ PUSHORT NodeNumber
Definition: iofuncs.h:2567
struct _SYSTEM_FIRMWARE_TABLE_INFORMATION SYSTEM_FIRMWARE_TABLE_INFORMATION
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
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
ULONG_PTR * PSIZE_T
Definition: typedefs.h:78
union node Node
Definition: types.h:1255
_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
Definition: bufpool.h:45
VOID WINAPI GetSystemInfoInternal(IN PSYSTEM_BASIC_INFORMATION BasicInfo, IN PSYSTEM_PROCESSOR_INFORMATION ProcInfo, OUT LPSYSTEM_INFO SystemInfo)
Definition: sysinfo.c:27
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
const char * LPCSTR
Definition: xmlstorage.h:183
void * PVOID
Definition: retypes.h:9
#define ULL(a, b)
Definition: format_msg.c:27
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:585
BOOL WINAPI SetSystemFileCacheSize(IN SIZE_T MinimumFileCacheSize, IN SIZE_T MaximumFileCacheSize, IN DWORD Flags)
Definition: sysinfo.c:580
unsigned int BOOL
Definition: ntddk_ex.h:94
enum _SYSTEM_FIRMWARE_TABLE_ACTION SYSTEM_FIRMWARE_TABLE_ACTION
#define PV_NT351
Definition: sysinfo.c:21
#define PROCESSOR_FEATURE_MAX
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
uint64_t ULONGLONG
Definition: typedefs.h:65
_In_ PLIST_ENTRY _In_ PSTRING _In_ USHORT _In_opt_ PSTRING _In_opt_ PSTRING _In_ ULONG _In_ ULONG Action
Definition: fsrtlfuncs.h:738
BOOL WINAPI GetNumaHighestNodeNumber(OUT PULONG HighestNodeNumber)
Definition: sysinfo.c:266
unsigned int UINT
Definition: ndis.h:50
DWORD WINAPI GetFirmwareEnvironmentVariableW(IN LPCWSTR lpName, IN LPCWSTR lpGuid, IN PVOID pValue, IN DWORD nSize)
Definition: sysinfo.c:423
#define BufferSize
Definition: classpnp.h:419
unsigned long DWORD
Definition: ntddk_ex.h:95
UINT WINAPI EnumSystemFirmwareTables(IN DWORD FirmwareTableProviderSignature, OUT PVOID pFirmwareTableBuffer, IN DWORD BufferSize)
Definition: sysinfo.c:503
#define SetLastError(x)
Definition: compat.h:409
BOOL WINAPI GetLogicalProcessorInformation(OUT PSYSTEM_LOGICAL_PROCESSOR_INFORMATION Buffer, IN OUT PDWORD ReturnLength)
Definition: sysinfo.c:234
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define PROCESSOR_ARCHITECTURE_AMD64
Definition: ketypes.h:114
#define SharedUserData
unsigned char UCHAR
Definition: xmlstorage.h:181
DWORD WINAPI GetProcessVersion(IN DWORD ProcessId)
Definition: proc.c:1790
#define WINAPI
Definition: msvc.h:20
#define PROCESSOR_INTEL_386
Definition: winnt_old.h:422
Status
Definition: gdiplustypes.h:24
#define PROCESSOR_ARCHITECTURE_INTEL
Definition: ketypes.h:105
ULONG_PTR SIZE_T
Definition: typedefs.h:78
DWORD WINAPI GetFirmwareEnvironmentVariableA(IN LPCSTR lpName, IN LPCSTR lpGuid, IN PVOID pValue, IN DWORD nSize)
Definition: sysinfo.c:451
_SEH2_END
Definition: create.c:4424
SIZE_T WINAPI GetLargePageMinimum(VOID)
Definition: sysinfo.c:132
BOOL WINAPI IsProcessorFeaturePresent(IN DWORD ProcessorFeature)
Definition: sysinfo.c:168
#define STUB
Definition: kernel32.h:27
#define PROCESSOR_INTEL_IA64
Definition: winnt_old.h:427
SYSTEM_FIRMWARE_TABLE_ACTION Action
#define SystemBasicInformation
Definition: xboxvmp.h:35
_SEH2_FINALLY
Definition: create.c:4395
VOID WINAPI GetSystemInfo(IN LPSYSTEM_INFO lpSystemInfo)
Definition: sysinfo.c:142
unsigned int * PULONG
Definition: retypes.h:1
BOOL WINAPI GetSystemFileCacheSize(OUT PSIZE_T lpMinimumFileCacheSize, OUT PSIZE_T lpMaximumFileCacheSize, OUT PDWORD lpFlags)
Definition: sysinfo.c:567
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
DWORD * PDWORD
Definition: pedump.c:68
ULONGLONG ActiveProcessorsAffinityMask[MAXIMUM_NUMA_NODES]
Definition: extypes.h:1396
BOOL WINAPI GetSystemRegistryQuota(OUT PDWORD pdwQuotaAllowed, OUT PDWORD pdwQuotaUsed)
Definition: sysinfo.c:179
#define OUT
Definition: typedefs.h:39
__GNU_EXTENSION typedef unsigned __int64 * PULONGLONG
Definition: ntbasedef.h:390
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define PROCESSOR_AMD_X8664
Definition: winnt_old.h:433
BOOL WINAPI GetNumaNodeProcessorMask(IN UCHAR Node, OUT PULONGLONG ProcessorMask)
Definition: sysinfo.c:299
#define PROCESSOR_INTEL_486
Definition: winnt_old.h:423
BOOL WINAPI GetNumaProcessorNode(IN UCHAR Processor, OUT PUCHAR NodeNumber)
Definition: sysinfo.c:334
__kernel_entry NTSTATUS NTAPI NtQuerySystemInformation(_In_ SYSTEM_INFORMATION_CLASS SystemInformationClass, _Out_writes_bytes_to_opt_(SystemInformationLength, *ReturnLength) PVOID SystemInformation, _In_ ULONG Length, _Out_opt_ PULONG UnsafeResultLength)
Definition: sysinfo.c:2829
#define PROCESSOR_INTEL_PENTIUM
Definition: winnt_old.h:424
Definition: dlist.c:348