1 // Copyright 2021 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_HEAP_CPPGC_OBJECT_POISONER_H_ 6 #define V8_HEAP_CPPGC_OBJECT_POISONER_H_ 7 8 #include "src/base/sanitizer/asan.h" 9 #include "src/heap/cppgc/heap-object-header.h" 10 #include "src/heap/cppgc/heap-page.h" 11 #include "src/heap/cppgc/heap-visitor.h" 12 #include "src/heap/cppgc/object-view.h" 13 14 namespace cppgc { 15 namespace internal { 16 17 #ifdef V8_USE_ADDRESS_SANITIZER 18 19 // Poisons the payload of unmarked objects. 20 class UnmarkedObjectsPoisoner : public HeapVisitor<UnmarkedObjectsPoisoner> { 21 friend class HeapVisitor<UnmarkedObjectsPoisoner>; 22 23 private: VisitHeapObjectHeader(HeapObjectHeader& header)24 bool VisitHeapObjectHeader(HeapObjectHeader& header) { 25 if (header.IsFree() || header.IsMarked()) return true; 26 27 ASAN_POISON_MEMORY_REGION(header.ObjectStart(), 28 ObjectView<>(header).Size()); 29 return true; 30 } 31 }; 32 33 #endif // V8_USE_ADDRESS_SANITIZER 34 35 } // namespace internal 36 } // namespace cppgc 37 38 #endif // V8_HEAP_CPPGC_OBJECT_POISONER_H_ 39