From cb5e7a8fd74a03db90903600c09bca16c06e57fe Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Tue, 13 Oct 2026 13:32:15 +0200 Subject: [PATCH] deps: V8: cherry-pick 011b2de3051a Original commit message: [sandbox] fix dispatch table access on illumos illumos pointers are VA48, can allocate from the top of the 64-bit range as well. Co-Authored-By: Dan McDonald Refs: https://github.com/nodejs/node/pull/65161 Change-Id: I7d803ca0da2ab6c7cc206cb964d63683523a13da Refs: https://github.com/v8/v8/commit/011b2de3051afad5f0adb7b9dfedffa888c0a07b Signed-off-by: Chengzhong Wu PR-URL: https://github.com/nodejs/node/pull/67070 Reviewed-By: Yagiz Nizipli Reviewed-By: Richard Lau Reviewed-By: Joyee Cheung --- common.gypi | 2 +- deps/v8/src/codegen/code-stub-assembler.cc | 15 +++++++++++++-- deps/v8/src/sandbox/js-dispatch-table-inl.h | 16 ++++++++++++++++ deps/v8/src/sandbox/js-dispatch-table.h | 15 +++++++++++++++ 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/common.gypi b/common.gypi index f10b26fa0e0..7c9305aa2d9 100644 --- a/common.gypi +++ b/common.gypi @@ -50,7 +50,7 @@ # Reset this number to 0 on major V8 upgrades. # Increment by one for each non-official patch applied to deps/v8. - 'v8_embedder_string': '-node.0', + 'v8_embedder_string': '-node.1', ##### V8 defaults for Node.js ##### diff --git a/deps/v8/src/codegen/code-stub-assembler.cc b/deps/v8/src/codegen/code-stub-assembler.cc index 3ca3a3a0c1c..01583c64141 100644 --- a/deps/v8/src/codegen/code-stub-assembler.cc +++ b/deps/v8/src/codegen/code-stub-assembler.cc @@ -2216,8 +2216,19 @@ TNode CodeStubAssembler::LoadCodeObjectFromJSDispatchTable( TNode shifted_value; if (JSDispatchEntry::kObjectPointerOffset == 0) { - shifted_value = WordShr( - value, UniqueUintPtrConstant(JSDispatchEntry::kObjectPointerShift)); + shifted_value = +#if defined(__illumos__) && defined(V8_HOST_ARCH_64_BIT) + // Pointers in illumos span both the low 2^47 range and the high 2^47 + // range as well. Checking the high bit being set in illumos means all + // higher bits need to be set to 1 after shifting right. Use WordSar() + // so any high-bit check wouldn't be necessary. + UncheckedCast(WordSar( + UncheckedCast(value), + UniqueIntPtrConstant(JSDispatchEntry::kObjectPointerShift))); +#else + WordShr(value, + UniqueUintPtrConstant(JSDispatchEntry::kObjectPointerShift)); +#endif /* __illumos__ and 64-bit */ } else { shifted_value = UintPtrAdd( WordShr(value, diff --git a/deps/v8/src/sandbox/js-dispatch-table-inl.h b/deps/v8/src/sandbox/js-dispatch-table-inl.h index c43dd402967..00295fa38cb 100644 --- a/deps/v8/src/sandbox/js-dispatch-table-inl.h +++ b/deps/v8/src/sandbox/js-dispatch-table-inl.h @@ -33,6 +33,7 @@ void JSDispatchEntry::MakeJSDispatchEntry(Address object, Address entrypoint, DCHECK_EQ(parameter_count & ~kParameterCountMask, 0); Address payload = parameter_count; #else // !(V8_TARGET_ARCH_X64 && V8_SUPPORT_LA57) +#if !defined(__illumos__) || !defined(V8_TARGET_ARCH_64_BIT) DCHECK_EQ((((object - kObjectPointerOffset) << kObjectPointerShift) >> kObjectPointerShift) + kObjectPointerOffset, @@ -40,6 +41,7 @@ void JSDispatchEntry::MakeJSDispatchEntry(Address object, Address entrypoint, DCHECK_EQ((object - kObjectPointerOffset) + kObjectPointerOffset, object); DCHECK_LT((object - kObjectPointerOffset), 1ULL << ((sizeof(encoded_word_) * 8) - kObjectPointerShift)); +#endif /* __illumos__ & 64-bit */ Address payload = ((object - kObjectPointerOffset) << kObjectPointerShift) | (parameter_count & kParameterCountMask); @@ -74,8 +76,17 @@ Address JSDispatchEntry::GetCodePointer() const { // and so may be 0 or 1 here. As the return value is a tagged pointer, the // bit must be 1 when returned, so we need to set it here. Address payload = encoded_word_.load(std::memory_order_acquire); +#if defined(__illumos__) && defined(V8_TARGET_ARCH_64_BIT) + // Unsigned types won't sign-extend on shift-right, but we need to do + // this with illumos VA48 addressing. + DCHECK_EQ(kObjectPointerOffset, 0); + return (Address)(static_cast(payload) >> + static_cast(kObjectPointerShift)) | + kHeapObjectTag; +#else return ((payload >> kObjectPointerShift) + kObjectPointerOffset) | kHeapObjectTag; +#endif /* __illumos__ & 64-bit */ #endif // V8_TARGET_ARCH_X64 && V8_SUPPORT_LA57 } @@ -292,7 +303,12 @@ void JSDispatchEntry::MakeFreelistEntry(uint32_t next_entry_index) { #ifdef V8_TARGET_ARCH_64_BIT bool JSDispatchEntry::IsFreelistEntry(Address entrypoint) const { +#ifdef __illumos__ + // See the illumos definition of kFreeEntryTag for why we have to do this. + return (entrypoint & 0xffff000000000000ull) == kFreeEntryTag; +#else return (entrypoint & kFreeEntryTag) == kFreeEntryTag; +#endif /* __illumos__ */ } #endif diff --git a/deps/v8/src/sandbox/js-dispatch-table.h b/deps/v8/src/sandbox/js-dispatch-table.h index ee58c6b4367..270c2efa13e 100644 --- a/deps/v8/src/sandbox/js-dispatch-table.h +++ b/deps/v8/src/sandbox/js-dispatch-table.h @@ -106,7 +106,22 @@ struct JSDispatchEntry { static constexpr uintptr_t kParameterCountOffset = 2 * kSystemPointerSize; static constexpr uint32_t kObjectPointerShift = 0; #else // !(V8_TARGET_ARCH_X64 && V8_SUPPORT_LA57) +#ifdef __illumos__ + // In illumos 64-bit apps, pointers are allocated both the bottom 2^47 range + // AND the top 2^47 range in the 64-bit space. Instead of 47 bits of VA space + // we have 48 bits. This means, however, the top 16-bits may be 0xffff. We + // therefore pick a different value for the kFreeEntryTag. If/when we go to + // VA57, aka 5-level paging, we'll need to revisit this again, as will node + // by default, since the fixed-bits on the high end will shrink from top + // 16-bits to top 8-bits. + // + // Unless illumos ships an Oracle-Solaris-like VA47 link-time options to + // restrict pointers from allocating from above the Virtual Address hole, + // we need to be mindful of this. + static constexpr Address kFreeEntryTag = 0xfeed000000000000ull; +#else static constexpr Address kFreeEntryTag = 0xffff000000000000ull; +#endif /* __illumos__ */ #ifdef V8_TARGET_BIG_ENDIAN // 2-byte parameter count is on the least significant side of encoded_word_. static constexpr int kBigEndianParamCountOffset =