Skip to content

Commit 7dc00fa

Browse files
joyeecheungaduh95
authored andcommitted
deps: V8: backport 185f0fe09b72
Original commit message: [numbers] Refactor HashSeed as a lightweight view over ByteArray Instead of copying the seed and secrets into a struct with value fields, HashSeed now stores a pointer pointing either into the read-only ByteArray, or the static default seed for off-heap HashSeed::Default() calls. The underlying storage is always 8-byte aligned so we can cast it directly into a struct. Change-Id: I5896a7f2ae24296eb4c80b757a5d90ac70a34866 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/7609720 Reviewed-by: Leszek Swirski <leszeks@chromium.org> Commit-Queue: Joyee Cheung <joyee@igalia.com> Cr-Commit-Position: refs/heads/main@{#105531} Refs: v8/v8@185f0fe Co-authored-by: Joyee Cheung <joyeec9h3@gmail.com> Backport-PR-URL: nodejs-private/node-private#833 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> PR-URL: nodejs-private/node-private#809 CVE-ID: CVE-2026-21717
1 parent 076acd0 commit 7dc00fa

File tree

16 files changed

+136
-78
lines changed

16 files changed

+136
-78
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.36',
41+
'v8_embedder_string': '-node.37',
4242

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

deps/v8/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1850,6 +1850,7 @@ filegroup(
18501850
"src/numbers/conversions.h",
18511851
"src/numbers/conversions-inl.h",
18521852
"src/numbers/hash-seed.h",
1853+
"src/numbers/hash-seed.cc",
18531854
"src/numbers/hash-seed-inl.h",
18541855
"src/numbers/integer-literal.h",
18551856
"src/numbers/integer-literal-inl.h",

deps/v8/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5450,6 +5450,7 @@ v8_source_set("v8_base_without_compiler") {
54505450
"src/logging/runtime-call-stats.cc",
54515451
"src/logging/tracing-flags.cc",
54525452
"src/numbers/conversions.cc",
5453+
"src/numbers/hash-seed.cc",
54535454
"src/numbers/math-random.cc",
54545455
"src/objects/abstract-code.cc",
54555456
"src/objects/backing-store.cc",

deps/v8/src/DEPS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ specific_include_rules = {
129129
"heap\.cc": [
130130
"+third_party/rapidhash-v8/secret.h",
131131
],
132-
"hash-seed-inl\.h": [
132+
"hash-seed\.cc": [
133133
"+third_party/rapidhash-v8/secret.h",
134134
],
135135
}

deps/v8/src/heap/factory-base.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,9 @@ Handle<WeakFixedArray> FactoryBase<Impl>::NewWeakFixedArray(
272272
}
273273

274274
template <typename Impl>
275-
Handle<ByteArray> FactoryBase<Impl>::NewByteArray(int length,
276-
AllocationType allocation) {
277-
return ByteArray::New(isolate(), length, allocation);
275+
Handle<ByteArray> FactoryBase<Impl>::NewByteArray(
276+
int length, AllocationType allocation, AllocationAlignment alignment) {
277+
return ByteArray::New(isolate(), length, allocation, alignment);
278278
}
279279

280280
template <typename Impl>
@@ -1225,8 +1225,8 @@ FactoryBase<Impl>::AllocateRawTwoByteInternalizedString(
12251225

12261226
template <typename Impl>
12271227
Tagged<HeapObject> FactoryBase<Impl>::AllocateRawArray(
1228-
int size, AllocationType allocation) {
1229-
Tagged<HeapObject> result = AllocateRaw(size, allocation);
1228+
int size, AllocationType allocation, AllocationAlignment alignment) {
1229+
Tagged<HeapObject> result = AllocateRaw(size, allocation, alignment);
12301230
if (!V8_ENABLE_THIRD_PARTY_HEAP_BOOL &&
12311231
(size >
12321232
isolate()->heap()->AsHeap()->MaxRegularHeapObjectSize(allocation)) &&

deps/v8/src/heap/factory-base.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ class FactoryBase : public TorqueGeneratedFactory<Impl> {
181181

182182
// The function returns a pre-allocated empty byte array for length = 0.
183183
Handle<ByteArray> NewByteArray(
184-
int length, AllocationType allocation = AllocationType::kYoung);
184+
int length, AllocationType allocation = AllocationType::kYoung,
185+
AllocationAlignment alignment = kTaggedAligned);
185186

186187
// Allocates a trusted byte array in trusted space, initialized with zeros.
187188
Handle<TrustedByteArray> NewTrustedByteArray(int length);
@@ -374,7 +375,9 @@ class FactoryBase : public TorqueGeneratedFactory<Impl> {
374375
static constexpr int kNumberToStringBufferSize = 32;
375376

376377
// Allocate memory for an uninitialized array (e.g., a FixedArray or similar).
377-
Tagged<HeapObject> AllocateRawArray(int size, AllocationType allocation);
378+
Tagged<HeapObject> AllocateRawArray(
379+
int size, AllocationType allocation,
380+
AllocationAlignment alignment = kTaggedAligned);
378381
Tagged<HeapObject> AllocateRawFixedArray(int length,
379382
AllocationType allocation);
380383
Tagged<HeapObject> AllocateRawWeakArrayList(int length,

deps/v8/src/heap/heap.cc

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@
119119
#include "src/tracing/trace-event.h"
120120
#include "src/utils/utils-inl.h"
121121
#include "src/utils/utils.h"
122-
#include "third_party/rapidhash-v8/secret.h"
123122

124123
#ifdef V8_ENABLE_CONSERVATIVE_STACK_SCANNING
125124
#include "src/heap/conservative-stack-visitor.h"
@@ -5817,31 +5816,6 @@ void Heap::SetUpSpaces(LinearAllocationArea& new_allocation_info,
58175816
}
58185817
}
58195818

5820-
void Heap::InitializeHashSeed() {
5821-
DCHECK(!deserialization_complete_);
5822-
uint64_t new_hash_seed;
5823-
if (v8_flags.hash_seed == 0) {
5824-
int64_t rnd = isolate()->random_number_generator()->NextInt64();
5825-
new_hash_seed = static_cast<uint64_t>(rnd);
5826-
} else {
5827-
new_hash_seed = static_cast<uint64_t>(v8_flags.hash_seed);
5828-
}
5829-
5830-
Tagged<ByteArray> hash_seed = ReadOnlyRoots(this).hash_seed();
5831-
5832-
MemCopy(hash_seed->begin(), reinterpret_cast<uint8_t*>(&new_hash_seed),
5833-
kInt64Size);
5834-
5835-
#if V8_USE_DEFAULT_HASHER_SECRET
5836-
MemCopy(hash_seed->begin() + kInt64Size,
5837-
reinterpret_cast<const uint8_t*>(RAPIDHASH_DEFAULT_SECRET),
5838-
kInt64Size * 3);
5839-
#else
5840-
rapidhash_make_secret(new_hash_seed, reinterpret_cast<uint64_t*>(
5841-
hash_seed->begin() + kInt64Size));
5842-
#endif // V8_USE_DEFAULT_HASHER_SECRET
5843-
}
5844-
58455819
std::shared_ptr<v8::TaskRunner> Heap::GetForegroundTaskRunner() const {
58465820
return task_runner_;
58475821
}

deps/v8/src/heap/heap.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -725,9 +725,6 @@ class Heap final {
725725
// Prepares the heap, setting up for deserialization.
726726
void InitializeMainThreadLocalHeap(LocalHeap* main_thread_local_heap);
727727

728-
// (Re-)Initialize hash seed from flag or RNG.
729-
void InitializeHashSeed();
730-
731728
// Invoked once for the process from V8::Initialize.
732729
static void InitializeOncePerProcess();
733730

deps/v8/src/heap/setup-heap-internal.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "src/init/heap-symbols.h"
1717
#include "src/init/setup-isolate.h"
1818
#include "src/interpreter/interpreter.h"
19+
#include "src/numbers/hash-seed.h"
1920
#include "src/objects/arguments.h"
2021
#include "src/objects/call-site-info.h"
2122
#include "src/objects/cell-inl.h"
@@ -853,9 +854,10 @@ bool Heap::CreateImportantReadOnlyObjects() {
853854
// Hash seed for strings
854855

855856
Factory* factory = isolate()->factory();
856-
set_hash_seed(
857-
*factory->NewByteArray(kInt64Size * 4, AllocationType::kReadOnly));
858-
InitializeHashSeed();
857+
set_hash_seed(*factory->NewByteArray(HashSeed::kTotalSize,
858+
AllocationType::kReadOnly,
859+
AllocationAlignment::kDoubleAligned));
860+
HashSeed::InitializeRoots(isolate());
859861

860862
// Important strings and symbols
861863
for (const ConstantStringInit& entry : kImportantConstantStringTable) {

deps/v8/src/numbers/hash-seed-inl.h

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include "src/numbers/hash-seed.h"
99
#include "src/objects/fixed-array-inl.h"
1010
#include "src/roots/roots-inl.h"
11-
#include "third_party/rapidhash-v8/secret.h"
1211

1312
namespace v8 {
1413
namespace internal {
@@ -19,23 +18,13 @@ inline HashSeed::HashSeed(Isolate* isolate)
1918
inline HashSeed::HashSeed(LocalIsolate* isolate)
2019
: HashSeed(ReadOnlyRoots(isolate)) {}
2120

22-
inline HashSeed::HashSeed(ReadOnlyRoots roots) {
23-
// roots.hash_seed is not aligned
24-
MemCopy(&seed_, roots.hash_seed()->begin(), sizeof(seed_));
25-
MemCopy(secret_, roots.hash_seed()->begin() + sizeof(seed_), sizeof(secret_));
26-
}
27-
28-
inline HashSeed::HashSeed(uint64_t seed, const uint64_t secret[3])
29-
: seed_(seed),
30-
secret_{
31-
secret[0],
32-
secret[1],
33-
secret[2],
34-
} {}
35-
36-
inline HashSeed HashSeed::Default() {
37-
return HashSeed(0, RAPIDHASH_DEFAULT_SECRET);
38-
}
21+
inline HashSeed::HashSeed(ReadOnlyRoots roots)
22+
: data_(reinterpret_cast<const Data*>(roots.hash_seed()->begin())) {}
23+
24+
inline HashSeed HashSeed::Default() { return HashSeed(kDefaultData); }
25+
26+
inline uint64_t HashSeed::seed() const { return data_->seed; }
27+
inline const uint64_t* HashSeed::secret() const { return data_->secrets; }
3928

4029
} // namespace internal
4130
} // namespace v8

0 commit comments

Comments
 (0)