Commit e8c5de21 authored by Michael Lippautz's avatar Michael Lippautz Committed by V8 LUCI CQ

api: Make sure TracedReference never is a zap value

When checks are enabled, ensure that the global handle zap value never
leaks into user code as it indicates that the garbage collector failed
to keep alive an object.

Bug: chromium:1056170
Change-Id: I4836fe49cd6e443d689068af10276ed99b46eb10
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2972729
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Reviewed-by: 's avatarDominik Inführ <dinfuehr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75330}
parent 00fb203d
......@@ -885,6 +885,8 @@ class TracedReferenceBase {
std::memory_order_relaxed);
}
V8_EXPORT void CheckValue() const;
// val_ points to a GlobalHandles node.
internal::Address* val_ = nullptr;
......@@ -926,8 +928,18 @@ class BasicTracedReference : public TracedReferenceBase {
const_cast<BasicTracedReference<T>&>(*this));
}
T* operator->() const { return reinterpret_cast<T*>(val_); }
T* operator*() const { return reinterpret_cast<T*>(val_); }
T* operator->() const {
#ifdef V8_ENABLE_CHECKS
CheckValue();
#endif // V8_ENABLE_CHECKS
return reinterpret_cast<T*>(val_);
}
T* operator*() const {
#ifdef V8_ENABLE_CHECKS
CheckValue();
#endif // V8_ENABLE_CHECKS
return reinterpret_cast<T*>(val_);
}
private:
enum DestructionMode { kWithDestructor, kWithoutDestructor };
......
......@@ -9998,6 +9998,14 @@ void EmbedderHeapTracer::ResetHandleInNonTracingGC(
UNREACHABLE();
}
void TracedReferenceBase::CheckValue() const {
#ifdef V8_HOST_ARCH_64_BIT
if (!val_) return;
CHECK_NE(internal::kGlobalHandleZapValue, *reinterpret_cast<uint64_t*>(val_));
#endif // V8_HOST_ARCH_64_BIT
}
CFunction::CFunction(const void* address, const CFunctionInfo* type_info)
: address_(address), type_info_(type_info) {
CHECK_NOT_NULL(address_);
......
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