Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/coreclr/debug/createdump/createdumpunix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

#include "createdump.h"
#include <minipal/ospagesize.h>

#if defined(__arm__) || defined(__aarch64__) || defined(__loongarch64) || defined(__riscv)
long g_pageSize = 0;
Expand All @@ -20,7 +21,7 @@ CreateDump(const CreateDumpOptions& options)

// Initialize PAGE_SIZE
#if defined(__arm__) || defined(__aarch64__) || defined(__loongarch64) || defined(__riscv)
g_pageSize = sysconf(_SC_PAGESIZE);
g_pageSize = minipal_getpagesize();
#endif
TRACE("PAGE_SIZE %d\n", PAGE_SIZE);

Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/debug/daccess/enummem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ HRESULT ClrDataAccess::EnumMemCollectImages()
ulSize = assembly->GetLoadedLayout()->GetSize();
}

// memory are mapped in GetOsPageSize() size.
// memory are mapped in minipal_getpagesize() size.
// Some memory are mapped in but some are not. You cannot
// write all in one block. So iterating through page size
//
Expand All @@ -112,7 +112,7 @@ HRESULT ClrDataAccess::EnumMemCollectImages()
// MethodHeader MethodDesc::GetILHeader. Without this RVA,
// all locals are broken. In case, you are asked about this question again.
//
ulSizeBlock = ulSize > GetOsPageSize() ? GetOsPageSize() : ulSize;
ulSizeBlock = ulSize > minipal_getpagesize() ? minipal_getpagesize() : ulSize;
ReportMem(pStartAddr, ulSizeBlock, false);
pStartAddr += ulSizeBlock;
ulSize -= ulSizeBlock;
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/debug/di/shimlocaldatatarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ ShimLocalDataTarget::ReadVirtual(
{
// Calculate bytes to read and don't let read cross
// a page boundary.
readSize = GetOsPageSize() - (ULONG32)(address & (GetOsPageSize() - 1));
readSize = minipal_getpagesize() - (ULONG32)(address & (minipal_getpagesize() - 1));
readSize = min(cbRequestSize, readSize);

if (!ReadProcessMemory(m_hProcess, (PVOID)(ULONG_PTR)address,
Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/debug/di/shimremotedatatarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "dbgtransportsession.h"
#include "dbgtransportmanager.h"

#include <minipal/ospagesize.h>

#ifdef __APPLE__
#include <mach/mach.h>
#else
Expand Down Expand Up @@ -299,7 +301,7 @@ ShimRemoteDataTarget::ReadVirtual(
#ifdef __APPLE__
// vm_read_overwrite usually requires the address be page-aligned and the size be a multiple
// of the page size, so we always page-align ourselves and copy out the relevant slice.
const size_t pageSize = (size_t)sysconf(_SC_PAGESIZE);
const size_t pageSize = minipal_getpagesize();
vm_address_t addressAligned = (vm_address_t)(address & ~(ULONG64)(pageSize - 1));
ssize_t offset = (ssize_t)(address & (pageSize - 1));
ssize_t bytesLeft = (ssize_t)cbRequestSize;
Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/gc/unix/gcenv.unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ uint64_t GetAvailablePhysicalMemory()
sz = sizeof(free_count);
sysctlbyname("vm.stats.vm.v_free_count", &free_count, &sz, NULL, 0);

available = (inactive_count + laundry_count + free_count) * sysconf(_SC_PAGESIZE);
available = (inactive_count + laundry_count + free_count) * minipal_getpagesize();
#elif defined(__HAIKU__)
system_info info;
if (get_system_info(&info) == B_OK)
Expand Down Expand Up @@ -1140,7 +1140,7 @@ uint64_t GetAvailablePageFile()
rc = sysctlnametomib("vm.swap_info", mib, &length);
if (rc == 0)
{
int pagesize = getpagesize();
uint32_t pagesize = minipal_getpagesize();
// Aggregate the information for all swap files on the system
for (mib[2] = 0; ; mib[2]++)
{
Expand All @@ -1161,7 +1161,7 @@ uint64_t GetAvailablePageFile()
struct anoninfo ai;
if (swapctl(SC_AINFO, &ai) != -1)
{
int pagesize = getpagesize();
uint32_t pagesize = minipal_getpagesize();
available = ai.ani_free * pagesize;
}
#elif HAVE_SYSINFO
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/inc/loaderheap.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ struct LoaderHeapEvent;
inline UINT32 GetStubCodePageSize()
{
#if (defined(TARGET_ARM64) && defined(TARGET_UNIX)) || defined(TARGET_WASM)
return max(16*1024u, GetOsPageSize());
return max(16*1024u, minipal_getpagesize());
#elif defined(TARGET_ARM)
return 4096; // ARM is special as the 32bit instruction set does not easily permit a 16KB offset
#else
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/inc/pedecoder.inl
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ inline PEDecoder::PEDecoder(PTR_VOID mappedBase, bool fixedUp /*= FALSE*/)
CONTRACTL_END;

// Temporarily set the size to 2 pages, so we can get the headers.
m_size = GetOsPageSize()*2;
m_size = minipal_getpagesize()*2;

m_pNTHeaders = PTR_IMAGE_NT_HEADERS(FindNTHeaders());
if (!m_pNTHeaders)
Expand Down Expand Up @@ -182,7 +182,7 @@ inline HRESULT PEDecoder::Init(void *mappedBase, bool fixedUp /*= FALSE*/)
m_flags |= FLAG_RELOCATED;

// Temporarily set the size to 2 pages, so we can get the headers.
m_size = GetOsPageSize()*2;
m_size = minipal_getpagesize()*2;

m_pNTHeaders = FindNTHeaders();
if (!m_pNTHeaders)
Expand Down
3 changes: 1 addition & 2 deletions src/coreclr/inc/utilcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ using std::nothrow;
#include <stddef.h>
#include <minipal/guid.h>
#include <minipal/log.h>
#include <minipal/ospagesize.h>
#include <dn-u16.h>

#include "clrnt.h"
Expand Down Expand Up @@ -577,8 +578,6 @@ int GetTotalProcessorCount();
//******************************************************************************
int GetCurrentProcessCpuCount();

uint32_t GetOsPageSize();


//*****************************************************************************
// Return != 0 if the bit at the specified index in the array is on and 0 if
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/pal/src/exception/machexception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ SET_DEFAULT_DEBUG_CHANNEL(EXCEPT); // some headers have code with asserts, so do

#include <minipal/debugger.h>
#include <minipal/utils.h>
#include <minipal/ospagesize.h>

#include "machmessage.h"

Expand Down Expand Up @@ -751,7 +752,7 @@ HijackFaultingThread(
if (exceptionRecord.ExceptionCode == EXCEPTION_ACCESS_VIOLATION)
{
// Calculate the page base addresses for the fault and the faulting thread's SP.
int cbPage = getpagesize();
int cbPage = minipal_getpagesize();
char *pFaultPage = (char*)(exceptionRecord.ExceptionInformation[1] & ~(cbPage - 1));
char *pStackTopPage = (char*)((size_t)targetSP & ~(cbPage - 1));
Comment thread
pavelsavara marked this conversation as resolved.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
**=========================================================*/

#include <palsuite.h>
#include <minipal/ospagesize.h>

PALTEST(miscellaneous_IsBadWritePtr_test2_paltest_isbadwriteptr_test2, "miscellaneous/IsBadWritePtr/test2/paltest_isbadwriteptr_test2")
{
Expand All @@ -31,7 +32,7 @@ PALTEST(miscellaneous_IsBadWritePtr_test2_paltest_isbadwriteptr_test2, "miscella
*/

PageOne = VirtualAlloc(NULL,
GetOsPageSize()*4,
minipal_getpagesize()*4,
MEM_RESERVE,
PAGE_NOACCESS);

Expand All @@ -43,7 +44,7 @@ PALTEST(miscellaneous_IsBadWritePtr_test2_paltest_isbadwriteptr_test2, "miscella
/* Set the first Page to PAGE_NOACCESS */

PageOne = VirtualAlloc(PageOne,
GetOsPageSize(),
minipal_getpagesize(),
MEM_COMMIT,
PAGE_NOACCESS);

Expand All @@ -57,8 +58,8 @@ PALTEST(miscellaneous_IsBadWritePtr_test2_paltest_isbadwriteptr_test2, "miscella

/* Set the second Page to PAGE_READWRITE */

PageTwo = VirtualAlloc(((BYTE*)PageOne)+GetOsPageSize(),
GetOsPageSize(),
PageTwo = VirtualAlloc(((BYTE*)PageOne)+minipal_getpagesize(),
minipal_getpagesize(),
MEM_COMMIT,
PAGE_READWRITE);
if(PageTwo == NULL)
Expand All @@ -71,8 +72,8 @@ PALTEST(miscellaneous_IsBadWritePtr_test2_paltest_isbadwriteptr_test2, "miscella

/* Set the third Page to PAGE_NOACCESS */

PageThree = VirtualAlloc(((BYTE*)PageTwo) + (2 * GetOsPageSize()),
GetOsPageSize(),
PageThree = VirtualAlloc(((BYTE*)PageTwo) + (2 * minipal_getpagesize()),
minipal_getpagesize(),
MEM_COMMIT,
PAGE_NOACCESS);

Expand All @@ -87,7 +88,7 @@ PALTEST(miscellaneous_IsBadWritePtr_test2_paltest_isbadwriteptr_test2, "miscella

/* Check that calling IsBadWritePtr on the first page returns non-zero */

if(IsBadWritePtr(PageThree,GetOsPageSize()) == 0)
if(IsBadWritePtr(PageThree,minipal_getpagesize()) == 0)
{
VirtualFree(PageOne,0,MEM_RELEASE);

Expand All @@ -98,7 +99,7 @@ PALTEST(miscellaneous_IsBadWritePtr_test2_paltest_isbadwriteptr_test2, "miscella

/* Check that calling IsBadWritePtr on the middle page returns 0 */

if(IsBadWritePtr(PageTwo,GetOsPageSize()) != 0)
if(IsBadWritePtr(PageTwo,minipal_getpagesize()) != 0)
{
VirtualFree(PageOne,0,MEM_RELEASE);

Expand All @@ -108,7 +109,7 @@ PALTEST(miscellaneous_IsBadWritePtr_test2_paltest_isbadwriteptr_test2, "miscella

/* Check that calling IsBadWritePtr on the third page returns non-zero */

if(IsBadWritePtr(PageThree,GetOsPageSize()) == 0)
if(IsBadWritePtr(PageThree,minipal_getpagesize()) == 0)
{
VirtualFree(PageOne,0,MEM_RELEASE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
**=========================================================*/

#include <palsuite.h>
#include <minipal/ospagesize.h>

PALTEST(miscellaneous_IsBadWritePtr_test3_paltest_isbadwriteptr_test3, "miscellaneous/IsBadWritePtr/test3/paltest_isbadwriteptr_test3")
{
Expand All @@ -28,7 +29,7 @@ PALTEST(miscellaneous_IsBadWritePtr_test3_paltest_isbadwriteptr_test3, "miscella
*/

PageOne = VirtualAlloc(NULL,
GetOsPageSize(),
minipal_getpagesize(),
MEM_COMMIT,
PAGE_READONLY);

Expand All @@ -37,7 +38,7 @@ PALTEST(miscellaneous_IsBadWritePtr_test3_paltest_isbadwriteptr_test3, "miscella
Fail("ERROR: VirtualAlloc failed to commit the required memory.\n");
}

if(IsBadWritePtr(PageOne,GetOsPageSize()) == 0)
if(IsBadWritePtr(PageOne,minipal_getpagesize()) == 0)
{
VirtualFree(PageOne,0,MEM_RELEASE);

Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/utilcode/clrhost_nodependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ BOOL DbgIsExecutable(LPVOID lpMem, SIZE_T length)
// No NX support on PAL
return TRUE;
#else // !(TARGET_UNIX)
BYTE *regionStart = (BYTE*) ALIGN_DOWN((BYTE*)lpMem, GetOsPageSize());
BYTE *regionEnd = (BYTE*) ALIGN_UP((BYTE*)lpMem+length, GetOsPageSize());
BYTE *regionStart = (BYTE*) ALIGN_DOWN((BYTE*)lpMem, minipal_getpagesize());
BYTE *regionEnd = (BYTE*) ALIGN_UP((BYTE*)lpMem+length, minipal_getpagesize());
_ASSERTE(length > 0);
_ASSERTE(regionStart < regionEnd);

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/utilcode/dacutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ LiveProcDataTarget::ReadVirtual(
{
// Calculate bytes to read and don't let read cross
// a page boundary.
readSize = GetOsPageSize() - (ULONG32)(address & (GetOsPageSize() - 1));
readSize = minipal_getpagesize() - (ULONG32)(address & (minipal_getpagesize() - 1));
readSize = min(request, readSize);

if (!ReadProcessMemory(m_process, (PVOID)(ULONG_PTR)address,
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/utilcode/executableallocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ void ExecutableAllocator::InitLazyPreferredRange(size_t base, size_t size, int r
}

// Randomize the address space
pStart += GetOsPageSize() * randomPageOffset;
pStart += minipal_getpagesize() * randomPageOffset;

g_lazyPreferredRangeStart = pStart;
g_lazyPreferredRangeHint = pStart;
Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/utilcode/explicitcontrolloaderheap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ ExplicitControlLoaderHeap::ExplicitControlLoaderHeap(bool fMakeExecutable) :
m_pEndReservedRegion = NULL;
m_pAllocPtr = NULL;

m_dwCommitBlockSize = GetOsPageSize();
m_dwCommitBlockSize = minipal_getpagesize();

#ifdef _DEBUG
m_dwDebugWastedBytes = 0;
Expand Down Expand Up @@ -165,7 +165,7 @@ BOOL ExplicitControlLoaderHeap::ReservePages(size_t dwSizeToCommit)
size_t dwSizeToReserve;

// Round to page size again
dwSizeToCommit = ALIGN_UP(dwSizeToCommit, GetOsPageSize());
dwSizeToCommit = ALIGN_UP(dwSizeToCommit, minipal_getpagesize());

ReservedMemoryHolder pData = NULL;
BOOL fReleaseMemory = TRUE;
Expand Down Expand Up @@ -266,7 +266,7 @@ BOOL ExplicitControlLoaderHeap::GetMoreCommittedPages(size_t dwMinSize)
dwSizeToCommit = min((SIZE_T)(m_pEndReservedRegion - m_pPtrToEndOfCommittedRegion), (SIZE_T)m_dwCommitBlockSize);

// Round to page size
dwSizeToCommit = ALIGN_UP(dwSizeToCommit, GetOsPageSize());
dwSizeToCommit = ALIGN_UP(dwSizeToCommit, minipal_getpagesize());

size_t dwSizeToCommitPart = dwSizeToCommit;

Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/utilcode/interleavedloaderheap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ UnlockedInterleavedLoaderHeap::UnlockedInterleavedLoaderHeap(
}
CONTRACTL_END;

_ASSERTE((GetStubCodePageSize() % GetOsPageSize()) == 0); // Stub code page size MUST be in increments of the page size. (Really it must be a power of 2 as well, but this is good enough)
_ASSERTE((GetStubCodePageSize() % minipal_getpagesize()) == 0); // Stub code page size MUST be in increments of the page size. (Really it must be a power of 2 as well, but this is good enough)
}

UnlockedInterleavedLoaderHeap::~UnlockedInterleavedLoaderHeap()
Expand Down Expand Up @@ -151,7 +151,7 @@ BOOL UnlockedInterleavedLoaderHeap::UnlockedReservePages(size_t dwSizeToCommit)
size_t dwSizeToReserve;

// Round to page size again
dwSizeToCommit = ALIGN_UP(dwSizeToCommit, GetOsPageSize());
dwSizeToCommit = ALIGN_UP(dwSizeToCommit, minipal_getpagesize());

ReservedMemoryHolder pData = NULL;

Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/utilcode/loaderheap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ BOOL UnlockedLoaderHeap::UnlockedReservePages(size_t dwSizeToCommit)
size_t dwSizeToReserve;

// Round to page size again
dwSizeToCommit = ALIGN_UP(dwSizeToCommit, GetOsPageSize());
dwSizeToCommit = ALIGN_UP(dwSizeToCommit, minipal_getpagesize());

ReservedMemoryHolder pData = NULL;
BOOL fReleaseMemory = TRUE;
Expand Down Expand Up @@ -307,7 +307,7 @@ BOOL UnlockedLoaderHeap::GetMoreCommittedPages(size_t dwMinSize)
dwSizeToCommit = min((SIZE_T)(m_pEndReservedRegion - m_pPtrToEndOfCommittedRegion), (SIZE_T)m_dwCommitBlockSize);

// Round to page size
dwSizeToCommit = ALIGN_UP(dwSizeToCommit, GetOsPageSize());
dwSizeToCommit = ALIGN_UP(dwSizeToCommit, minipal_getpagesize());

size_t dwSizeToCommitPart = dwSizeToCommit;

Expand Down
30 changes: 0 additions & 30 deletions src/coreclr/utilcode/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1085,36 +1085,6 @@ DWORD_PTR GetCurrentProcessCpuMask()
}
#endif // HOST_WINDOWS

uint32_t GetOsPageSizeUncached()
{
SYSTEM_INFO sysInfo;
::GetSystemInfo(&sysInfo);
return sysInfo.dwAllocationGranularity ? sysInfo.dwAllocationGranularity : 0x1000;
}

namespace
{
Volatile<uint32_t> g_pageSize = 0;
}

uint32_t GetOsPageSize()
{
#ifdef HOST_UNIX
size_t result = g_pageSize.LoadWithoutBarrier();

if(!result)
{
result = GetOsPageSizeUncached();

g_pageSize.StoreWithoutBarrier(result);
}

return result;
#else
return 0x1000;
#endif
}

//=============================================================================
// AssemblyNamesList
//=============================================================================
Expand Down
Loading
Loading