dsound/tests: Allow more time for an event to be signalled.
[wine.git] / dlls / kernel32 / cpu.c
blob0014738cf424d5ece6a09b1c88db3a59b496c30e
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 /***********************************************************************
50 * GetSystemInfo [KERNEL32.@]
52 * Get information about the system.
54 * RETURNS
55 * Nothing.
57 VOID WINAPI GetSystemInfo(
58 LPSYSTEM_INFO si /* [out] Destination for system information, may not be NULL */)
60 SYSTEM_CPU_INFORMATION sci;
62 TRACE("si=0x%p\n", si);
64 if (!set_ntstatus( NtQuerySystemInformation( SystemCpuInformation, &sci, sizeof(sci), NULL ))) return;
66 si->u.s.wProcessorArchitecture = sci.Architecture;
67 si->u.s.wReserved = 0;
68 si->dwPageSize = system_info.PageSize;
69 si->lpMinimumApplicationAddress = system_info.LowestUserAddress;
70 si->lpMaximumApplicationAddress = system_info.HighestUserAddress;
71 si->dwActiveProcessorMask = system_info.ActiveProcessorsAffinityMask;
72 si->dwNumberOfProcessors = system_info.NumberOfProcessors;
74 switch (sci.Architecture)
76 case PROCESSOR_ARCHITECTURE_INTEL:
77 switch (sci.Level)
79 case 3: si->dwProcessorType = PROCESSOR_INTEL_386; break;
80 case 4: si->dwProcessorType = PROCESSOR_INTEL_486; break;
81 case 5:
82 case 6: si->dwProcessorType = PROCESSOR_INTEL_PENTIUM; break;
83 default: si->dwProcessorType = PROCESSOR_INTEL_PENTIUM; break;
85 break;
86 case PROCESSOR_ARCHITECTURE_PPC:
87 switch (sci.Level)
89 case 1: si->dwProcessorType = PROCESSOR_PPC_601; break;
90 case 3:
91 case 6: si->dwProcessorType = PROCESSOR_PPC_603; break;
92 case 4: si->dwProcessorType = PROCESSOR_PPC_604; break;
93 case 9: si->dwProcessorType = PROCESSOR_PPC_604; break;
94 case 20: si->dwProcessorType = PROCESSOR_PPC_620; break;
95 default: si->dwProcessorType = 0;
97 break;
98 case PROCESSOR_ARCHITECTURE_AMD64:
99 si->dwProcessorType = PROCESSOR_AMD_X8664;
100 break;
101 case PROCESSOR_ARCHITECTURE_ARM:
102 switch (sci.Level)
104 case 4: si->dwProcessorType = PROCESSOR_ARM_7TDMI; break;
105 default: si->dwProcessorType = PROCESSOR_ARM920;
107 break;
108 case PROCESSOR_ARCHITECTURE_ARM64:
109 si->dwProcessorType = 0;
110 break;
111 default:
112 FIXME("Unknown processor architecture %x\n", sci.Architecture);
113 si->dwProcessorType = 0;
115 si->dwAllocationGranularity = system_info.AllocationGranularity;
116 si->wProcessorLevel = sci.Level;
117 si->wProcessorRevision = sci.Revision;
121 /***********************************************************************
122 * GetNativeSystemInfo [KERNEL32.@]
124 VOID WINAPI GetNativeSystemInfo(
125 LPSYSTEM_INFO si /* [out] Destination for system information, may not be NULL */)
127 BOOL is_wow64;
129 GetSystemInfo(si);
131 IsWow64Process(GetCurrentProcess(), &is_wow64);
132 if (is_wow64)
134 if (si->u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
136 si->u.s.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_AMD64;
137 si->dwProcessorType = PROCESSOR_AMD_X8664;
139 else
141 FIXME("Add the proper information for %d in wow64 mode\n",
142 si->u.s.wProcessorArchitecture);
147 /***********************************************************************
148 * K32GetPerformanceInfo (KERNEL32.@)
150 BOOL WINAPI K32GetPerformanceInfo(PPERFORMANCE_INFORMATION info, DWORD size)
152 SYSTEM_PERFORMANCE_INFORMATION perf;
153 SYSTEM_BASIC_INFORMATION basic;
154 SYSTEM_PROCESS_INFORMATION *process, *spi;
155 DWORD info_size;
156 NTSTATUS status;
158 TRACE( "(%p, %d)\n", info, size );
160 if (size < sizeof(*info))
162 SetLastError( ERROR_BAD_LENGTH );
163 return FALSE;
166 status = NtQuerySystemInformation( SystemPerformanceInformation, &perf, sizeof(perf), NULL );
167 if (status) goto err;
168 status = NtQuerySystemInformation( SystemBasicInformation, &basic, sizeof(basic), NULL );
169 if (status) goto err;
171 info->cb = sizeof(*info);
172 info->CommitTotal = perf.TotalCommittedPages;
173 info->CommitLimit = perf.TotalCommitLimit;
174 info->CommitPeak = perf.PeakCommitment;
175 info->PhysicalTotal = basic.MmNumberOfPhysicalPages;
176 info->PhysicalAvailable = perf.AvailablePages;
177 info->SystemCache = 0;
178 info->KernelTotal = perf.PagedPoolUsage + perf.NonPagedPoolUsage;
179 info->KernelPaged = perf.PagedPoolUsage;
180 info->KernelNonpaged = perf.NonPagedPoolUsage;
181 info->PageSize = basic.PageSize;
183 /* fields from SYSTEM_PROCESS_INFORMATION */
184 NtQuerySystemInformation( SystemProcessInformation, NULL, 0, &info_size );
185 for (;;)
187 process = HeapAlloc( GetProcessHeap(), 0, info_size );
188 if (!process)
190 SetLastError( ERROR_OUTOFMEMORY );
191 return FALSE;
193 status = NtQuerySystemInformation( SystemProcessInformation, process, info_size, &info_size );
194 if (!status) break;
195 HeapFree( GetProcessHeap(), 0, process );
196 if (status != STATUS_INFO_LENGTH_MISMATCH)
197 goto err;
200 info->HandleCount = info->ProcessCount = info->ThreadCount = 0;
201 spi = process;
202 for (;;)
204 info->ProcessCount++;
205 info->HandleCount += spi->HandleCount;
206 info->ThreadCount += spi->dwThreadCount;
207 if (spi->NextEntryOffset == 0) break;
208 spi = (SYSTEM_PROCESS_INFORMATION *)((char *)spi + spi->NextEntryOffset);
210 HeapFree( GetProcessHeap(), 0, process );
211 return TRUE;
213 err:
214 SetLastError( RtlNtStatusToDosError( status ) );
215 return FALSE;
218 /***********************************************************************
219 * GetLargePageMinimum (KERNEL32.@)
221 SIZE_T WINAPI GetLargePageMinimum(void)
223 #if defined(__i386__) || defined(__x86_64__) || defined(__arm__)
224 return 2 * 1024 * 1024;
225 #endif
226 FIXME("Not implemented on your platform/architecture.\n");
227 return 0;
230 /***********************************************************************
231 * GetActiveProcessorGroupCount (KERNEL32.@)
233 WORD WINAPI GetActiveProcessorGroupCount(void)
235 FIXME("semi-stub, always returning 1\n");
236 return 1;
239 /***********************************************************************
240 * GetActiveProcessorCount (KERNEL32.@)
242 DWORD WINAPI GetActiveProcessorCount(WORD group)
244 SYSTEM_INFO si;
245 DWORD cpus;
247 GetSystemInfo( &si );
248 cpus = si.dwNumberOfProcessors;
250 FIXME("semi-stub, returning %u\n", cpus);
251 return cpus;
254 /***********************************************************************
255 * GetMaximumProcessorCount (KERNEL32.@)
257 DWORD WINAPI GetMaximumProcessorCount(WORD group)
259 SYSTEM_INFO si;
260 DWORD cpus;
262 GetSystemInfo( &si );
263 cpus = si.dwNumberOfProcessors;
265 FIXME("semi-stub, returning %u\n", cpus);
266 return cpus;
269 /***********************************************************************
270 * GetEnabledXStateFeatures (KERNEL32.@)
272 DWORD64 WINAPI GetEnabledXStateFeatures(void)
274 FIXME("\n");
275 return 0;
278 /***********************************************************************
279 * GetSystemFirmwareTable (KERNEL32.@)
281 UINT WINAPI GetSystemFirmwareTable(DWORD provider, DWORD id, void *buffer, DWORD size)
283 ULONG buffer_size = FIELD_OFFSET(SYSTEM_FIRMWARE_TABLE_INFORMATION, TableBuffer) + size;
284 SYSTEM_FIRMWARE_TABLE_INFORMATION *sfti = HeapAlloc(GetProcessHeap(), 0, buffer_size);
285 NTSTATUS status;
287 TRACE("(0x%08x, 0x%08x, %p, %d)\n", provider, id, buffer, size);
289 if (!sfti)
291 SetLastError(ERROR_OUTOFMEMORY);
292 return 0;
295 sfti->ProviderSignature = provider;
296 sfti->Action = SystemFirmwareTable_Get;
297 sfti->TableID = id;
299 status = NtQuerySystemInformation(SystemFirmwareTableInformation, sfti, buffer_size, &buffer_size);
300 buffer_size -= FIELD_OFFSET(SYSTEM_FIRMWARE_TABLE_INFORMATION, TableBuffer);
301 if (buffer_size <= size)
302 memcpy(buffer, sfti->TableBuffer, buffer_size);
304 if (status) SetLastError(RtlNtStatusToDosError(status));
305 HeapFree(GetProcessHeap(), 0, sfti);
306 return buffer_size;
310 /***********************************************************************
311 * EnumSystemFirmwareTables (KERNEL32.@)
313 UINT WINAPI EnumSystemFirmwareTables(DWORD provider, void *buffer, DWORD size)
315 FIXME("(0x%08x, %p, %d)\n", provider, buffer, size);
316 return 0;