Restore ADDRESS_SANITIZER blocks to reduce diff with upstream.
#include "arena.h"
+
+#ifdef ADDRESS_SANITIZER
+#include <sanitizer/asan_interface.h>
+#endif
+
namespace google {
namespace protobuf {
@@ -129,6 +134,12 @@ Arena::Block* Arena::NewBlock(void* me, Block* my_last_block, size_t n,
b->pos = kHeaderSize + n;
b->size = size;
b->owner = me;
+#ifdef ADDRESS_SANITIZER
+ // Poison the rest of the block for ASAN. It was unpoisoned by the underlying
+ // malloc but it's not yet usable until we return it as part of an allocation.
+ ASAN_POISON_MEMORY_REGION(
+ reinterpret_cast<char*>(b) + b->pos, b->size - b->pos);
+#endif
return b;
}
@@ -190,6 +201,9 @@ void* Arena::AllocateAligned(const std::type_info* allocated, size_t n) {
void* Arena::AllocFromBlock(Block* b, size_t n) {
size_t p = b->pos;
b->pos = p + n;
+#ifdef ADDRESS_SANITIZER
+ ASAN_UNPOISON_MEMORY_REGION(reinterpret_cast<char*>(b) + p, n);
+#endif return reinterpret_cast<char*>(b) + p;
return reinterpret_cast<char*>(b) + p;
}
