Chromium Code Reviews| Index: src/zone-inl.h |
| diff --git a/src/zone-inl.h b/src/zone-inl.h |
| index f257382a2dba5b118cadb98e83c1da68b58ad27a..faf99e3d1fd88b8545db94b2fb1bfa0b57b6f390 100644 |
| --- a/src/zone-inl.h |
| +++ b/src/zone-inl.h |
| @@ -30,6 +30,10 @@ |
| #include "zone.h" |
| +#ifdef ADDRESS_SANITIZER |
| +#include <sanitizer/asan_interface.h> |
|
kcc1
2014/03/26 06:43:41
A style nit. I would do
#ifdef ADDRESS_SANITIZER
Jakob Kummerow
2014/03/26 09:59:12
Good idea, done for ASAN_UNPOISON_MEMORY_REGION, k
|
| +#endif |
| + |
| #include "counters.h" |
| #include "isolate.h" |
| #include "utils.h" |
| @@ -39,6 +43,9 @@ namespace v8 { |
| 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); |
| @@ -54,12 +61,25 @@ inline void* Zone::New(int size) { |
| // 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; |
| @@ -69,6 +89,7 @@ inline void* Zone::New(int 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))); |
| } |