580f63b10c78e2d0bef14c2b3d568b38d0e9dcbe
[reactos.git] / reactos / dll / win32 / kernel32 / client / sysinfo.c
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 */
11
12 /* INCLUDES *******************************************************************/
13
14 #include <k32.h>
15
16 #define NDEBUG
17 #include <debug.h>
18
19 #define PV_NT351 0x00030033
20
21 /* PRIVATE FUNCTIONS **********************************************************/
22
23 VOID
24 WINAPI
25 GetSystemInfoInternal(IN PSYSTEM_BASIC_INFORMATION BasicInfo,
26 IN PSYSTEM_PROCESSOR_INFORMATION ProcInfo,
27 OUT LPSYSTEM_INFO SystemInfo)
28 {
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;
40
41 switch (ProcInfo->ProcessorArchitecture)
42 {
43 case PROCESSOR_ARCHITECTURE_INTEL:
44 switch (ProcInfo->ProcessorLevel)
45 {
46 case 3:
47 SystemInfo->dwProcessorType = PROCESSOR_INTEL_386;
48 break;
49 case 4:
50 SystemInfo->dwProcessorType = PROCESSOR_INTEL_486;
51 break;
52 default:
53 SystemInfo->dwProcessorType = PROCESSOR_INTEL_PENTIUM;
54 }
55 break;
56
57 case PROCESSOR_ARCHITECTURE_AMD64:
58 SystemInfo->dwProcessorType = PROCESSOR_AMD_X8664;
59 break;
60
61 case PROCESSOR_ARCHITECTURE_IA64:
62 SystemInfo->dwProcessorType = PROCESSOR_INTEL_IA64;
63 break;
64
65 default:
66 SystemInfo->dwProcessorType = 0;
67 break;
68 }
69
70 if (PV_NT351 > GetProcessVersion(0))
71 {
72 SystemInfo->wProcessorLevel = 0;
73 SystemInfo->wProcessorRevision = 0;
74 }
75 }
76
77 /* PUBLIC FUNCTIONS ***********************************************************/
78
79 /*
80 * @implemented
81 */
82 SIZE_T
83 WINAPI
84 GetLargePageMinimum(VOID)
85 {
86 return SharedUserData->LargePageMinimum;
87 }
88
89 /*
90 * @implemented
91 */
92 VOID
93 WINAPI
94 GetSystemInfo(IN LPSYSTEM_INFO lpSystemInfo)
95 {
96 SYSTEM_BASIC_INFORMATION BasicInfo;
97 SYSTEM_PROCESSOR_INFORMATION ProcInfo;
98 NTSTATUS Status;
99
100 Status = NtQuerySystemInformation(SystemBasicInformation,
101 &BasicInfo,
102 sizeof(BasicInfo),
103 0);
104 if (!NT_SUCCESS(Status)) return;
105
106 Status = NtQuerySystemInformation(SystemProcessorInformation,
107 &ProcInfo,
108 sizeof(ProcInfo),
109 0);
110 if (!NT_SUCCESS(Status)) return;
111
112 GetSystemInfoInternal(&BasicInfo, &ProcInfo, lpSystemInfo);
113 }
114
115 /*
116 * @implemented
117 */
118 BOOL
119 WINAPI
120 IsProcessorFeaturePresent(IN DWORD ProcessorFeature)
121 {
122 if (ProcessorFeature >= PROCESSOR_FEATURE_MAX) return FALSE;
123 return ((BOOL)SharedUserData->ProcessorFeatures[ProcessorFeature]);
124 }
125
126 /*
127 * @implemented
128 */
129 BOOL
130 WINAPI
131 GetSystemRegistryQuota(OUT PDWORD pdwQuotaAllowed,
132 OUT PDWORD pdwQuotaUsed)
133 {
134 SYSTEM_REGISTRY_QUOTA_INFORMATION QuotaInfo;
135 ULONG BytesWritten;
136 NTSTATUS Status;
137
138 Status = NtQuerySystemInformation(SystemRegistryQuotaInformation,
139 &QuotaInfo,
140 sizeof(QuotaInfo),
141 &BytesWritten);
142 if (NT_SUCCESS(Status))
143 {
144 if (pdwQuotaAllowed) *pdwQuotaAllowed = QuotaInfo.RegistryQuotaAllowed;
145 if (pdwQuotaUsed) *pdwQuotaUsed = QuotaInfo.RegistryQuotaUsed;
146 return TRUE;
147 }
148
149 BaseSetLastNTError(Status);
150 return FALSE;
151 }
152
153 /*
154 * @implemented
155 */
156 VOID
157 WINAPI
158 GetNativeSystemInfo(IN LPSYSTEM_INFO lpSystemInfo)
159 {
160 SYSTEM_BASIC_INFORMATION BasicInfo;
161 SYSTEM_PROCESSOR_INFORMATION ProcInfo;
162 NTSTATUS Status;
163
164 /* FIXME: Should be SystemNativeBasicInformation */
165 Status = NtQuerySystemInformation(SystemBasicInformation,
166 &BasicInfo,
167 sizeof(BasicInfo),
168 0);
169 if (!NT_SUCCESS(Status)) return;
170
171 /* FIXME: Should be SystemNativeProcessorInformation */
172 Status = NtQuerySystemInformation(SystemProcessorInformation,
173 &ProcInfo,
174 sizeof(ProcInfo),
175 0);
176 if (!NT_SUCCESS(Status)) return;
177
178 GetSystemInfoInternal(&BasicInfo, &ProcInfo, lpSystemInfo);
179 }
180
181 /*
182 * @implemented
183 */
184 BOOL
185 WINAPI
186 GetLogicalProcessorInformation(OUT PSYSTEM_LOGICAL_PROCESSOR_INFORMATION Buffer,
187 IN OUT PDWORD ReturnLength)
188 {
189 NTSTATUS Status;
190
191 if (!ReturnLength)
192 {
193 SetLastError(ERROR_INVALID_PARAMETER);
194 return FALSE;
195 }
196
197 Status = NtQuerySystemInformation(SystemLogicalProcessorInformation,
198 Buffer,
199 *ReturnLength,
200 ReturnLength);
201
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))
205 {
206 BaseSetLastNTError(Status);
207 return FALSE;
208 }
209
210 return TRUE;
211 }
212
213 /*
214 * @unimplemented
215 */
216 BOOL
217 WINAPI
218 GetNumaHighestNodeNumber(OUT PULONG HighestNodeNumber)
219 {
220 STUB;
221 return 0;
222 }
223
224 /*
225 * @unimplemented
226 */
227 BOOL
228 WINAPI
229 GetNumaNodeProcessorMask(IN UCHAR Node,
230 OUT PULONGLONG ProcessorMask)
231 {
232 STUB;
233 return 0;
234 }
235
236 /*
237 * @unimplemented
238 */
239 BOOL
240 WINAPI
241 GetNumaProcessorNode(IN UCHAR Processor,
242 OUT PUCHAR NodeNumber)
243 {
244 STUB;
245 return 0;
246 }
247
248 /*
249 * @unimplemented
250 */
251 BOOL
252 WINAPI
253 GetNumaAvailableMemoryNode(IN UCHAR Node,
254 OUT PULONGLONG AvailableBytes)
255 {
256 STUB;
257 return FALSE;
258 }
259
260 /*
261 * @unimplemented
262 */
263 DWORD
264 WINAPI
265 GetFirmwareEnvironmentVariableW(IN LPCWSTR lpName,
266 IN LPCWSTR lpGuid,
267 IN PVOID pValue,
268 IN DWORD nSize)
269 {
270 STUB;
271 return 0;
272 }
273
274 /*
275 * @unimplemented
276 */
277 BOOL
278 WINAPI
279 SetFirmwareEnvironmentVariableW(IN LPCWSTR lpName,
280 IN LPCWSTR lpGuid,
281 IN PVOID pValue,
282 IN DWORD nSize)
283 {
284 STUB;
285 return 0;
286 }
287
288 /*
289 * @unimplemented
290 */
291 DWORD
292 WINAPI
293 GetFirmwareEnvironmentVariableA(IN LPCSTR lpName,
294 IN LPCSTR lpGuid,
295 IN PVOID pValue,
296 IN DWORD nSize)
297 {
298 STUB;
299 return 0;
300 }
301
302 /*
303 * @unimplemented
304 */
305 BOOL
306 WINAPI
307 SetFirmwareEnvironmentVariableA(IN LPCSTR lpName,
308 IN LPCSTR lpGuid,
309 IN PVOID pValue,
310 IN DWORD nSize)
311 {
312 STUB;
313 return 0;
314 }
315
316 /*
317 * @unimplemented
318 */
319 UINT
320 WINAPI
321 EnumSystemFirmwareTables(IN DWORD FirmwareTableProviderSignature,
322 OUT PVOID pFirmwareTableBuffer,
323 IN DWORD BufferSize)
324 {
325 STUB;
326 return 0;
327 }
328
329 /*
330 * @unimplemented
331 */
332 UINT
333 WINAPI
334 GetSystemFirmwareTable(IN DWORD FirmwareTableProviderSignature,
335 IN DWORD FirmwareTableID,
336 OUT PVOID pFirmwareTableBuffer,
337 IN DWORD BufferSize)
338 {
339 STUB;
340 return 0;
341 }
342
343 /*
344 * @unimplemented
345 */
346 BOOL
347 WINAPI
348 GetSystemFileCacheSize(OUT PSIZE_T lpMinimumFileCacheSize,
349 OUT PSIZE_T lpMaximumFileCacheSize,
350 OUT PDWORD lpFlags)
351 {
352 STUB;
353 return FALSE;
354 }
355
356 /*
357 * @unimplemented
358 */
359 BOOL
360 WINAPI
361 SetSystemFileCacheSize(IN SIZE_T MinimumFileCacheSize,
362 IN SIZE_T MaximumFileCacheSize,
363 IN DWORD Flags)
364 {
365 STUB;
366 return FALSE;
367 }