Platform: detect system page size

This commit is contained in:
李通洲
2023-11-08 00:02:00 +08:00
parent 864e707224
commit 3e0d97db2e
7 changed files with 27 additions and 20 deletions
+2
View File
@@ -22,6 +22,8 @@ typedef struct FFPlatform {
FFstrbuf systemVersion;
FFstrbuf systemArchitecture;
FFstrbuf systemDisplayVersion;
uint32_t pageSize;
} FFPlatform;
void ffPlatformInit(FFPlatform* platform);
+13
View File
@@ -10,6 +10,7 @@
#ifdef __APPLE__
#include <libproc.h>
#include <sys/sysctl.h>
#elif defined(__FreeBSD__)
#include <sys/sysctl.h>
#endif
@@ -153,6 +154,16 @@ static void getUserShell(FFPlatform* platform, const struct passwd* pwd)
ffStrbufAppendS(&platform->userShell, shell);
}
static void getPageSize(FFPlatform* platform)
{
#if defined(__FreeBSD__) || defined(__APPLE__)
size_t length = sizeof(platform->pageSize);
sysctl((int[]){ CTL_HW, HW_PAGESIZE }, 2, &platform->pageSize, &length, NULL, 0);
#else
platform->pageSize = (uint32_t) sysconf(_SC_PAGESIZE);
#endif
}
void ffPlatformInitImpl(FFPlatform* platform)
{
struct passwd* pwd = getpwuid(getuid());
@@ -176,4 +187,6 @@ void ffPlatformInitImpl(FFPlatform* platform)
ffStrbufAppendS(&platform->systemVersion, uts.version);
ffStrbufAppendS(&platform->systemArchitecture, uts.machine);
ffStrbufInit(&platform->systemDisplayVersion);
getPageSize(platform);
}
+5 -3
View File
@@ -183,9 +183,9 @@ static void getSystemReleaseAndVersion(FFPlatform* platform)
}
}
static void getSystemArchitecture(FFPlatform* platform)
static void getSystemArchitectureAndPageSize(FFPlatform* platform)
{
SYSTEM_INFO sysInfo = {0};
SYSTEM_INFO sysInfo;
GetNativeSystemInfo(&sysInfo);
switch(sysInfo.wProcessorArchitecture)
@@ -215,6 +215,8 @@ static void getSystemArchitecture(FFPlatform* platform)
default:
break;
}
platform->pageSize = sysInfo.dwPageSize;
}
void ffPlatformInitImpl(FFPlatform* platform)
@@ -230,5 +232,5 @@ void ffPlatformInitImpl(FFPlatform* platform)
getUserShell(platform);
getSystemReleaseAndVersion(platform);
getSystemArchitecture(platform);
getSystemArchitectureAndPageSize(platform);
}