From a9fbe2004d3f1978930fdb837e2e10f4e88b9013 Mon Sep 17 00:00:00 2001 From: Martin Kustermann Date: Tue, 24 Jan 2017 12:47:36 +0100 Subject: [PATCH] VM: Tell lsan about mmap()ed regions used for our heap The mmap()ed pages hold pointers to `VirtualMemory` objects. So we tell lsan that the mmap()ed regions are roots. R=vegorov@google.com Review-Url: https://codereview.chromium.org/2646363005 . --- runtime/platform/address_sanitizer.h | 22 ++++++++++++++++++++++ runtime/tests/vm/vm.status | 4 ++-- runtime/vm/pages.cc | 11 ++++++++++- tests/standalone/standalone.status | 8 -------- 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/runtime/platform/address_sanitizer.h b/runtime/platform/address_sanitizer.h index ec8baf70d1b..bc7359dab31 100644 --- a/runtime/platform/address_sanitizer.h +++ b/runtime/platform/address_sanitizer.h @@ -10,18 +10,40 @@ // Allow the use of ASan (AddressSanitizer). This is needed as ASan needs to be // told about areas where the VM does the equivalent of a long-jump. #if defined(__has_feature) + #if __has_feature(address_sanitizer) extern "C" void __asan_unpoison_memory_region(void*, size_t); +extern "C" void __lsan_register_root_region(const void* p, size_t size); +extern "C" void __lsan_unregister_root_region(const void* p, size_t size); #define ASAN_UNPOISON(ptr, len) __asan_unpoison_memory_region(ptr, len) +#define LSAN_REGISTER_ROOT_REGION(ptr, len) \ + __lsan_register_root_region(ptr, len) +#define LSAN_UNREGISTER_ROOT_REGION(ptr, len) \ + __lsan_unregister_root_region(ptr, len) #else // __has_feature(address_sanitizer) #define ASAN_UNPOISON(ptr, len) \ do { \ } while (false && (ptr) == 0 && (len) == 0) +#define LSAN_REGISTER_ROOT_REGION(ptr, len) \ + do { \ + } while (false && (ptr) == 0 && (len) == 0) +#define LSAN_UNREGISTER_ROOT_REGION(ptr, len) \ + do { \ + } while (false && (ptr) == 0 && (len) == 0) #endif // __has_feature(address_sanitizer) + #else // defined(__has_feature) + #define ASAN_UNPOISON(ptr, len) \ do { \ } while (false && (ptr) == 0 && (len) == 0) +#define LSAN_REGISTER_ROOT_REGION(ptr, len) \ + do { \ + } while (false && (ptr) == 0 && (len) == 0) +#define LSAN_UNREGISTER_ROOT_REGION(ptr, len) \ + do { \ + } while (false && (ptr) == 0 && (len) == 0) + #endif // defined(__has_feature) #endif // RUNTIME_PLATFORM_ADDRESS_SANITIZER_H_ diff --git a/runtime/tests/vm/vm.status b/runtime/tests/vm/vm.status index e9461797a58..db40a4ded72 100644 --- a/runtime/tests/vm/vm.status +++ b/runtime/tests/vm/vm.status @@ -18,8 +18,8 @@ cc/Fail0: Fail cc/Fail1: Fail cc/Fail2: Fail -cc/Dart2JSCompileAll: Crash # Issue 27369 -cc/Dart2JSCompilerStats: Crash # Issue 27369 +cc/Dart2JSCompileAll: Fail, Crash # Issue 27369 +cc/Dart2JSCompilerStats: Fail, Crash # Issue 27369 cc/SNPrint_BadArgs: Skip diff --git a/runtime/vm/pages.cc b/runtime/vm/pages.cc index c8f24daf5f0..287d4cf6a4e 100644 --- a/runtime/vm/pages.cc +++ b/runtime/vm/pages.cc @@ -4,6 +4,7 @@ #include "vm/pages.h" +#include "platform/address_sanitizer.h" #include "platform/assert.h" #include "vm/compiler_stats.h" #include "vm/gc_marker.h" @@ -69,6 +70,9 @@ HeapPage* HeapPage::Initialize(VirtualMemory* memory, PageType type) { result->memory_ = memory; result->next_ = NULL; result->type_ = type; + + LSAN_REGISTER_ROOT_REGION(result, sizeof(*result)); + return result; } @@ -89,9 +93,14 @@ HeapPage* HeapPage::Allocate(intptr_t size_in_words, PageType type) { void HeapPage::Deallocate() { + bool is_embedder_allocated = embedder_allocated(); + + if (!is_embedder_allocated) { + LSAN_UNREGISTER_ROOT_REGION(this, sizeof(*this)); + } + // For a regular heap pages, the memory for this object will become // unavailable after the delete below. - bool is_embedder_allocated = embedder_allocated(); delete memory_; // For a heap page from a snapshot, the HeapPage object lives in the malloc diff --git a/tests/standalone/standalone.status b/tests/standalone/standalone.status index f9d972a95bb..ed52805ff72 100644 --- a/tests/standalone/standalone.status +++ b/tests/standalone/standalone.status @@ -388,12 +388,4 @@ io/socket_info_ipv6_test: SkipByDesign [ $builder_tag == asan && $arch == x64 ] io/process_detached_test: Pass, Slow - -io/stdout_bad_argument_test: Fail # Issue 28353 -io/file_blocking_lock_test: Fail # Issue 28353 - -io/process_sync_test: RuntimeError -io/signals_test: RuntimeError -io/regress_7191_test: RuntimeError io/named_pipe_script_test: RuntimeError -io/http_server_close_response_after_error_test: RuntimeError