[llvm-branch-commits] [compiler-rt] [sanitizer] Add TryMemCpy (PR #112668)

Vitaly Buka via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Oct 17 15:51:35 PDT 2024


https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/112668

>From 9571c266d478f2cb49a8005b0d19f40b3de72052 Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Thu, 17 Oct 2024 15:47:37 -0700
Subject: [PATCH 1/2] rebase

Created using spr 1.3.4
---
 compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp    | 2 ++
 compiler-rt/lib/sanitizer_common/tests/sanitizer_posix_test.cpp | 1 +
 2 files changed, 3 insertions(+)

diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp
index 6459c64985faab..e1117c1bec33fa 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp
@@ -327,6 +327,8 @@ bool IsAccessibleMemoryRange(uptr beg, uptr size) {
 }
 
 bool TryMemCpy(void *dest, const void *src, uptr n) {
+  if (!n)
+    return true;
   int fds[2];
   CHECK_EQ(0, pipe(fds));
 
diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_posix_test.cpp b/compiler-rt/lib/sanitizer_common/tests/sanitizer_posix_test.cpp
index 9e463796b2c678..03a841a6f438cb 100644
--- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_posix_test.cpp
+++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_posix_test.cpp
@@ -16,6 +16,7 @@
 #  include <pthread.h>
 #  include <sys/mman.h>
 
+#  include <algorithm>
 #  include <numeric>
 
 #  include "gtest/gtest.h"

>From 2f85748304589ba78560fa8bedae42863c14c343 Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Thu, 17 Oct 2024 15:51:24 -0700
Subject: [PATCH 2/2] move test into a different pr

Created using spr 1.3.4
---
 .../tests/sanitizer_posix_test.cpp                | 15 ---------------
 1 file changed, 15 deletions(-)

diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_posix_test.cpp b/compiler-rt/lib/sanitizer_common/tests/sanitizer_posix_test.cpp
index 03a841a6f438cb..658ca60175b3bd 100644
--- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_posix_test.cpp
+++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_posix_test.cpp
@@ -127,21 +127,6 @@ TEST(SanitizerCommon, TryMemCpyNull) {
   EXPECT_FALSE(TryMemCpy(dst.data(), nullptr, dst.size()));
 }
 
-TEST(SanitizerCommon, TryMemCpyProtected) {
-  const int page_size = GetPageSize();
-  InternalMmapVector<char> src(3 * page_size);
-  std::iota(src.begin(), src.end(), 123);
-  std::vector<char> dst;
-  // Protect the middle page.
-  mprotect(src.data() + page_size, page_size, PROT_NONE);
-
-  dst.assign(src.size(), 0);
-  EXPECT_FALSE(TryMemCpy(dst.data(), src.data(), dst.size()));
-
-  mprotect(src.data() + page_size, page_size, PROT_READ | PROT_WRITE);
-  EXPECT_TRUE(std::equal(dst.begin(), dst.end(), src.begin()));
-}
-
 }  // namespace __sanitizer
 
 #endif  // SANITIZER_POSIX



More information about the llvm-branch-commits mailing list