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 * GetSystemInfo [KERNEL32.@]
52 * Get information about the system.
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
:
79 case 3: si
->dwProcessorType
= PROCESSOR_INTEL_386
; break;
80 case 4: si
->dwProcessorType
= PROCESSOR_INTEL_486
; break;
82 case 6: si
->dwProcessorType
= PROCESSOR_INTEL_PENTIUM
; break;
83 default: si
->dwProcessorType
= PROCESSOR_INTEL_PENTIUM
; break;
86 case PROCESSOR_ARCHITECTURE_PPC
:
89 case 1: si
->dwProcessorType
= PROCESSOR_PPC_601
; break;
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;
98 case PROCESSOR_ARCHITECTURE_AMD64
:
99 si
->dwProcessorType
= PROCESSOR_AMD_X8664
;
101 case PROCESSOR_ARCHITECTURE_ARM
:
104 case 4: si
->dwProcessorType
= PROCESSOR_ARM_7TDMI
; break;
105 default: si
->dwProcessorType
= PROCESSOR_ARM920
;
108 case PROCESSOR_ARCHITECTURE_ARM64
:
109 si
->dwProcessorType
= 0;
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 */)
131 IsWow64Process(GetCurrentProcess(), &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
;
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
;
158 TRACE( "(%p, %d)\n", info
, size
);
160 if (size
< sizeof(*info
))
162 SetLastError( ERROR_BAD_LENGTH
);
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
);
187 process
= HeapAlloc( GetProcessHeap(), 0, info_size
);
190 SetLastError( ERROR_OUTOFMEMORY
);
193 status
= NtQuerySystemInformation( SystemProcessInformation
, process
, info_size
, &info_size
);
195 HeapFree( GetProcessHeap(), 0, process
);
196 if (status
!= STATUS_INFO_LENGTH_MISMATCH
)
200 info
->HandleCount
= info
->ProcessCount
= info
->ThreadCount
= 0;
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
);
214 SetLastError( RtlNtStatusToDosError( status
) );
218 /***********************************************************************
219 * GetLargePageMinimum (KERNEL32.@)
221 SIZE_T WINAPI
GetLargePageMinimum(void)
223 #if defined(__i386__) || defined(__x86_64__) || defined(__arm__)
224 return 2 * 1024 * 1024;
226 FIXME("Not implemented on your platform/architecture.\n");
230 /***********************************************************************
231 * GetActiveProcessorGroupCount (KERNEL32.@)
233 WORD WINAPI
GetActiveProcessorGroupCount(void)
235 FIXME("semi-stub, always returning 1\n");
239 /***********************************************************************
240 * GetActiveProcessorCount (KERNEL32.@)
242 DWORD WINAPI
GetActiveProcessorCount(WORD group
)
247 GetSystemInfo( &si
);
248 cpus
= si
.dwNumberOfProcessors
;
250 FIXME("semi-stub, returning %u\n", cpus
);
254 /***********************************************************************
255 * GetMaximumProcessorCount (KERNEL32.@)
257 DWORD WINAPI
GetMaximumProcessorCount(WORD group
)
262 GetSystemInfo( &si
);
263 cpus
= si
.dwNumberOfProcessors
;
265 FIXME("semi-stub, returning %u\n", cpus
);
269 /***********************************************************************
270 * GetEnabledXStateFeatures (KERNEL32.@)
272 DWORD64 WINAPI
GetEnabledXStateFeatures(void)
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
);
287 TRACE("(0x%08x, 0x%08x, %p, %d)\n", provider
, id
, buffer
, size
);
291 SetLastError(ERROR_OUTOFMEMORY
);
295 sfti
->ProviderSignature
= provider
;
296 sfti
->Action
= SystemFirmwareTable_Get
;
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
);
310 /***********************************************************************
311 * EnumSystemFirmwareTables (KERNEL32.@)
313 UINT WINAPI
EnumSystemFirmwareTables(DWORD provider
, void *buffer
, DWORD size
)
315 FIXME("(0x%08x, %p, %d)\n", provider
, buffer
, size
);