@@ -7,10 +7,10 @@ This refactors several allocators to allocate within the V8 memory cage,
77allowing them to be compatible with the V8_SANDBOXED_POINTERS feature.
88
99diff --git a/src/api/environment.cc b/src/api/environment.cc
10- index 2abf5994405e8da2a04d1b23b75ccd3658398474..b06e8529bb8ca2fa6d7f0735531bbbf39da6af12 100644
10+ index 9cbe99596b1b8c148ac076acf8a9623d6989d505..93d85d46dc6b3b30795b88ffa8070253f62e51bd 100644
1111--- a/src/api/environment.cc
1212+++ b/src/api/environment.cc
13- @@ -80,19 +80,27 @@ MaybeLocal<Value> PrepareStackTraceCallback(Local<Context> context,
13+ @@ -80,6 +80,14 @@ MaybeLocal<Value> PrepareStackTraceCallback(Local<Context> context,
1414 return result;
1515 }
1616
@@ -24,42 +24,8 @@ index 2abf5994405e8da2a04d1b23b75ccd3658398474..b06e8529bb8ca2fa6d7f0735531bbbf3
2424+
2525 void* NodeArrayBufferAllocator::Allocate(size_t size) {
2626 void* ret;
27- - if (zero_fill_field_ || per_process::cli_options->zero_fill_all_buffers)
28- - ret = UncheckedCalloc(size);
29- + if (*zero_fill_field_ || per_process::cli_options->zero_fill_all_buffers)
30- + ret = allocator_->Allocate(size);
31- else
32- - ret = UncheckedMalloc(size);
33- + ret = allocator_->AllocateUninitialized(size);
34- if (LIKELY(ret != nullptr))
35- total_mem_usage_.fetch_add(size, std::memory_order_relaxed);
36- return ret;
37- }
38-
39- void* NodeArrayBufferAllocator::AllocateUninitialized(size_t size) {
40- - void* ret = node::UncheckedMalloc(size);
41- + void* ret = allocator_->AllocateUninitialized(size);
42- if (LIKELY(ret != nullptr))
43- total_mem_usage_.fetch_add(size, std::memory_order_relaxed);
44- return ret;
45- @@ -100,7 +108,7 @@ void* NodeArrayBufferAllocator::AllocateUninitialized(size_t size) {
46-
47- void* NodeArrayBufferAllocator::Reallocate(
48- void* data, size_t old_size, size_t size) {
49- - void* ret = UncheckedRealloc<char>(static_cast<char*>(data), size);
50- + void* ret = allocator_->Reallocate(data, old_size, size);
51- if (LIKELY(ret != nullptr) || UNLIKELY(size == 0))
52- total_mem_usage_.fetch_add(size - old_size, std::memory_order_relaxed);
53- return ret;
54- @@ -108,7 +116,7 @@ void* NodeArrayBufferAllocator::Reallocate(
55-
56- void NodeArrayBufferAllocator::Free(void* data, size_t size) {
57- total_mem_usage_.fetch_sub(size, std::memory_order_relaxed);
58- - free(data);
59- + allocator_->Free(data, size);
60- }
61-
62- DebuggingArrayBufferAllocator::~DebuggingArrayBufferAllocator() {
27+ if (zero_fill_field_ || per_process::cli_options->zero_fill_all_buffers)
28+
6329diff --git a/src/crypto/crypto_util.cc b/src/crypto/crypto_util.cc
6430index f55e292fbbc75448b15dc9be0327ad2dedef49e0..7719574859637aecc98f8a4b00ba6ebca8280631 100644
6531--- a/src/crypto/crypto_util.cc
@@ -166,7 +132,7 @@ index c537a247f55ff070da1988fc8b7309b5692b5c18..59bfb597849cd5a94800d6c83b238ef7
166132 return ret;
167133
168134diff --git a/src/node_internals.h b/src/node_internals.h
169- index d37be23cd63e82d4040777bd0e17ed449ec0b15b..eb84760593ff5fb5aa6a8104e8714099f24a67a0 100644
135+ index f7314c906e580664be445a8912030e17a3ac2fa4..99258ad0aa1e15ea1ba139fd0e83111e1436cc40 100644
170136--- a/src/node_internals.h
171137+++ b/src/node_internals.h
172138@@ -97,7 +97,9 @@ bool InitializePrimordials(v8::Local<v8::Context> context);
@@ -180,18 +146,16 @@ index d37be23cd63e82d4040777bd0e17ed449ec0b15b..eb84760593ff5fb5aa6a8104e8714099
180146
181147 void* Allocate(size_t size) override; // Defined in src/node.cc
182148 void* AllocateUninitialized(size_t size) override;
183- @@ -116,8 +118,10 @@ class NodeArrayBufferAllocator : public ArrayBufferAllocator {
149+ @@ -116,7 +118,7 @@ class NodeArrayBufferAllocator : public ArrayBufferAllocator {
184150 }
185151
186152 private:
187153- uint32_t zero_fill_field_ = 1; // Boolean but exposed as uint32 to JS land.
188154+ uint32_t* zero_fill_field_ = nullptr; // Boolean but exposed as uint32 to JS land.
189155 std::atomic<size_t> total_mem_usage_ {0};
190- +
191- + std::unique_ptr<v8::ArrayBuffer::Allocator> allocator_{v8::ArrayBuffer::Allocator::NewDefaultAllocator()};
192- };
193156
194- class DebuggingArrayBufferAllocator final : public NodeArrayBufferAllocator {
157+ // Delegate to V8's allocator for compatibility with the V8 memory cage.
158+
195159diff --git a/src/node_serdes.cc b/src/node_serdes.cc
196160index f6f0034bc24d09e3ad65491c7d6be0b9c9db1581..92d5020f293c98c81d3891a82f7320629bf9f926 100644
197161--- a/src/node_serdes.cc
0 commit comments