# deprecation_warnings=on
ifeq ($(deprecationwarnings), on)
GYPFLAGS += -Dv8_deprecation_warnings=1
-endif
+endif
+# asan=/path/to/clang++
+ifneq ($(strip $(asan)),)
+ GYPFLAGS += -Dasan=1
+ export CXX="$(asan)"
+ export CXX_host="$(asan)"
+ export LINK="$(asan)"
+ export ASAN_SYMBOLIZER_PATH="$(dir $(asan))llvm-symbolizer"
+endif
+
# arm specific flags.
# arm_version=<number | "default">
ifneq ($(strip $(arm_version)),)
'ldflags': [
'-fsanitize=address',
],
- }
+ 'defines': [
+ 'ADDRESS_SANITIZER',
+ ],
+ },
}],
['OS=="linux" or OS=="freebsd" or OS=="openbsd" or OS=="solaris" \
or OS=="netbsd"', {
#include "zone.h"
+#ifdef ADDRESS_SANITIZER
+ #include <sanitizer/asan_interface.h>
+#else
+ #define ASAN_UNPOISON_MEMORY_REGION(start, size) ((void) 0)
+#endif
+
#include "counters.h"
#include "isolate.h"
#include "utils.h"
namespace internal {
+static const int kASanRedzoneBytes = 24; // Must be a multiple of 8.
+
+
inline void* Zone::New(int size) {
// Round up the requested size to fit the alignment.
size = RoundUp(size, kAlignment);
// Check if the requested size is available without expanding.
Address result = position_;
- if (size > limit_ - position_) {
- result = NewExpand(size);
+ int size_with_redzone =
+#ifdef ADDRESS_SANITIZER
+ size + kASanRedzoneBytes;
+#else
+ size;
+#endif
+
+ if (size_with_redzone > limit_ - position_) {
+ result = NewExpand(size_with_redzone);
} else {
- position_ += size;
+ position_ += size_with_redzone;
}
+#ifdef ADDRESS_SANITIZER
+ Address redzone_position = result + size;
+ ASSERT(redzone_position + kASanRedzoneBytes == position_);
+ ASAN_POISON_MEMORY_REGION(redzone_position, kASanRedzoneBytes);
+#endif
+
// Check that the result has the proper alignment and return it.
ASSERT(IsAddressAligned(result, kAlignment, 0));
allocation_size_ += size;
template <typename T>
T* Zone::NewArray(int length) {
+ CHECK(std::numeric_limits<int>::max() / static_cast<int>(sizeof(T)) > length);
return static_cast<T*>(New(length * sizeof(T)));
}
} else {
int size = current->size();
#ifdef DEBUG
+ // Un-poison first so the zapping doesn't trigger ASan complaints.
+ ASAN_UNPOISON_MEMORY_REGION(current, size);
// Zap the entire current segment (including the header).
memset(current, kZapDeadByte, size);
#endif
Address start = keep->start();
position_ = RoundUp(start, kAlignment);
limit_ = keep->end();
+ // Un-poison so we can re-use the segment later.
+ ASAN_UNPOISON_MEMORY_REGION(start, keep->capacity());
#ifdef DEBUG
// Zap the contents of the kept segment (but not the header).
memset(start, kZapDeadByte, keep->capacity());
if (segment_head_ != NULL) {
int size = segment_head_->size();
#ifdef DEBUG
+ // Un-poison first so the zapping doesn't trigger ASan complaints.
+ ASAN_UNPOISON_MEMORY_REGION(segment_head_, size);
// Zap the entire kept segment (including the header).
memset(segment_head_, kZapDeadByte, size);
#endif
// All pointers returned from New() have this alignment. In addition, if the
// object being allocated has a size that is divisible by 8 then its alignment
- // will be 8.
+ // will be 8. ASan requires 8-byte alignment.
+#ifdef ADDRESS_SANITIZER
+ static const int kAlignment = 8;
+ STATIC_ASSERT(kPointerSize <= 8);
+#else
static const int kAlignment = kPointerSize;
+#endif
// Never allocate segments smaller than this size in bytes.
static const int kMinimumSegmentSize = 8 * KB;