v8/test/unittests/heap/cppgc/sanitizer-unittest.cc
Michael Lippautz c9e82887bd cppgc: Allow ASAN-safe memset in SetMemoryInaccessible()
The application may itself change ASAN poisoning which conflicts with
the memset() right before poisoning memory.

This is relevant for destructors but also when invoking Resize() on an
object that uses ASAN container annotations. Annotations are hard to
adjust for the embedder as it is not clear upfront whether the call will
succeed.

Bug: chromium:1056170
Change-Id: I7f719e4130ba6149494a45f220a341658970bc6f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2878733
Reviewed-by: Omer Katz <omerkatz@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#74431}
2021-05-07 08:14:17 +00:00

60 lines
1.5 KiB
C++

// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "include/cppgc/allocation.h"
#include "src/base/macros.h"
#include "src/base/sanitizer/asan.h"
#include "test/unittests/heap/cppgc/tests.h"
#include "testing/gtest/include/gtest/gtest.h"
#if defined(LEAK_SANITIZER)
#include <sanitizer/lsan_interface.h>
#endif // LEAK_SANITIZER
namespace cppgc {
namespace internal {
#if defined(LEAK_SANITIZER)
using LsanTest = testing::TestWithHeap;
class GCed final : public GarbageCollected<GCed> {
public:
void Trace(cppgc::Visitor*) const {}
std::unique_ptr<int> dummy{std::make_unique<int>(17)};
};
TEST_F(LsanTest, LeakDetectionDoesNotFindMemoryRetainedFromManaged) {
auto* o = MakeGarbageCollected<GCed>(GetAllocationHandle());
__lsan_do_leak_check();
USE(o);
}
#endif // LEAK_SANITIZER
#ifdef V8_USE_ADDRESS_SANITIZER
using AsanTest = testing::TestWithHeap;
class ObjectPoisoningInDestructor final
: public GarbageCollected<ObjectPoisoningInDestructor> {
public:
~ObjectPoisoningInDestructor() {
ASAN_POISON_MEMORY_REGION(this, sizeof(ObjectPoisoningInDestructor));
}
void Trace(cppgc::Visitor*) const {}
void* dummy{0};
};
TEST_F(AsanTest, ObjectPoisoningInDestructor) {
MakeGarbageCollected<ObjectPoisoningInDestructor>(GetAllocationHandle());
PreciseGC();
}
#endif // V8_USE_ADDRESS_SANITIZER
} // namespace internal
} // namespace cppgc