[compiler-rt] a2b677e - [fuzzer] Don't hard-code page size in FuzzerUtil.h
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Thu May 25 16:35:20 PDT 2023
Author: zhanglimin
Date: 2023-05-25T16:35:08-07:00
New Revision: a2b677e8153758997a9043360cf51333eecc3c44
URL: https://github.com/llvm/llvm-project/commit/a2b677e8153758997a9043360cf51333eecc3c44
DIFF: https://github.com/llvm/llvm-project/commit/a2b677e8153758997a9043360cf51333eecc3c44.diff
LOG: [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
Added:
Modified:
compiler-rt/lib/fuzzer/FuzzerUtil.cpp
compiler-rt/lib/fuzzer/FuzzerUtil.h
Removed:
################################################################################
diff --git a/compiler-rt/lib/fuzzer/FuzzerUtil.cpp b/compiler-rt/lib/fuzzer/FuzzerUtil.cpp
index aeab70f20c28e..4872463bc5c29 100644
--- a/compiler-rt/lib/fuzzer/FuzzerUtil.cpp
+++ b/compiler-rt/lib/fuzzer/FuzzerUtil.cpp
@@ -19,6 +19,7 @@
#include <signal.h>
#include <sstream>
#include <stdio.h>
+#include <sys/auxv.h>
#include <sys/types.h>
#include <thread>
@@ -234,4 +235,9 @@ uint64_t SimpleFastHash(const void *Data, size_t Size, uint64_t Initial) {
return Res;
}
+size_t PageSize() {
+ static size_t PageSizeCached = getauxval(AT_PAGESZ);
+ return PageSizeCached;
+}
+
} // namespace fuzzer
diff --git a/compiler-rt/lib/fuzzer/FuzzerUtil.h b/compiler-rt/lib/fuzzer/FuzzerUtil.h
index 71d49097e559a..5296e7784b3f5 100644
--- a/compiler-rt/lib/fuzzer/FuzzerUtil.h
+++ b/compiler-rt/lib/fuzzer/FuzzerUtil.h
@@ -94,7 +94,8 @@ inline size_t Log(size_t X) {
return static_cast<size_t>((sizeof(unsigned long long) * 8) - Clzll(X) - 1);
}
-inline size_t PageSize() { return 4096; }
+size_t PageSize();
+
inline uint8_t *RoundUpByPage(uint8_t *P) {
uintptr_t X = reinterpret_cast<uintptr_t>(P);
size_t Mask = PageSize() - 1;
More information about the llvm-commits
mailing list