Skip to content

Commit 4b23764

Browse files
danmcdtargos
authored andcommitted
deps: patch V8 for illumos
illumos pointers are VA48, can allocate from the top of the 64-bit range as well. PR-URL: nodejs#58070 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Rafael Gonzaga <[email protected]>
1 parent 353ef73 commit 4b23764

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

common.gypi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
# Reset this number to 0 on major V8 upgrades.
4040
# Increment by one for each non-official patch applied to deps/v8.
41-
'v8_embedder_string': '-node.4',
41+
'v8_embedder_string': '-node.5',
4242

4343
##### V8 defaults for Node.js #####
4444

deps/v8/src/codegen/code-stub-assembler.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1985,7 +1985,16 @@ TNode<Code> CodeStubAssembler::LoadCodeObjectFromJSDispatchTable(
19851985
// The LSB is used as marking bit by the js dispatch table, so here we have
19861986
// to set it using a bitwise OR as it may or may not be set.
19871987
value = UncheckedCast<UintPtrT>(WordOr(
1988+
#if defined(__illumos__) && defined(V8_HOST_ARCH_64_BIT)
1989+
// Pointers in illumos span both the low 2^47 range and the high 2^47 range
1990+
// as well. Checking the high bit being set in illumos means all higher bits
1991+
// need to be set to 1 after shifting right.
1992+
// Try WordSar() so any high-bit check wouldn't be necessary.
1993+
WordSar(UncheckedCast<IntPtrT>(value),
1994+
IntPtrConstant(JSDispatchEntry::kObjectPointerShift)),
1995+
#else
19881996
WordShr(value, UintPtrConstant(JSDispatchEntry::kObjectPointerShift)),
1997+
#endif /* __illumos__ */
19891998
UintPtrConstant(kHeapObjectTag)));
19901999
return CAST(BitcastWordToTagged(value));
19912000
}

deps/v8/src/sandbox/js-dispatch-table-inl.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ void JSDispatchEntry::MakeJSDispatchEntry(Address object, Address entrypoint,
2323
uint16_t parameter_count,
2424
bool mark_as_alive) {
2525
DCHECK_EQ(object & kHeapObjectTag, 0);
26+
#if !defined(__illumos__) || !defined(V8_TARGET_ARCH_64_BIT)
2627
DCHECK_EQ((object << kObjectPointerShift) >> kObjectPointerShift, object);
28+
#endif /* __illumos__ */
2729

2830
Address payload =
2931
(object << kObjectPointerShift) | (parameter_count & kParameterCountMask);
@@ -49,7 +51,14 @@ Address JSDispatchEntry::GetCodePointer() const {
4951
// and so may be 0 or 1 here. As the return value is a tagged pointer, the
5052
// bit must be 1 when returned, so we need to set it here.
5153
Address payload = encoded_word_.load(std::memory_order_relaxed);
54+
#if defined(__illumos__) && defined(V8_TARGET_ARCH_64_BIT)
55+
// Unsigned types won't sign-extend on shift-right, but we need to do
56+
// this with illumos VA48 addressing.
57+
return (Address)((intptr_t)payload >> (int)kObjectPointerShift) |
58+
kHeapObjectTag;
59+
#else
5260
return (payload >> kObjectPointerShift) | kHeapObjectTag;
61+
#endif /* __illumos__ */
5362
}
5463

5564
Tagged<Code> JSDispatchEntry::GetCode() const {
@@ -205,7 +214,12 @@ void JSDispatchEntry::MakeFreelistEntry(uint32_t next_entry_index) {
205214
bool JSDispatchEntry::IsFreelistEntry() const {
206215
#ifdef V8_TARGET_ARCH_64_BIT
207216
auto entrypoint = entrypoint_.load(std::memory_order_relaxed);
217+
#ifdef __illumos__
218+
// See the illumos definition of kFreeEntryTag for why we have to do this.
219+
return (entrypoint & 0xffff000000000000ull) == kFreeEntryTag;
220+
#else
208221
return (entrypoint & kFreeEntryTag) == kFreeEntryTag;
222+
#endif /* __illumos__ */
209223
#else
210224
return next_free_entry_.load(std::memory_order_relaxed) != 0;
211225
#endif

deps/v8/src/sandbox/js-dispatch-table.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,22 @@ struct JSDispatchEntry {
7878
#if defined(V8_TARGET_ARCH_64_BIT)
7979
// Freelist entries contain the index of the next free entry in their lower 32
8080
// bits and are tagged with this tag.
81+
#ifdef __illumos__
82+
// In illumos 64-bit apps, pointers are allocated both the bottom 2^47 range
83+
// AND the top 2^47 range in the 64-bit space. Instead of 47 bits of VA space
84+
// we have 48 bits. This means, however, the top 16-bits may be 0xffff. We
85+
// therefore pick a different value for the kFreeEntryTag. If/when we go to
86+
// VA57, aka 5-level paging, we'll need to revisit this again, as will node
87+
// by default, since the fixed-bits on the high end will shrink from top
88+
// 16-bits to top 8-bits.
89+
//
90+
// Unless illumos ships an Oracle-Solaris-like VA47 link-time options to
91+
// restrict pointers from allocating from above the Virtual Address hole,
92+
// we need to be mindful of this.
93+
static constexpr Address kFreeEntryTag = 0xfeed000000000000ull;
94+
#else
8195
static constexpr Address kFreeEntryTag = 0xffff000000000000ull;
96+
#endif /* __illumos__ */
8297
#ifdef V8_TARGET_BIG_ENDIAN
8398
// 2-byte parameter count is on the least significant side of encoded_word_.
8499
static constexpr int kBigEndianParamCountOffset =

0 commit comments

Comments
 (0)