#ifndef V8_BASE_SANITIZER_ASAN_H_
#define V8_BASE_SANITIZER_ASAN_H_
#include <type_traits>
#include "src/base/macros.h"
#ifdef V8_USE_ADDRESS_SANITIZER
#include <sanitizer/asan_interface.h>
#if !defined(ASAN_POISON_MEMORY_REGION) || !defined(ASAN_UNPOISON_MEMORY_REGION)
#error \
"ASAN_POISON_MEMORY_REGION and ASAN_UNPOISON_MEMORY_REGION must be defined"
#endif
#define DISABLE_ASAN …
#define ASAN_CHECK_WHOLE_MEMORY_REGION_IS_POISONED …
class AsanUnpoisonScope final {
public:
AsanUnpoisonScope(const void* addr, size_t size)
: addr_(addr),
size_(size),
was_poisoned_(
__asan_region_is_poisoned(const_cast<void*>(addr_), size_)) {
if (was_poisoned_) {
ASAN_UNPOISON_MEMORY_REGION(addr_, size_);
}
}
~AsanUnpoisonScope() {
if (was_poisoned_) {
ASAN_POISON_MEMORY_REGION(addr_, size_);
}
}
private:
const void* addr_;
size_t size_;
bool was_poisoned_;
};
#else
#define DISABLE_ASAN
#define ASAN_POISON_MEMORY_REGION(start, size) …
#define ASAN_UNPOISON_MEMORY_REGION(start, size) …
#define ASAN_CHECK_WHOLE_MEMORY_REGION_IS_POISONED(start, size) …
class AsanUnpoisonScope final { … };
#endif
#ifdef V8_USE_HWADDRESS_SANITIZER
#define DISABLE_HWASAN …
#else
#define DISABLE_HWASAN
#endif
#endif