Skip to content

Commit a2b677e

Browse files
Ami-zhangvitalybuka
authored andcommitted
[fuzzer] Don't hard-code page size in FuzzerUtil.h
Don't hard code the page in FuzzerUtil.h, this breaks on e.g. LoongArch which defaults to a 16KiB page size. Reviewed By: #sanitizers, vitalybuka Differential Revision: https://reviews.llvm.org/D140607
1 parent 98aad40 commit a2b677e

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

compiler-rt/lib/fuzzer/FuzzerUtil.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <signal.h>
2020
#include <sstream>
2121
#include <stdio.h>
22+
#include <sys/auxv.h>
2223
#include <sys/types.h>
2324
#include <thread>
2425

@@ -234,4 +235,9 @@ uint64_t SimpleFastHash(const void *Data, size_t Size, uint64_t Initial) {
234235
return Res;
235236
}
236237

238+
size_t PageSize() {
239+
static size_t PageSizeCached = getauxval(AT_PAGESZ);
240+
return PageSizeCached;
241+
}
242+
237243
} // namespace fuzzer

compiler-rt/lib/fuzzer/FuzzerUtil.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ inline size_t Log(size_t X) {
9494
return static_cast<size_t>((sizeof(unsigned long long) * 8) - Clzll(X) - 1);
9595
}
9696

97-
inline size_t PageSize() { return 4096; }
97+
size_t PageSize();
98+
9899
inline uint8_t *RoundUpByPage(uint8_t *P) {
99100
uintptr_t X = reinterpret_cast<uintptr_t>(P);
100101
size_t Mask = PageSize() - 1;

0 commit comments

Comments
 (0)