[compiler-rt] [sanitizer] Add MemCpyAccessible (PR #112794)

Florian Mayer via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 17 17:14:03 PDT 2024


================
@@ -127,6 +127,43 @@ TEST(SanitizerCommon, TryMemCpyNull) {
   EXPECT_FALSE(TryMemCpy(dst.data(), nullptr, dst.size()));
 }
 
+TEST(SanitizerCommon, MemCpyAccessible) {
+  const int page_num = 1000;
+  const int page_size = GetPageSize();
+  InternalMmapVector<char> src(page_num * page_size);
+  std::iota(src.begin(), src.end(), 123);
+  std::vector<char> dst;
+  std::vector<char> exp = {src.begin(), src.end()};
+
+  // Protect some pages.
+  for (int i = 7; i < page_num; i *= 2) {
+    mprotect(src.data() + i * page_size, page_size, PROT_NONE);
+    std::fill(exp.data() + i * page_size, exp.data() + (i + 1) * page_size, 0);
+  }
+
+  dst.assign(src.size(), 0);
----------------
fmayer wrote:

nit '\0'

https://github.com/llvm/llvm-project/pull/112794


More information about the llvm-commits mailing list