diff --git a/compiler-rt/lib/fuzzer/FuzzerTracePC.cpp b/compiler-rt/lib/fuzzer/FuzzerTracePC.cpp --- a/compiler-rt/lib/fuzzer/FuzzerTracePC.cpp +++ b/compiler-rt/lib/fuzzer/FuzzerTracePC.cpp @@ -46,8 +46,9 @@ auto &M = Modules[NumModules++]; uint8_t *AlignedStart = RoundUpByPage(Start); uint8_t *AlignedStop = RoundDownByPage(Stop); - size_t NumFullPages = AlignedStop > AlignedStart ? - (AlignedStop - AlignedStart) / PageSize() : 0; + size_t NumFullPages = AlignedStop > AlignedStart + ? (AlignedStop - AlignedStart) / GetPageSizeCached() + : 0; bool NeedFirst = Start < AlignedStart || !NumFullPages; bool NeedLast = Stop > AlignedStop && AlignedStop >= AlignedStart; M.NumRegions = NumFullPages + NeedFirst + NeedLast;; @@ -57,8 +58,8 @@ size_t R = 0; if (NeedFirst) M.Regions[R++] = {Start, std::min(Stop, AlignedStart), true, false}; - for (uint8_t *P = AlignedStart; P < AlignedStop; P += PageSize()) - M.Regions[R++] = {P, P + PageSize(), true, true}; + for (uint8_t *P = AlignedStart; P < AlignedStop; P += GetPageSizeCached()) + M.Regions[R++] = {P, P + GetPageSizeCached(), true, true}; if (NeedLast) M.Regions[R++] = {AlignedStop, Stop, true, false}; assert(R == M.NumRegions); diff --git a/compiler-rt/lib/fuzzer/FuzzerUtil.h b/compiler-rt/lib/fuzzer/FuzzerUtil.h --- a/compiler-rt/lib/fuzzer/FuzzerUtil.h +++ b/compiler-rt/lib/fuzzer/FuzzerUtil.h @@ -15,6 +15,7 @@ #include "FuzzerBuiltinsMsvc.h" #include "FuzzerCommand.h" #include "FuzzerDefs.h" +#include namespace fuzzer { @@ -94,16 +95,22 @@ return static_cast((sizeof(unsigned long long) * 8) - Clzll(X) - 1); } -inline size_t PageSize() { return 4096; } +inline size_t PageSizeCached; +inline size_t GetPageSizeCached() { + if (!PageSizeCached) + PageSizeCached = getauxval(AT_PAGESZ); + return PageSizeCached; +} + inline uint8_t *RoundUpByPage(uint8_t *P) { uintptr_t X = reinterpret_cast(P); - size_t Mask = PageSize() - 1; + size_t Mask = GetPageSizeCached() - 1; X = (X + Mask) & ~Mask; return reinterpret_cast(X); } inline uint8_t *RoundDownByPage(uint8_t *P) { uintptr_t X = reinterpret_cast(P); - size_t Mask = PageSize() - 1; + size_t Mask = GetPageSizeCached() - 1; X = X & ~Mask; return reinterpret_cast(X); }