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
23 #include "wine/port.h"
28 #ifdef HAVE_SYS_TIME_H
29 # include <sys/time.h>
33 #define NONAMELESSUNION
34 #define NONAMELESSSTRUCT
36 #define WIN32_NO_STATUS
43 #include "wine/unicode.h"
44 #include "kernel_private.h"
45 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(reg
);
49 /****************************************************************************
50 * QueryPerformanceCounter (KERNEL32.@)
52 * Get the current value of the performance counter.
55 * counter [O] Destination for the current counter reading
58 * Success: TRUE. counter contains the current reading
62 * See QueryPerformanceFrequency.
64 BOOL WINAPI
QueryPerformanceCounter(PLARGE_INTEGER counter
)
66 NtQueryPerformanceCounter( counter
, NULL
);
71 /****************************************************************************
72 * QueryPerformanceFrequency (KERNEL32.@)
74 * Get the resolution of the performance counter.
77 * frequency [O] Destination for the counter resolution
80 * Success. TRUE. Frequency contains the resolution of the counter.
84 * See QueryPerformanceCounter.
86 BOOL WINAPI
QueryPerformanceFrequency(PLARGE_INTEGER frequency
)
88 LARGE_INTEGER counter
;
89 NtQueryPerformanceCounter( &counter
, frequency
);
94 /***********************************************************************
95 * GetSystemInfo [KERNEL32.@]
97 * Get information about the system.
102 VOID WINAPI
GetSystemInfo(
103 LPSYSTEM_INFO si
/* [out] Destination for system information, may not be NULL */)
106 SYSTEM_CPU_INFORMATION sci
;
108 TRACE("si=0x%p\n", si
);
110 if ((nts
= NtQuerySystemInformation( SystemCpuInformation
, &sci
, sizeof(sci
), NULL
)) != STATUS_SUCCESS
)
112 SetLastError(RtlNtStatusToDosError(nts
));
116 si
->u
.s
.wProcessorArchitecture
= sci
.Architecture
;
117 si
->u
.s
.wReserved
= 0;
118 si
->dwPageSize
= system_info
.PageSize
;
119 si
->lpMinimumApplicationAddress
= system_info
.LowestUserAddress
;
120 si
->lpMaximumApplicationAddress
= system_info
.HighestUserAddress
;
121 si
->dwActiveProcessorMask
= system_info
.ActiveProcessorsAffinityMask
;
122 si
->dwNumberOfProcessors
= system_info
.NumberOfProcessors
;
124 switch (sci
.Architecture
)
126 case PROCESSOR_ARCHITECTURE_INTEL
:
129 case 3: si
->dwProcessorType
= PROCESSOR_INTEL_386
; break;
130 case 4: si
->dwProcessorType
= PROCESSOR_INTEL_486
; break;
132 case 6: si
->dwProcessorType
= PROCESSOR_INTEL_PENTIUM
; break;
133 default: si
->dwProcessorType
= PROCESSOR_INTEL_PENTIUM
; break;
136 case PROCESSOR_ARCHITECTURE_PPC
:
139 case 1: si
->dwProcessorType
= PROCESSOR_PPC_601
; break;
141 case 6: si
->dwProcessorType
= PROCESSOR_PPC_603
; break;
142 case 4: si
->dwProcessorType
= PROCESSOR_PPC_604
; break;
143 case 9: si
->dwProcessorType
= PROCESSOR_PPC_604
; break;
144 case 20: si
->dwProcessorType
= PROCESSOR_PPC_620
; break;
145 default: si
->dwProcessorType
= 0;
148 case PROCESSOR_ARCHITECTURE_AMD64
:
149 si
->dwProcessorType
= PROCESSOR_AMD_X8664
;
151 case PROCESSOR_ARCHITECTURE_ARM
:
154 case 4: si
->dwProcessorType
= PROCESSOR_ARM_7TDMI
; break;
155 default: si
->dwProcessorType
= PROCESSOR_ARM920
;
158 case PROCESSOR_ARCHITECTURE_ARM64
:
159 si
->dwProcessorType
= 0;
162 FIXME("Unknown processor architecture %x\n", sci
.Architecture
);
163 si
->dwProcessorType
= 0;
165 si
->dwAllocationGranularity
= system_info
.AllocationGranularity
;
166 si
->wProcessorLevel
= sci
.Level
;
167 si
->wProcessorRevision
= sci
.Revision
;
171 /***********************************************************************
172 * GetNativeSystemInfo [KERNEL32.@]
174 VOID WINAPI
GetNativeSystemInfo(
175 LPSYSTEM_INFO si
/* [out] Destination for system information, may not be NULL */)
181 IsWow64Process(GetCurrentProcess(), &is_wow64
);
184 if (si
->u
.s
.wProcessorArchitecture
== PROCESSOR_ARCHITECTURE_INTEL
)
186 si
->u
.s
.wProcessorArchitecture
= PROCESSOR_ARCHITECTURE_AMD64
;
187 si
->dwProcessorType
= PROCESSOR_AMD_X8664
;
191 FIXME("Add the proper information for %d in wow64 mode\n",
192 si
->u
.s
.wProcessorArchitecture
);
197 /***********************************************************************
198 * IsProcessorFeaturePresent [KERNEL32.@]
200 * Determine if the cpu supports a given feature.
202 BOOL WINAPI
IsProcessorFeaturePresent ( DWORD feature
)
204 return RtlIsProcessorFeaturePresent( feature
);
207 /***********************************************************************
208 * K32GetPerformanceInfo (KERNEL32.@)
210 BOOL WINAPI
K32GetPerformanceInfo(PPERFORMANCE_INFORMATION info
, DWORD size
)
214 SYSTEM_PERFORMANCE_INFORMATION performance
;
215 SYSTEM_PROCESS_INFORMATION process
;
216 SYSTEM_BASIC_INFORMATION basic
;
218 SYSTEM_PROCESS_INFORMATION
*spi
;
219 DWORD process_info_size
;
222 TRACE( "(%p, %d)\n", info
, size
);
224 if (size
< sizeof(*info
))
226 SetLastError( ERROR_BAD_LENGTH
);
230 memset( info
, 0, sizeof(*info
) );
231 info
->cb
= sizeof(*info
);
233 /* fields from SYSTEM_PROCESS_INFORMATION */
234 NtQuerySystemInformation( SystemProcessInformation
, NULL
, 0, &process_info_size
);
237 sysinfo
= HeapAlloc( GetProcessHeap(), 0, max(process_info_size
, sizeof(*sysinfo
)) );
240 SetLastError( ERROR_OUTOFMEMORY
);
243 status
= NtQuerySystemInformation( SystemProcessInformation
, &sysinfo
->process
,
244 process_info_size
, &process_info_size
);
246 if (status
!= STATUS_INFO_LENGTH_MISMATCH
)
248 HeapFree( GetProcessHeap(), 0, sysinfo
);
250 for (spi
= &sysinfo
->process
;; spi
= (SYSTEM_PROCESS_INFORMATION
*)(((PCHAR
)spi
) + spi
->NextEntryOffset
))
252 info
->ProcessCount
++;
253 info
->HandleCount
+= spi
->HandleCount
;
254 info
->ThreadCount
+= spi
->dwThreadCount
;
255 if (spi
->NextEntryOffset
== 0) break;
258 /* fields from SYSTEM_PERFORMANCE_INFORMATION */
259 status
= NtQuerySystemInformation( SystemPerformanceInformation
, &sysinfo
->performance
,
260 sizeof(sysinfo
->performance
), NULL
);
261 if (status
) goto err
;
262 info
->CommitTotal
= sysinfo
->performance
.TotalCommittedPages
;
263 info
->CommitLimit
= sysinfo
->performance
.TotalCommitLimit
;
264 info
->CommitPeak
= sysinfo
->performance
.PeakCommitment
;
265 info
->PhysicalAvailable
= sysinfo
->performance
.AvailablePages
;
266 info
->KernelTotal
= sysinfo
->performance
.PagedPoolUsage
+
267 sysinfo
->performance
.NonPagedPoolUsage
;
268 info
->KernelPaged
= sysinfo
->performance
.PagedPoolUsage
;
269 info
->KernelNonpaged
= sysinfo
->performance
.NonPagedPoolUsage
;
271 /* fields from SYSTEM_BASIC_INFORMATION */
272 status
= NtQuerySystemInformation( SystemBasicInformation
, &sysinfo
->basic
,
273 sizeof(sysinfo
->basic
), NULL
);
274 if (status
) goto err
;
275 info
->PhysicalTotal
= sysinfo
->basic
.MmNumberOfPhysicalPages
;
276 info
->PageSize
= sysinfo
->basic
.PageSize
;
279 HeapFree( GetProcessHeap(), 0, sysinfo
);
282 SetLastError( RtlNtStatusToDosError( status
) );
288 /***********************************************************************
289 * GetLargePageMinimum (KERNEL32.@)
291 SIZE_T WINAPI
GetLargePageMinimum(void)
293 #if defined(__i386__) || defined(__x86_64__) || defined(__arm__)
294 return 2 * 1024 * 1024;
296 FIXME("Not implemented on your platform/architecture.\n");
300 /***********************************************************************
301 * GetActiveProcessorGroupCount (KERNEL32.@)
303 WORD WINAPI
GetActiveProcessorGroupCount(void)
305 FIXME("semi-stub, always returning 1\n");
309 /***********************************************************************
310 * GetActiveProcessorCount (KERNEL32.@)
312 DWORD WINAPI
GetActiveProcessorCount(WORD group
)
317 GetSystemInfo( &si
);
318 cpus
= si
.dwNumberOfProcessors
;
320 FIXME("semi-stub, returning %u\n", cpus
);
324 /***********************************************************************
325 * GetMaximumProcessorCount (KERNEL32.@)
327 DWORD WINAPI
GetMaximumProcessorCount(WORD group
)
332 GetSystemInfo( &si
);
333 cpus
= si
.dwNumberOfProcessors
;
335 FIXME("semi-stub, returning %u\n", cpus
);
339 /***********************************************************************
340 * GetEnabledXStateFeatures (KERNEL32.@)
342 DWORD64 WINAPI
GetEnabledXStateFeatures(void)
348 /***********************************************************************
349 * GetSystemFirmwareTable (KERNEL32.@)
351 UINT WINAPI
GetSystemFirmwareTable(DWORD provider
, DWORD id
, void *buffer
, DWORD size
)
353 ULONG buffer_size
= FIELD_OFFSET(SYSTEM_FIRMWARE_TABLE_INFORMATION
, TableBuffer
) + size
;
354 SYSTEM_FIRMWARE_TABLE_INFORMATION
*sfti
= HeapAlloc(GetProcessHeap(), 0, buffer_size
);
357 TRACE("(0x%08x, 0x%08x, %p, %d)\n", provider
, id
, buffer
, size
);
361 SetLastError(ERROR_OUTOFMEMORY
);
365 sfti
->ProviderSignature
= provider
;
366 sfti
->Action
= SystemFirmwareTable_Get
;
369 status
= NtQuerySystemInformation(SystemFirmwareTableInformation
, sfti
, buffer_size
, &buffer_size
);
370 buffer_size
-= FIELD_OFFSET(SYSTEM_FIRMWARE_TABLE_INFORMATION
, TableBuffer
);
371 if (buffer_size
<= size
)
372 memcpy(buffer
, sfti
->TableBuffer
, buffer_size
);
374 if (status
) SetLastError(RtlNtStatusToDosError(status
));
375 HeapFree(GetProcessHeap(), 0, sfti
);