Commit ae18e6cd authored by heimbuef's avatar heimbuef Committed by Commit bot

Fixed zapping of contents

BUG=

Review-Url: https://codereview.chromium.org/2377943003
Cr-Commit-Position: refs/heads/master@{#39946}
parent a87f0cfa
...@@ -1706,6 +1706,7 @@ v8_source_set("v8_base") { ...@@ -1706,6 +1706,7 @@ v8_source_set("v8_base") {
"src/zone/zone-allocator.h", "src/zone/zone-allocator.h",
"src/zone/zone-allocator.h", "src/zone/zone-allocator.h",
"src/zone/zone-containers.h", "src/zone/zone-containers.h",
"src/zone/zone-segment.cc",
"src/zone/zone-segment.h", "src/zone/zone-segment.h",
"src/zone/zone.cc", "src/zone/zone.cc",
"src/zone/zone.h", "src/zone/zone.h",
......
...@@ -1273,6 +1273,7 @@ ...@@ -1273,6 +1273,7 @@
'wasm/wasm-result.h', 'wasm/wasm-result.h',
'zone/accounting-allocator.cc', 'zone/accounting-allocator.cc',
'zone/accounting-allocator.h', 'zone/accounting-allocator.h',
'zone/zone-segment.cc',
'zone/zone-segment.h', 'zone/zone-segment.h',
'zone/zone.cc', 'zone/zone.cc',
'zone/zone.h', 'zone/zone.h',
......
...@@ -29,6 +29,7 @@ Segment* AccountingAllocator::AllocateSegment(size_t bytes) { ...@@ -29,6 +29,7 @@ Segment* AccountingAllocator::AllocateSegment(size_t bytes) {
void AccountingAllocator::FreeSegment(Segment* memory) { void AccountingAllocator::FreeSegment(Segment* memory) {
base::NoBarrier_AtomicIncrement( base::NoBarrier_AtomicIncrement(
&current_memory_usage_, -static_cast<base::AtomicWord>(memory->size())); &current_memory_usage_, -static_cast<base::AtomicWord>(memory->size()));
memory->ZapHeader();
free(memory); free(memory);
} }
......
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/zone/zone-segment.h"
namespace v8 {
namespace internal {
void Segment::ZapContents() {
#ifdef DEBUG
memset(start(), kZapDeadByte, capacity());
#endif
}
void Segment::ZapHeader() {
#ifdef DEBUG
memset(this, kZapDeadByte, sizeof(Segment));
#endif
}
} // namespace internal
} // namespace v8
...@@ -38,7 +38,16 @@ class Segment { ...@@ -38,7 +38,16 @@ class Segment {
Address start() const { return address(sizeof(Segment)); } Address start() const { return address(sizeof(Segment)); }
Address end() const { return address(size_); } Address end() const { return address(size_); }
// Zap the contents of the segment (but not the header).
void ZapContents();
// Zaps the header and makes the segment unusable this way.
void ZapHeader();
private: private:
#ifdef DEBUG
// Constant byte value used for zapping dead memory in debug mode.
static const unsigned char kZapDeadByte = 0xcd;
#endif
// Computes the address of the nth byte in this segment. // Computes the address of the nth byte in this segment.
Address address(size_t n) const { return Address(this) + n; } Address address(size_t n) const { return Address(this) + n; }
......
...@@ -92,11 +92,6 @@ void* Zone::New(size_t size) { ...@@ -92,11 +92,6 @@ void* Zone::New(size_t size) {
} }
void Zone::DeleteAll() { void Zone::DeleteAll() {
#ifdef DEBUG
// Constant byte value used for zapping dead memory in debug mode.
static const unsigned char kZapDeadByte = 0xcd;
#endif
// Find a segment with a suitable size to keep around. // Find a segment with a suitable size to keep around.
Segment* keep = nullptr; Segment* keep = nullptr;
// Traverse the chained list of segments, zapping (in debug mode) // Traverse the chained list of segments, zapping (in debug mode)
...@@ -112,9 +107,8 @@ void Zone::DeleteAll() { ...@@ -112,9 +107,8 @@ void Zone::DeleteAll() {
#ifdef DEBUG #ifdef DEBUG
// Un-poison first so the zapping doesn't trigger ASan complaints. // Un-poison first so the zapping doesn't trigger ASan complaints.
ASAN_UNPOISON_MEMORY_REGION(current, size); ASAN_UNPOISON_MEMORY_REGION(current, size);
// Zap the entire current segment (including the header).
memset(current, kZapDeadByte, size);
#endif #endif
current->ZapContents();
segment_bytes_allocated_ -= size; segment_bytes_allocated_ -= size;
allocator_->FreeSegment(current); allocator_->FreeSegment(current);
} }
...@@ -131,10 +125,7 @@ void Zone::DeleteAll() { ...@@ -131,10 +125,7 @@ void Zone::DeleteAll() {
limit_ = keep->end(); limit_ = keep->end();
// Un-poison so we can re-use the segment later. // Un-poison so we can re-use the segment later.
ASAN_UNPOISON_MEMORY_REGION(start, keep->capacity()); ASAN_UNPOISON_MEMORY_REGION(start, keep->capacity());
#ifdef DEBUG keep->ZapContents();
// Zap the contents of the kept segment (but not the header).
memset(start, kZapDeadByte, keep->capacity());
#endif
} else { } else {
position_ = limit_ = 0; position_ = limit_ = 0;
} }
...@@ -145,20 +136,14 @@ void Zone::DeleteAll() { ...@@ -145,20 +136,14 @@ void Zone::DeleteAll() {
} }
void Zone::DeleteKeptSegment() { void Zone::DeleteKeptSegment() {
#ifdef DEBUG
// Constant byte value used for zapping dead memory in debug mode.
static const unsigned char kZapDeadByte = 0xcd;
#endif
DCHECK(segment_head_ == nullptr || segment_head_->next() == nullptr); DCHECK(segment_head_ == nullptr || segment_head_->next() == nullptr);
if (segment_head_ != nullptr) { if (segment_head_ != nullptr) {
size_t size = segment_head_->size(); size_t size = segment_head_->size();
#ifdef DEBUG #ifdef DEBUG
// Un-poison first so the zapping doesn't trigger ASan complaints. // Un-poison first so the zapping doesn't trigger ASan complaints.
ASAN_UNPOISON_MEMORY_REGION(segment_head_, size); ASAN_UNPOISON_MEMORY_REGION(segment_head_, size);
// Zap the entire kept segment (including the header).
memset(segment_head_, kZapDeadByte, size);
#endif #endif
segment_head_->ZapContents();
segment_bytes_allocated_ -= size; segment_bytes_allocated_ -= size;
allocator_->FreeSegment(segment_head_); allocator_->FreeSegment(segment_head_);
segment_head_ = nullptr; segment_head_ = nullptr;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment