Skip to content

Commit 0ea5639

Browse files
committed
Platform (Windows): prefers Nt* APIs
1 parent aa3a916 commit 0ea5639

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/common/impl/FFPlatform_windows.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -248,21 +248,30 @@ static void getSystemReleaseAndVersion(FFPlatformSysinfo* info)
248248
}
249249
}
250250

251-
static void getSystemArchitectureAndPageSize(FFPlatformSysinfo* info)
251+
static void getSystemPageSize(FFPlatformSysinfo* info)
252252
{
253-
SYSTEM_INFO sysInfo;
254-
GetNativeSystemInfo(&sysInfo);
253+
SYSTEM_BASIC_INFORMATION sbi;
254+
if (NT_SUCCESS(NtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), NULL)))
255+
info->pageSize = sbi.PhysicalPageSize;
256+
else
257+
info->pageSize = 4096;
258+
}
255259

256-
switch(sysInfo.wProcessorArchitecture)
260+
static void getSystemArchitecture(FFPlatformSysinfo* info)
261+
{
262+
SYSTEM_PROCESSOR_INFORMATION spi;
263+
if (NT_SUCCESS(NtQuerySystemInformation(SystemProcessorInformation, &spi, sizeof(spi), NULL)))
257264
{
265+
switch (spi.ProcessorArchitecture)
266+
{
258267
case PROCESSOR_ARCHITECTURE_AMD64:
259268
ffStrbufSetStatic(&info->architecture, "x86_64");
260269
break;
261270
case PROCESSOR_ARCHITECTURE_IA64:
262271
ffStrbufSetStatic(&info->architecture, "ia64");
263272
break;
264273
case PROCESSOR_ARCHITECTURE_INTEL:
265-
switch (sysInfo.wProcessorLevel)
274+
switch (spi.ProcessorLevel)
266275
{
267276
case 4:
268277
ffStrbufSetStatic(&info->architecture, "i486");
@@ -300,9 +309,8 @@ static void getSystemArchitectureAndPageSize(FFPlatformSysinfo* info)
300309
default:
301310
ffStrbufSetStatic(&info->architecture, "unknown");
302311
break;
312+
}
303313
}
304-
305-
info->pageSize = sysInfo.dwPageSize;
306314
}
307315

308316
void ffPlatformInitImpl(FFPlatform* platform)
@@ -319,5 +327,6 @@ void ffPlatformInitImpl(FFPlatform* platform)
319327
getUserShell(platform);
320328

321329
getSystemReleaseAndVersion(&platform->sysinfo);
322-
getSystemArchitectureAndPageSize(&platform->sysinfo);
330+
getSystemArchitecture(&platform->sysinfo);
331+
getSystemPageSize(&platform->sysinfo);
323332
}

0 commit comments

Comments
 (0)