[compiler-rt] baa1488 - [fuzzer] Don't hard-code page size in FuzzerUtil.h
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Thu May 25 20:24:36 PDT 2023
Author: zhanglimin
Date: 2023-05-25T20:24:24-07:00
New Revision: baa1488c169391deb6cc7d6a29ba7f40d0a2086f
URL: https://github.com/llvm/llvm-project/commit/baa1488c169391deb6cc7d6a29ba7f40d0a2086f
DIFF: https://github.com/llvm/llvm-project/commit/baa1488c169391deb6cc7d6a29ba7f40d0a2086f.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..71c3dc1ce7afd 100644
--- a/compiler-rt/lib/fuzzer/FuzzerUtil.cpp
+++ b/compiler-rt/lib/fuzzer/FuzzerUtil.cpp
@@ -21,6 +21,7 @@
#include <stdio.h>
#include <sys/types.h>
#include <thread>
+#include <unistd.h>
namespace fuzzer {
@@ -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 = sysconf(_SC_PAGESIZE);
+ 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