[PATCH] D63830: [ASan] Make FlushUnneededASanShadowMemory a per-platform function

Petr Hosek via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 26 11:04:16 PDT 2019


phosek created this revision.
phosek added reviewers: kcc, eugenis, mcgrathr.
Herald added subscribers: llvm-commits, Sanitizers, kubamracek.
Herald added projects: LLVM, Sanitizers.

Currently, FlushUnneededASanShadowMemory invokes ReleaseMemoryPagesToOS
on all platforms. The latter function is complex and used by other parts
and implementing it on systems like Fuchsia is tricky. However, the
former is fairly straightforward to implement.

This change decouples the two functions and makes
FlushUnneededASanShadowMemory implementation per-platform which allows
implementing this function separately from ReleaseMemoryPagesToOS. On
all systems except for Fuchsia, FlushUnneededASanShadowMemory is still
implemented in terms of ReleaseMemoryPagesToOS so this change should be
NFC.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D63830

Files:
  compiler-rt/lib/asan/asan_fuchsia.cc
  compiler-rt/lib/asan/asan_linux.cc
  compiler-rt/lib/asan/asan_mac.cc
  compiler-rt/lib/asan/asan_poisoning.cc
  compiler-rt/lib/asan/asan_win.cc


Index: compiler-rt/lib/asan/asan_win.cc
===================================================================
--- compiler-rt/lib/asan/asan_win.cc
+++ compiler-rt/lib/asan/asan_win.cc
@@ -370,6 +370,12 @@
 
 WIN_FORCE_LINK(__asan_dso_reg_hook)
 
+void FlushUnneededASanShadowMemory(uptr p, uptr size) {
+  // Since asan's mapping is compacting, the shadow chunk may be
+  // not page-aligned, so we only flush the page-aligned portion.
+  ReleaseMemoryPagesToOS(MemToShadow(p), MemToShadow(p + size));
+}
+
 // }}}
 }  // namespace __asan
 
Index: compiler-rt/lib/asan/asan_poisoning.cc
===================================================================
--- compiler-rt/lib/asan/asan_poisoning.cc
+++ compiler-rt/lib/asan/asan_poisoning.cc
@@ -62,12 +62,6 @@
   }
 };
 
-void FlushUnneededASanShadowMemory(uptr p, uptr size) {
-  // Since asan's mapping is compacting, the shadow chunk may be
-  // not page-aligned, so we only flush the page-aligned portion.
-  ReleaseMemoryPagesToOS(MemToShadow(p), MemToShadow(p + size));
-}
-
 void AsanPoisonOrUnpoisonIntraObjectRedzone(uptr ptr, uptr size, bool poison) {
   uptr end = ptr + size;
   if (Verbosity()) {
Index: compiler-rt/lib/asan/asan_mac.cc
===================================================================
--- compiler-rt/lib/asan/asan_mac.cc
+++ compiler-rt/lib/asan/asan_mac.cc
@@ -203,6 +203,12 @@
   asan_free(context, &stack, FROM_MALLOC);
 }
 
+void FlushUnneededASanShadowMemory(uptr p, uptr size) {
+  // Since asan's mapping is compacting, the shadow chunk may be
+  // not page-aligned, so we only flush the page-aligned portion.
+  ReleaseMemoryPagesToOS(MemToShadow(p), MemToShadow(p + size));
+}
+
 }  // namespace __asan
 
 using namespace __asan;  // NOLINT
Index: compiler-rt/lib/asan/asan_linux.cc
===================================================================
--- compiler-rt/lib/asan/asan_linux.cc
+++ compiler-rt/lib/asan/asan_linux.cc
@@ -254,6 +254,12 @@
   return false;
 }
 
+void FlushUnneededASanShadowMemory(uptr p, uptr size) {
+  // Since asan's mapping is compacting, the shadow chunk may be
+  // not page-aligned, so we only flush the page-aligned portion.
+  ReleaseMemoryPagesToOS(MemToShadow(p), MemToShadow(p + size));
+}
+
 } // namespace __asan
 
 #endif  // SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD ||
Index: compiler-rt/lib/asan/asan_fuchsia.cc
===================================================================
--- compiler-rt/lib/asan/asan_fuchsia.cc
+++ compiler-rt/lib/asan/asan_fuchsia.cc
@@ -196,6 +196,9 @@
   return false;
 }
 
+void FlushUnneededASanShadowMemory(uptr p, uptr size) {
+}
+
 }  // namespace __asan
 
 // These are declared (in extern "C") by <zircon/sanitizer.h>.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63830.206711.patch
Type: text/x-patch
Size: 2711 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190626/9484d681/attachment.bin>


More information about the llvm-commits mailing list