Release 1.9.12.
[wine.git] / dlls / kernel32 / cpu.c
blobf48fcf0278be1720a899c415fc93cb80b63ce132
1 /*
2 * What processor?
4 * Copyright 1995,1997 Morten Welinder
5 * Copyright 1997-1998 Marcus Meissner
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
23 #include "wine/port.h"
25 #include <stdarg.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #ifdef HAVE_SYS_TIME_H
29 # include <sys/time.h>
30 #endif
33 #define NONAMELESSUNION
34 #define NONAMELESSSTRUCT
35 #include "ntstatus.h"
36 #define WIN32_NO_STATUS
37 #include "windef.h"
38 #include "winbase.h"
39 #include "winnt.h"
40 #include "winternl.h"
41 #include "psapi.h"
42 #include "ddk/wdm.h"
43 #include "wine/unicode.h"
44 #include "kernel_private.h"
45 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(reg);
49 #define SHARED_DATA ((KSHARED_USER_DATA*)0x7ffe0000)
51 /****************************************************************************
52 * QueryPerformanceCounter (KERNEL32.@)
54 * Get the current value of the performance counter.
56 * PARAMS
57 * counter [O] Destination for the current counter reading
59 * RETURNS
60 * Success: TRUE. counter contains the current reading
61 * Failure: FALSE.
63 * SEE ALSO
64 * See QueryPerformanceFrequency.
66 BOOL WINAPI QueryPerformanceCounter(PLARGE_INTEGER counter)
68 NtQueryPerformanceCounter( counter, NULL );
69 return TRUE;
73 /****************************************************************************
74 * QueryPerformanceFrequency (KERNEL32.@)
76 * Get the resolution of the performance counter.
78 * PARAMS
79 * frequency [O] Destination for the counter resolution
81 * RETURNS
82 * Success. TRUE. Frequency contains the resolution of the counter.
83 * Failure: FALSE.
85 * SEE ALSO
86 * See QueryPerformanceCounter.
88 BOOL WINAPI QueryPerformanceFrequency(PLARGE_INTEGER frequency)
90 LARGE_INTEGER counter;
91 NtQueryPerformanceCounter( &counter, frequency );
92 return TRUE;
96 /***********************************************************************
97 * GetSystemInfo [KERNEL32.@]
99 * Get information about the system.
101 * RETURNS
102 * Nothing.
104 VOID WINAPI GetSystemInfo(
105 LPSYSTEM_INFO si /* [out] Destination for system information, may not be NULL */)
107 NTSTATUS nts;
108 SYSTEM_CPU_INFORMATION sci;
110 TRACE("si=0x%p\n", si);
112 if ((nts = NtQuerySystemInformation( SystemCpuInformation, &sci, sizeof(sci), NULL )) != STATUS_SUCCESS)
114 SetLastError(RtlNtStatusToDosError(nts));
115 return;
118 si->u.s.wProcessorArchitecture = sci.Architecture;
119 si->u.s.wReserved = 0;
120 si->dwPageSize = system_info.PageSize;
121 si->lpMinimumApplicationAddress = system_info.LowestUserAddress;
122 si->lpMaximumApplicationAddress = system_info.HighestUserAddress;
123 si->dwActiveProcessorMask = system_info.ActiveProcessorsAffinityMask;
124 si->dwNumberOfProcessors = system_info.NumberOfProcessors;
126 switch (sci.Architecture)
128 case PROCESSOR_ARCHITECTURE_INTEL:
129 switch (sci.Level)
131 case 3: si->dwProcessorType = PROCESSOR_INTEL_386; break;
132 case 4: si->dwProcessorType = PROCESSOR_INTEL_486; break;
133 case 5:
134 case 6: si->dwProcessorType = PROCESSOR_INTEL_PENTIUM; break;
135 default: si->dwProcessorType = PROCESSOR_INTEL_PENTIUM; break;
137 break;
138 case PROCESSOR_ARCHITECTURE_PPC:
139 switch (sci.Level)
141 case 1: si->dwProcessorType = PROCESSOR_PPC_601; break;
142 case 3:
143 case 6: si->dwProcessorType = PROCESSOR_PPC_603; break;
144 case 4: si->dwProcessorType = PROCESSOR_PPC_604; break;
145 case 9: si->dwProcessorType = PROCESSOR_PPC_604; break;
146 case 20: si->dwProcessorType = PROCESSOR_PPC_620; break;
147 default: si->dwProcessorType = 0;
149 break;
150 case PROCESSOR_ARCHITECTURE_AMD64:
151 si->dwProcessorType = PROCESSOR_AMD_X8664;
152 break;
153 case PROCESSOR_ARCHITECTURE_ARM:
154 switch (sci.Level)
156 case 4: si->dwProcessorType = PROCESSOR_ARM_7TDMI; break;
157 default: si->dwProcessorType = PROCESSOR_ARM920;
159 break;
160 default:
161 FIXME("Unknown processor architecture %x\n", sci.Architecture);
162 si->dwProcessorType = 0;
164 si->dwAllocationGranularity = system_info.AllocationGranularity;
165 si->wProcessorLevel = sci.Level;
166 si->wProcessorRevision = sci.Revision;
170 /***********************************************************************
171 * GetNativeSystemInfo [KERNEL32.@]
173 VOID WINAPI GetNativeSystemInfo(
174 LPSYSTEM_INFO si /* [out] Destination for system information, may not be NULL */)
176 BOOL is_wow64;
178 GetSystemInfo(si);
180 IsWow64Process(GetCurrentProcess(), &is_wow64);
181 if (is_wow64)
183 if (si->u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
185 si->u.s.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_AMD64;
186 si->dwProcessorType = PROCESSOR_AMD_X8664;
188 else
190 FIXME("Add the proper information for %d in wow64 mode\n",
191 si->u.s.wProcessorArchitecture);
196 /***********************************************************************
197 * IsProcessorFeaturePresent [KERNEL32.@]
199 * Determine if the cpu supports a given feature.
201 * RETURNS
202 * TRUE, If the processor supports feature,
203 * FALSE otherwise.
205 BOOL WINAPI IsProcessorFeaturePresent (
206 DWORD feature /* [in] Feature number, (PF_ constants from "winnt.h") */)
208 if (feature < PROCESSOR_FEATURE_MAX)
209 return SHARED_DATA->ProcessorFeatures[feature];
210 else
211 return FALSE;
214 /***********************************************************************
215 * K32GetPerformanceInfo (KERNEL32.@)
217 BOOL WINAPI K32GetPerformanceInfo(PPERFORMANCE_INFORMATION info, DWORD size)
219 union
221 SYSTEM_PERFORMANCE_INFORMATION performance;
222 SYSTEM_PROCESS_INFORMATION process;
223 SYSTEM_BASIC_INFORMATION basic;
224 } *sysinfo;
225 SYSTEM_PROCESS_INFORMATION *spi;
226 DWORD process_info_size;
227 NTSTATUS status;
229 TRACE( "(%p, %d)\n", info, size );
231 if (size < sizeof(*info))
233 SetLastError( ERROR_BAD_LENGTH );
234 return FALSE;
237 memset( info, 0, sizeof(*info) );
238 info->cb = sizeof(*info);
240 /* fields from SYSTEM_PROCESS_INFORMATION */
241 NtQuerySystemInformation( SystemProcessInformation, NULL, 0, &process_info_size );
242 for (;;)
244 sysinfo = HeapAlloc( GetProcessHeap(), 0, max(process_info_size, sizeof(*sysinfo)) );
245 if (!sysinfo)
247 SetLastError( ERROR_OUTOFMEMORY );
248 return FALSE;
250 status = NtQuerySystemInformation( SystemProcessInformation, &sysinfo->process,
251 process_info_size, &process_info_size );
252 if (!status) break;
253 if (status != STATUS_INFO_LENGTH_MISMATCH)
254 goto err;
255 HeapFree( GetProcessHeap(), 0, sysinfo );
257 for (spi = &sysinfo->process;; spi = (SYSTEM_PROCESS_INFORMATION *)(((PCHAR)spi) + spi->NextEntryOffset))
259 info->ProcessCount++;
260 info->HandleCount += spi->HandleCount;
261 info->ThreadCount += spi->dwThreadCount;
262 if (spi->NextEntryOffset == 0) break;
265 /* fields from SYSTEM_PERFORMANCE_INFORMATION */
266 status = NtQuerySystemInformation( SystemPerformanceInformation, &sysinfo->performance,
267 sizeof(sysinfo->performance), NULL );
268 if (status) goto err;
269 info->CommitTotal = sysinfo->performance.TotalCommittedPages;
270 info->CommitLimit = sysinfo->performance.TotalCommitLimit;
271 info->CommitPeak = sysinfo->performance.PeakCommitment;
272 info->PhysicalAvailable = sysinfo->performance.AvailablePages;
273 info->KernelTotal = sysinfo->performance.PagedPoolUsage +
274 sysinfo->performance.NonPagedPoolUsage;
275 info->KernelPaged = sysinfo->performance.PagedPoolUsage;
276 info->KernelNonpaged = sysinfo->performance.NonPagedPoolUsage;
278 /* fields from SYSTEM_BASIC_INFORMATION */
279 status = NtQuerySystemInformation( SystemBasicInformation, &sysinfo->basic,
280 sizeof(sysinfo->basic), NULL );
281 if (status) goto err;
282 info->PhysicalTotal = sysinfo->basic.MmNumberOfPhysicalPages;
283 info->PageSize = sysinfo->basic.PageSize;
285 err:
286 HeapFree( GetProcessHeap(), 0, sysinfo );
287 if (status)
289 SetLastError( RtlNtStatusToDosError( status ) );
290 return FALSE;
292 return TRUE;