From a91f6b8433c4dcc7df3b773c00a71f4d122418d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Tue, 3 May 2016 11:27:09 +0200 Subject: [PATCH] deps: backport IsValid changes from 4e8736d in V8 V8 erroneously did null pointer checks on `this`. It can lead to a SIGSEGV crash if node is compiled with GCC 6. Backport relevant changes from [1] that fix this issue. [1]: https://codereview.chromium.org/1900423002 Fixes: https://github.com/nodejs/node/issues/6272 PR-URL: https://github.com/nodejs/node/pull/6544 Reviewed-By: Ben Noordhuis Reviewed-By: Fedor Indutny --- deps/v8/src/heap/incremental-marking.cc | 4 ++-- deps/v8/src/heap/spaces-inl.h | 4 ++-- deps/v8/src/heap/spaces.cc | 2 +- deps/v8/src/heap/spaces.h | 4 ++-- deps/v8/test/cctest/heap/test-spaces.cc | 6 +++--- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/deps/v8/src/heap/incremental-marking.cc b/deps/v8/src/heap/incremental-marking.cc index 376e8488cedf31..46f95cc1810c33 100644 --- a/deps/v8/src/heap/incremental-marking.cc +++ b/deps/v8/src/heap/incremental-marking.cc @@ -366,7 +366,7 @@ void IncrementalMarking::DeactivateIncrementalWriteBarrier() { DeactivateIncrementalWriteBarrierForSpace(heap_->new_space()); LargePage* lop = heap_->lo_space()->first_page(); - while (lop->is_valid()) { + while (LargePage::IsValid(lop)) { SetOldSpacePageFlags(lop, false, false); lop = lop->next_page(); } @@ -398,7 +398,7 @@ void IncrementalMarking::ActivateIncrementalWriteBarrier() { ActivateIncrementalWriteBarrier(heap_->new_space()); LargePage* lop = heap_->lo_space()->first_page(); - while (lop->is_valid()) { + while (LargePage::IsValid(lop)) { SetOldSpacePageFlags(lop, true, is_compacting_); lop = lop->next_page(); } diff --git a/deps/v8/src/heap/spaces-inl.h b/deps/v8/src/heap/spaces-inl.h index 135498f69d180b..c16c9f00a4df39 100644 --- a/deps/v8/src/heap/spaces-inl.h +++ b/deps/v8/src/heap/spaces-inl.h @@ -325,14 +325,14 @@ void MemoryChunk::IncrementLiveBytesFromMutator(HeapObject* object, int by) { bool PagedSpace::Contains(Address addr) { Page* p = Page::FromAddress(addr); - if (!p->is_valid()) return false; + if (!Page::IsValid(p)) return false; return p->owner() == this; } bool PagedSpace::Contains(Object* o) { if (!o->IsHeapObject()) return false; Page* p = Page::FromAddress(HeapObject::cast(o)->address()); - if (!p->is_valid()) return false; + if (!Page::IsValid(p)) return false; return p->owner() == this; } diff --git a/deps/v8/src/heap/spaces.cc b/deps/v8/src/heap/spaces.cc index a0a37523b246a4..8a7fd1a14fa608 100644 --- a/deps/v8/src/heap/spaces.cc +++ b/deps/v8/src/heap/spaces.cc @@ -2977,7 +2977,7 @@ LargePage* LargeObjectSpace::FindPage(Address a) { if (e != NULL) { DCHECK(e->value != NULL); LargePage* page = reinterpret_cast(e->value); - DCHECK(page->is_valid()); + DCHECK(LargePage::IsValid(page)); if (page->Contains(a)) { return page; } diff --git a/deps/v8/src/heap/spaces.h b/deps/v8/src/heap/spaces.h index 93a81cc9333216..49a43dc83d9019 100644 --- a/deps/v8/src/heap/spaces.h +++ b/deps/v8/src/heap/spaces.h @@ -558,9 +558,9 @@ class MemoryChunk { !chunk->high_water_mark_.TrySetValue(old_mark, new_mark)); } - Address address() { return reinterpret_cast
(this); } + static bool IsValid(MemoryChunk* chunk) { return chunk != nullptr; } - bool is_valid() { return address() != NULL; } + Address address() { return reinterpret_cast
(this); } base::Mutex* mutex() { return mutex_; } diff --git a/deps/v8/test/cctest/heap/test-spaces.cc b/deps/v8/test/cctest/heap/test-spaces.cc index a7cf161ca69175..5eb1549e113ffb 100644 --- a/deps/v8/test/cctest/heap/test-spaces.cc +++ b/deps/v8/test/cctest/heap/test-spaces.cc @@ -322,7 +322,7 @@ TEST(MemoryAllocator) { NOT_EXECUTABLE); first_page->InsertAfter(faked_space.anchor()->prev_page()); - CHECK(first_page->is_valid()); + CHECK(Page::IsValid(first_page)); CHECK(first_page->next_page() == faked_space.anchor()); total_pages++; @@ -334,7 +334,7 @@ TEST(MemoryAllocator) { Page* other = memory_allocator->AllocatePage( faked_space.AreaSize(), static_cast(&faked_space), NOT_EXECUTABLE); - CHECK(other->is_valid()); + CHECK(Page::IsValid(other)); total_pages++; other->InsertAfter(first_page); int page_count = 0; @@ -345,7 +345,7 @@ TEST(MemoryAllocator) { CHECK(total_pages == page_count); Page* second_page = first_page->next_page(); - CHECK(second_page->is_valid()); + CHECK(Page::IsValid(second_page)); // OldSpace's destructor will tear down the space and free up all pages. }