Skip to content

Commit 15aceea

Browse files
pavelsavaraam11
andauthored
Replace GetOsPageSize() with minipal_getpagesize() in CoreCLR (#127904)
Co-authored-by: Adeel Mujahid <3840695+am11@users.noreply.github.com>
1 parent 1daec0a commit 15aceea

36 files changed

Lines changed: 126 additions & 146 deletions

src/coreclr/debug/createdump/createdumpunix.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
#include "createdump.h"
5+
#include <minipal/ospagesize.h>
56

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

2122
// Initialize PAGE_SIZE
2223
#if defined(__arm__) || defined(__aarch64__) || defined(__loongarch64) || defined(__riscv)
23-
g_pageSize = sysconf(_SC_PAGESIZE);
24+
g_pageSize = minipal_getpagesize();
2425
#endif
2526
TRACE("PAGE_SIZE %d\n", PAGE_SIZE);
2627

src/coreclr/debug/daccess/enummem.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ HRESULT ClrDataAccess::EnumMemCollectImages()
9999
ulSize = assembly->GetLoadedLayout()->GetSize();
100100
}
101101

102-
// memory are mapped in GetOsPageSize() size.
102+
// memory are mapped in minipal_getpagesize() size.
103103
// Some memory are mapped in but some are not. You cannot
104104
// write all in one block. So iterating through page size
105105
//
@@ -112,7 +112,7 @@ HRESULT ClrDataAccess::EnumMemCollectImages()
112112
// MethodHeader MethodDesc::GetILHeader. Without this RVA,
113113
// all locals are broken. In case, you are asked about this question again.
114114
//
115-
ulSizeBlock = ulSize > GetOsPageSize() ? GetOsPageSize() : ulSize;
115+
ulSizeBlock = ulSize > minipal_getpagesize() ? minipal_getpagesize() : ulSize;
116116
ReportMem(pStartAddr, ulSizeBlock, false);
117117
pStartAddr += ulSizeBlock;
118118
ulSize -= ulSizeBlock;

src/coreclr/debug/di/shimlocaldatatarget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ ShimLocalDataTarget::ReadVirtual(
321321
{
322322
// Calculate bytes to read and don't let read cross
323323
// a page boundary.
324-
readSize = GetOsPageSize() - (ULONG32)(address & (GetOsPageSize() - 1));
324+
readSize = minipal_getpagesize() - (ULONG32)(address & (minipal_getpagesize() - 1));
325325
readSize = min(cbRequestSize, readSize);
326326

327327
if (!ReadProcessMemory(m_hProcess, (PVOID)(ULONG_PTR)address,

src/coreclr/debug/di/shimremotedatatarget.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include "dbgtransportsession.h"
1515
#include "dbgtransportmanager.h"
1616

17+
#include <minipal/ospagesize.h>
18+
1719
#ifdef __APPLE__
1820
#include <mach/mach.h>
1921
#else
@@ -299,7 +301,7 @@ ShimRemoteDataTarget::ReadVirtual(
299301
#ifdef __APPLE__
300302
// vm_read_overwrite usually requires the address be page-aligned and the size be a multiple
301303
// of the page size, so we always page-align ourselves and copy out the relevant slice.
302-
const size_t pageSize = (size_t)sysconf(_SC_PAGESIZE);
304+
const size_t pageSize = minipal_getpagesize();
303305
vm_address_t addressAligned = (vm_address_t)(address & ~(ULONG64)(pageSize - 1));
304306
ssize_t offset = (ssize_t)(address & (pageSize - 1));
305307
ssize_t bytesLeft = (ssize_t)cbRequestSize;

src/coreclr/gc/unix/gcenv.unix.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ uint64_t GetAvailablePhysicalMemory()
10841084
sz = sizeof(free_count);
10851085
sysctlbyname("vm.stats.vm.v_free_count", &free_count, &sz, NULL, 0);
10861086

1087-
available = (inactive_count + laundry_count + free_count) * sysconf(_SC_PAGESIZE);
1087+
available = (inactive_count + laundry_count + free_count) * minipal_getpagesize();
10881088
#elif defined(__HAIKU__)
10891089
system_info info;
10901090
if (get_system_info(&info) == B_OK)
@@ -1140,7 +1140,7 @@ uint64_t GetAvailablePageFile()
11401140
rc = sysctlnametomib("vm.swap_info", mib, &length);
11411141
if (rc == 0)
11421142
{
1143-
int pagesize = getpagesize();
1143+
uint32_t pagesize = minipal_getpagesize();
11441144
// Aggregate the information for all swap files on the system
11451145
for (mib[2] = 0; ; mib[2]++)
11461146
{
@@ -1161,7 +1161,7 @@ uint64_t GetAvailablePageFile()
11611161
struct anoninfo ai;
11621162
if (swapctl(SC_AINFO, &ai) != -1)
11631163
{
1164-
int pagesize = getpagesize();
1164+
uint32_t pagesize = minipal_getpagesize();
11651165
available = ai.ani_free * pagesize;
11661166
}
11671167
#elif HAVE_SYSINFO

src/coreclr/inc/loaderheap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ struct LoaderHeapEvent;
160160
inline UINT32 GetStubCodePageSize()
161161
{
162162
#if (defined(TARGET_ARM64) && defined(TARGET_UNIX)) || defined(TARGET_WASM)
163-
return max(16*1024u, GetOsPageSize());
163+
return max(16*1024u, minipal_getpagesize());
164164
#elif defined(TARGET_ARM)
165165
return 4096; // ARM is special as the 32bit instruction set does not easily permit a 16KB offset
166166
#else

src/coreclr/inc/pedecoder.inl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ inline PEDecoder::PEDecoder(PTR_VOID mappedBase, bool fixedUp /*= FALSE*/)
109109
CONTRACTL_END;
110110

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

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

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

187187
m_pNTHeaders = FindNTHeaders();
188188
if (!m_pNTHeaders)

src/coreclr/inc/utilcode.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ using std::nothrow;
3838
#include <stddef.h>
3939
#include <minipal/guid.h>
4040
#include <minipal/log.h>
41+
#include <minipal/ospagesize.h>
4142
#include <dn-u16.h>
4243

4344
#include "clrnt.h"
@@ -577,8 +578,6 @@ int GetTotalProcessorCount();
577578
//******************************************************************************
578579
int GetCurrentProcessCpuCount();
579580

580-
uint32_t GetOsPageSize();
581-
582581

583582
//*****************************************************************************
584583
// Return != 0 if the bit at the specified index in the array is on and 0 if

src/coreclr/pal/src/exception/machexception.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ SET_DEFAULT_DEBUG_CHANNEL(EXCEPT); // some headers have code with asserts, so do
3232

3333
#include <minipal/debugger.h>
3434
#include <minipal/utils.h>
35+
#include <minipal/ospagesize.h>
3536

3637
#include "machmessage.h"
3738

@@ -751,7 +752,7 @@ HijackFaultingThread(
751752
if (exceptionRecord.ExceptionCode == EXCEPTION_ACCESS_VIOLATION)
752753
{
753754
// Calculate the page base addresses for the fault and the faulting thread's SP.
754-
int cbPage = getpagesize();
755+
int cbPage = minipal_getpagesize();
755756
char *pFaultPage = (char*)(exceptionRecord.ExceptionInformation[1] & ~(cbPage - 1));
756757
char *pStackTopPage = (char*)((size_t)targetSP & ~(cbPage - 1));
757758

src/coreclr/pal/tests/palsuite/miscellaneous/IsBadWritePtr/test2/test2.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
**=========================================================*/
1616

1717
#include <palsuite.h>
18+
#include <minipal/ospagesize.h>
1819

1920
PALTEST(miscellaneous_IsBadWritePtr_test2_paltest_isbadwriteptr_test2, "miscellaneous/IsBadWritePtr/test2/paltest_isbadwriteptr_test2")
2021
{
@@ -31,7 +32,7 @@ PALTEST(miscellaneous_IsBadWritePtr_test2_paltest_isbadwriteptr_test2, "miscella
3132
*/
3233

3334
PageOne = VirtualAlloc(NULL,
34-
GetOsPageSize()*4,
35+
minipal_getpagesize()*4,
3536
MEM_RESERVE,
3637
PAGE_NOACCESS);
3738

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

4546
PageOne = VirtualAlloc(PageOne,
46-
GetOsPageSize(),
47+
minipal_getpagesize(),
4748
MEM_COMMIT,
4849
PAGE_NOACCESS);
4950

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

5859
/* Set the second Page to PAGE_READWRITE */
5960

60-
PageTwo = VirtualAlloc(((BYTE*)PageOne)+GetOsPageSize(),
61-
GetOsPageSize(),
61+
PageTwo = VirtualAlloc(((BYTE*)PageOne)+minipal_getpagesize(),
62+
minipal_getpagesize(),
6263
MEM_COMMIT,
6364
PAGE_READWRITE);
6465
if(PageTwo == NULL)
@@ -71,8 +72,8 @@ PALTEST(miscellaneous_IsBadWritePtr_test2_paltest_isbadwriteptr_test2, "miscella
7172

7273
/* Set the third Page to PAGE_NOACCESS */
7374

74-
PageThree = VirtualAlloc(((BYTE*)PageTwo) + (2 * GetOsPageSize()),
75-
GetOsPageSize(),
75+
PageThree = VirtualAlloc(((BYTE*)PageTwo) + (2 * minipal_getpagesize()),
76+
minipal_getpagesize(),
7677
MEM_COMMIT,
7778
PAGE_NOACCESS);
7879

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

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

90-
if(IsBadWritePtr(PageThree,GetOsPageSize()) == 0)
91+
if(IsBadWritePtr(PageThree,minipal_getpagesize()) == 0)
9192
{
9293
VirtualFree(PageOne,0,MEM_RELEASE);
9394

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

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

101-
if(IsBadWritePtr(PageTwo,GetOsPageSize()) != 0)
102+
if(IsBadWritePtr(PageTwo,minipal_getpagesize()) != 0)
102103
{
103104
VirtualFree(PageOne,0,MEM_RELEASE);
104105

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

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

111-
if(IsBadWritePtr(PageThree,GetOsPageSize()) == 0)
112+
if(IsBadWritePtr(PageThree,minipal_getpagesize()) == 0)
112113
{
113114
VirtualFree(PageOne,0,MEM_RELEASE);
114115

0 commit comments

Comments
 (0)