Use kPageSize instead of PAGE_SIZE
Arm64 musl libc doesn't define PAGE_SIZE because it is not guaranteed
to be constant across arm64 kernels; it could be 4Kb, 16Kb or 64Kb.
Use kPageSize instead, which is currently hardcoded to 4096 but is
at least checked against sysconf(_SC_PAGE_SIZE). Support for non-4K
pages later will require kPageSize to be initialized at runtime.
Bug: 236052820
Test: libartbase builds with linux musl arm64
Change-Id: Ib2c398398ad6aa12ee68e52c94ece7b7803f3013
diff --git a/libartbase/base/safe_copy.cc b/libartbase/base/safe_copy.cc
index ad75aa7..7b0b895 100644
--- a/libartbase/base/safe_copy.cc
+++ b/libartbase/base/safe_copy.cc
@@ -56,10 +56,10 @@
}
src_iovs[iovecs_used].iov_base = const_cast<char*>(cur);
- if (!IsAlignedParam(cur, PAGE_SIZE)) {
- src_iovs[iovecs_used].iov_len = AlignUp(cur, PAGE_SIZE) - cur;
+ if (!IsAlignedParam(cur, kPageSize)) {
+ src_iovs[iovecs_used].iov_len = AlignUp(cur, kPageSize) - cur;
} else {
- src_iovs[iovecs_used].iov_len = PAGE_SIZE;
+ src_iovs[iovecs_used].iov_len = kPageSize;
}
src_iovs[iovecs_used].iov_len = std::min(src_iovs[iovecs_used].iov_len, len);
diff --git a/libartbase/base/safe_copy_test.cc b/libartbase/base/safe_copy_test.cc
index 9f7d409..01ed7cd 100644
--- a/libartbase/base/safe_copy_test.cc
+++ b/libartbase/base/safe_copy_test.cc
@@ -31,7 +31,7 @@
#if defined(__linux__)
TEST(SafeCopyTest, smoke) {
- DCHECK_EQ(kPageSize, static_cast<decltype(kPageSize)>(PAGE_SIZE));
+ DCHECK_EQ(kPageSize, static_cast<size_t>(sysconf(_SC_PAGE_SIZE)));
// Map four pages, mark the second one as PROT_NONE, unmap the last one.
void* map = mmap(nullptr, kPageSize * 4, PROT_READ | PROT_WRITE,
@@ -79,7 +79,7 @@
}
TEST(SafeCopyTest, alignment) {
- DCHECK_EQ(kPageSize, static_cast<decltype(kPageSize)>(PAGE_SIZE));
+ DCHECK_EQ(kPageSize, static_cast<size_t>(sysconf(_SC_PAGE_SIZE)));
// Copy the middle of a mapping to the end of another one.
void* src_map = mmap(nullptr, kPageSize * 3, PROT_READ | PROT_WRITE,