Skip to content

Commit

Permalink
initialize OS page in PalInit
Browse files Browse the repository at this point in the history
  • Loading branch information
VSadov committed Jul 12, 2023
1 parent 4357ab0 commit f92b118
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
9 changes: 6 additions & 3 deletions src/coreclr/nativeaot/Runtime/unix/PalRedhawkInline.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,13 @@ FORCEINLINE void PalSetLastError(int32_t error)

FORCEINLINE int32_t PalOsPageSize()
{
#ifdef HOST_APPLE
return 0x4000;
#elif defined(HOST_AMD64)
#if defined(HOST_AMD64)
// all supported platforms use 4K pages on x64, including emulated environments
return 0x1000;
#elif defined(HOST_APPLE)
// OSX and related OS expose 16-kilobyte pages to the 64-bit userspace
// https://developer.apple.com/library/archive/documentation/Performance/Conceptual/ManagingMemory/Articles/AboutMemory.html
return 0x4000;
#else
return PalGetOsPageSize();
#endif
Expand Down
30 changes: 20 additions & 10 deletions src/coreclr/nativeaot/Runtime/unix/PalRedhawkUnix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,24 @@ void InitializeCurrentProcessCpuCount()
g_RhNumberOfProcessors = count;
}

static uint32_t g_RhPageSize;

void InitializeOsPageSize()
{
g_RhPageSize = (uint32_t)sysconf(_SC_PAGE_SIZE);

#if defined(HOST_AMD64)
ASSERT(g_RhPageSize == 0x1000);
#elif defined(HOST_APPLE)
ASSERT(g_RhPageSize == 0x4000);
#endif
}

REDHAWK_PALEXPORT uint32_t REDHAWK_PALAPI PalGetOsPageSize()
{
return g_RhPageSize;
}

#if defined(TARGET_LINUX) || defined(TARGET_ANDROID)
static pthread_key_t key;
#endif
Expand Down Expand Up @@ -412,6 +430,8 @@ REDHAWK_PALEXPORT bool REDHAWK_PALAPI PalInit()

InitializeCurrentProcessCpuCount();

InitializeOsPageSize();

#if defined(TARGET_LINUX) || defined(TARGET_ANDROID)
if (pthread_key_create(&key, RuntimeThreadShutdown) != 0)
{
Expand Down Expand Up @@ -1152,16 +1172,6 @@ REDHAWK_PALEXPORT int32_t PalGetProcessCpuCount()
return g_RhNumberOfProcessors;
}

REDHAWK_PALEXPORT uint32_t REDHAWK_PALAPI PalGetOsPageSize()
{
static int saved_pagesize = 0;
if (saved_pagesize)
return saved_pagesize;

saved_pagesize = sysconf(_SC_PAGESIZE);
return saved_pagesize;
}

__thread void* pStackHighOut = NULL;
__thread void* pStackLowOut = NULL;

Expand Down

0 comments on commit f92b118

Please sign in to comment.