Revision: 20266
Author: [email protected]
Date: Wed Mar 26 10:01:53 2014 UTC
Log: ASan support for the Zone
[email protected], [email protected]
Review URL: https://codereview.chromium.org/208743004
http://code.google.com/p/v8/source/detail?r=20266
Modified:
/branches/bleeding_edge/Makefile
/branches/bleeding_edge/build/standalone.gypi
/branches/bleeding_edge/src/zone-inl.h
/branches/bleeding_edge/src/zone.cc
/branches/bleeding_edge/src/zone.h
=======================================
--- /branches/bleeding_edge/Makefile Tue Mar 25 12:05:33 2014 UTC
+++ /branches/bleeding_edge/Makefile Wed Mar 26 10:01:53 2014 UTC
@@ -136,7 +136,16 @@
# 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)),)
=======================================
--- /branches/bleeding_edge/build/standalone.gypi Fri Mar 21 09:28:26 2014
UTC
+++ /branches/bleeding_edge/build/standalone.gypi Wed Mar 26 10:01:53 2014
UTC
@@ -184,7 +184,10 @@
'ldflags': [
'-fsanitize=address',
],
- }
+ 'defines': [
+ 'ADDRESS_SANITIZER',
+ ],
+ },
}],
['OS=="linux" or OS=="freebsd" or OS=="openbsd" or OS=="solaris" \
or OS=="netbsd"', {
=======================================
--- /branches/bleeding_edge/src/zone-inl.h Tue Aug 6 12:57:23 2013 UTC
+++ /branches/bleeding_edge/src/zone-inl.h Wed Mar 26 10:01:53 2014 UTC
@@ -30,6 +30,12 @@
#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"
@@ -39,6 +45,9 @@
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,11 +63,24 @@
// 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));
@@ -69,6 +91,7 @@
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)));
}
=======================================
--- /branches/bleeding_edge/src/zone.cc Mon Jan 13 13:00:09 2014 UTC
+++ /branches/bleeding_edge/src/zone.cc Wed Mar 26 10:01:53 2014 UTC
@@ -104,6 +104,8 @@
} 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
@@ -120,6 +122,8 @@
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());
@@ -143,6 +147,8 @@
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
=======================================
--- /branches/bleeding_edge/src/zone.h Mon Sep 2 11:39:23 2013 UTC
+++ /branches/bleeding_edge/src/zone.h Wed Mar 26 10:01:53 2014 UTC
@@ -89,8 +89,13 @@
// 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;
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.