Commit 72bd81c0 authored by Dominik Inführ's avatar Dominik Inführ Committed by Commit Bot

[handles] Do not allow handle deref when local heap is parked

When local heap is parked it is not allowed to dereference any handles.
A GC might be relocating objects at that point.

Change-Id: I557682d47f8f0acfe041506833f6b397feb4438b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2289981Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68768}
parent 8b9c2ac3
...@@ -35,20 +35,24 @@ bool HandleBase::IsDereferenceAllowed() const { ...@@ -35,20 +35,24 @@ bool HandleBase::IsDereferenceAllowed() const {
HeapObject heap_object = HeapObject::cast(object); HeapObject heap_object = HeapObject::cast(object);
if (IsReadOnlyHeapObject(heap_object)) return true; if (IsReadOnlyHeapObject(heap_object)) return true;
if (Heap::InOffThreadSpace(heap_object)) return true; if (Heap::InOffThreadSpace(heap_object)) return true;
Isolate* isolate = GetIsolateFromWritableObject(heap_object);
RootIndex root_index;
if (isolate->roots_table().IsRootHandleLocation(location_, &root_index) &&
RootsTable::IsImmortalImmovable(root_index)) {
return true;
}
LocalHeap* local_heap = LocalHeap::Current(); LocalHeap* local_heap = LocalHeap::Current();
if (V8_UNLIKELY(local_heap)) { if (V8_UNLIKELY(local_heap)) {
// Local heap can't access handles when parked
if (!local_heap->IsHandleDereferenceAllowed()) return false;
if (local_heap->ContainsPersistentHandle(location_)) { if (local_heap->ContainsPersistentHandle(location_)) {
// The current thread owns the handle and thus can dereference it. // The current thread owns the handle and thus can dereference it.
return true; return true;
} }
} }
Isolate* isolate = GetIsolateFromWritableObject(heap_object);
RootIndex root_index;
if (isolate->roots_table().IsRootHandleLocation(location_, &root_index) &&
RootsTable::IsImmortalImmovable(root_index)) {
return true;
}
return AllowHandleDereference::IsAllowed(); return AllowHandleDereference::IsAllowed();
} }
#endif #endif
......
...@@ -69,6 +69,11 @@ std::unique_ptr<PersistentHandles> LocalHeap::DetachPersistentHandles() { ...@@ -69,6 +69,11 @@ std::unique_ptr<PersistentHandles> LocalHeap::DetachPersistentHandles() {
bool LocalHeap::ContainsPersistentHandle(Address* location) { bool LocalHeap::ContainsPersistentHandle(Address* location) {
return persistent_handles_ ? persistent_handles_->Contains(location) : false; return persistent_handles_ ? persistent_handles_->Contains(location) : false;
} }
bool LocalHeap::IsHandleDereferenceAllowed() {
DCHECK_EQ(LocalHeap::Current(), this);
return state_ == ThreadState::Running;
}
#endif #endif
bool LocalHeap::IsParked() { bool LocalHeap::IsParked() {
......
...@@ -41,6 +41,7 @@ class V8_EXPORT_PRIVATE LocalHeap { ...@@ -41,6 +41,7 @@ class V8_EXPORT_PRIVATE LocalHeap {
std::unique_ptr<PersistentHandles> DetachPersistentHandles(); std::unique_ptr<PersistentHandles> DetachPersistentHandles();
#ifdef DEBUG #ifdef DEBUG
bool ContainsPersistentHandle(Address* location); bool ContainsPersistentHandle(Address* location);
bool IsHandleDereferenceAllowed();
#endif #endif
bool IsParked(); bool IsParked();
......
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