Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ jobs:
# arch: 'linux/arm64'
# node: '20.18.0'

linux_amd64:
imageName: 'ubuntu-20.04'
arch: 'linux/amd64'
node: '22.14.0'
ptrcompress: false
# linux_amd64:
# imageName: 'ubuntu-20.04'
# arch: 'linux/amd64'
# node: '22.14.0'
# ptrcompress: false

# Pointer Compression builds are failing on Linux
# linux_amd64_ptrc:
Expand All @@ -34,12 +34,12 @@ jobs:

macos_arm64:
imageName: 'macOS-15'
node: '22.14.0'
node: '22.17.1'
arch: 'arm64'
ptrcompress: false
macos_x64:
imageName: 'macOS-15'
node: '22.14.0'
node: '22.17.1'
arch: 'x64'
ptrcompress: false

Expand Down
2 changes: 0 additions & 2 deletions src/NodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ class NodeJsBuilder {
async patchThirdPartyMain() {
await patchFile(this.nodeSrcDir, join(this.patchDir, 'run_third_party_main.js.patch'));
await patchFile(this.nodeSrcDir, join(this.patchDir, 'node.cc.patch'));
await patchFile(this.nodeSrcDir, join(this.patchDir, 'fs-event.c.patch'));
}

async patchNodeCompileIssues() {
Expand All @@ -212,7 +211,6 @@ class NodeJsBuilder {
// The following patches fix the memory leak when using pointer compression
// They are fixing both Linux and Windows, however, we only apply them to Windows to keep the blast radius small
await patchFile(this.nodeSrcDir, join(this.patchDir, 'configure.py.patch'));
await patchFile(this.nodeSrcDir, join(this.patchDir, 'features.gypi.patch'));
await patchFile(this.nodeSrcDir, join(this.patchDir, 'node_buffer.cc.patch'));
await patchFile(this.nodeSrcDir, join(this.patchDir, 'v8_backing_store_callers.patch'));
}
Expand Down
17 changes: 17 additions & 0 deletions src/patch/22.17.1/configure.py.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--- a/configure.py
+++ b/configure.py
@@ -1722,11 +1722,12 @@ def configure_v8(o, configs):
# Until we manage to get rid of all those, v8_enable_sandbox cannot be used.
# Note that enabling pointer compression without enabling sandbox is unsupported by V8,
# so this can be broken at any time.
- o['variables']['v8_enable_sandbox'] = 0
+ # o['variables']['v8_enable_sandbox'] = 0
+ o['variables']['v8_enable_sandbox'] = 1 if options.enable_pointer_compression else 0
o['variables']['v8_enable_pointer_compression_shared_cage'] = 1 if options.enable_pointer_compression else 0
o['variables']['v8_enable_external_code_space'] = 1 if options.enable_pointer_compression else 0
+ o['variables']['v8_enable_shared_ro_heap'] = 0 if options.disable_shared_ro_heap else 1
o['variables']['v8_enable_31bit_smis_on_64bit_arch'] = 1 if options.enable_pointer_compression else 0
- o['variables']['v8_enable_shared_ro_heap'] = 0 if options.enable_pointer_compression or options.disable_shared_ro_heap else 1
o['variables']['v8_enable_extensible_ro_snapshot'] = 0
o['variables']['v8_trace_maps'] = 1 if options.trace_maps else 0
o['variables']['node_use_v8_platform'] = b(not options.without_v8_platform)
24 changes: 24 additions & 0 deletions src/patch/22.17.1/no_rand_on_glibc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
disable usage of <sys/random.h>

--- a/deps/cares/config/linux/ares_config.h
+++ b/deps/cares/config/linux/ares_config.h
@@ -116,7 +116,9 @@
#define HAVE_GETNAMEINFO 1

/* Define to 1 if you have `getrandom` */
+#if defined(__GLIBC__) && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 25
#define HAVE_GETRANDOM 1
+#endif

/* Define to 1 if you have `getservbyport_r` */
#define HAVE_GETSERVBYPORT_R 1
@@ -329,7 +331,9 @@
#define HAVE_SYS_PARAM_H 1

/* Define to 1 if you have the <sys/random.h> header file. */
+#if defined(__GLIBC__) && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 25
#define HAVE_SYS_RANDOM_H 1
+#endif

/* Define to 1 if you have the <sys/select.h> header file. */
#define HAVE_SYS_SELECT_H 1
17 changes: 17 additions & 0 deletions src/patch/22.17.1/node.cc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--- a/src/node.cc
+++ b/src/node.cc
@@ -404,6 +404,14 @@ MaybeLocal<Value> StartExecution(Environment* env, StartExecutionCallback cb) {
return env->RunSnapshotDeserializeMain();
}

+ // To allow people to extend Node in different ways, this hook allows
+ // one to drop a file lib/_third_party_main.js into the build
+ // directory which will be executed instead of Node's normal loading.
+ if (env->builtin_loader()->Exists("_third_party_main")) {
+ return StartExecution(env, "internal/main/run_third_party_main");
+ }
+
+
if (env->worker_context() != nullptr) {
return StartExecution(env, "internal/main/worker_thread");
}
13 changes: 13 additions & 0 deletions src/patch/22.17.1/node.gyp.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
disable building of cctest as it (a) it fails to build due to align_alloc and (b) it is just a waste of time

--- a/node.gyp
+++ b/node.gyp
@@ -1170,7 +1170,7 @@
}, # fuzz_strings
{
'target_name': 'cctest',
- 'type': 'executable',
+ 'type': 'none',

'dependencies': [
'<(node_lib_target_name)',
173 changes: 173 additions & 0 deletions src/patch/22.17.1/node_buffer.cc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
--- a/src/node_buffer.cc
+++ b/src/node_buffer.cc
@@ -81,6 +81,100 @@ using v8::Uint32Array;
using v8::Uint8Array;
using v8::Value;

+// Helper function to create a sandbox-aware backing store
+std::unique_ptr<BackingStore> CreateBackingStore(
+ Isolate* isolate,
+ void* data,
+ size_t byte_length,
+ BackingStore::DeleterCallback deleter,
+ void* deleter_data) {
+#ifdef V8_ENABLE_SANDBOX
+ // When V8 sandbox is enabled, we need to allocate memory through V8's
+ // ArrayBuffer::Allocator to ensure it's within the sandbox memory region.
+ // This creates a new backing store by first allocating memory through V8,
+ // copying any existing data into it, and setting up proper deallocation.
+ ArrayBuffer::Allocator* allocator = isolate->GetArrayBufferAllocator();
+ if (!allocator) {
+ fprintf(stderr, "Failed to get array buffer allocator\n");
+ return nullptr;
+ }
+
+ // Allocate memory using the isolate's allocator to ensure it's within the sandbox
+ void* allocated_memory = allocator->Allocate(byte_length);
+ if (!allocated_memory) {
+ fprintf(stderr, "Failed to allocate memory\n");
+ return nullptr;
+ }
+
+ // If we have data to copy, copy it into the allocated memory
+ if (data != nullptr) {
+ memcpy(allocated_memory, data, byte_length);
+ }
+
+ // Define a structure to hold all the information needed for proper memory cleanup
+ struct BackingStoreDeleterContext {
+ BackingStore::DeleterCallback original_deleter; // Original callback to free external resources
+ void* original_deleter_data; // Data passed to the original deleter
+ void* original_data; // Original data pointer
+ ArrayBuffer::Allocator* allocator; // Allocator used to free the memory
+ };
+
+ std::unique_ptr<BackingStoreDeleterContext> deletion_context;
+ if (deleter != nullptr) {
+ deletion_context = std::make_unique<BackingStoreDeleterContext>(BackingStoreDeleterContext{
+ deleter, deleter_data, data, allocator
+ });
+ }
+
+ std::unique_ptr<BackingStore> store;
+ if (deleter != nullptr) {
+ store = ArrayBuffer::NewBackingStore(
+ allocated_memory,
+ byte_length,
+ [](void* data, size_t length, void* deletion_context_ptr) {
+ auto* context = static_cast<BackingStoreDeleterContext*>(deletion_context_ptr);
+ // Call the original deleter to clean up any external resources
+ context->original_deleter(context->original_data, length, context->original_deleter_data);
+ // Free the memory using the allocator
+ context->allocator->Free(data, length);
+ },
+ deletion_context.get() // Pass the deletion context for memory cleanup
+ );
+ } else {
+ store = ArrayBuffer::NewBackingStore(
+ allocated_memory,
+ byte_length,
+ [](void* data, size_t length, void* allocator_ptr) {
+ auto* allocator = static_cast<ArrayBuffer::Allocator*>(allocator_ptr);
+ // Free the memory using the allocator
+ allocator->Free(data, length);
+ },
+ static_cast<void*>(allocator) // Pass the allocator for memory cleanup
+ );
+ }
+
+ // Handle the case where backing store creation fails
+ if (!store) {
+ fprintf(stderr, "Failed to create backing store\n");
+ allocator->Free(allocated_memory, byte_length);
+ return nullptr;
+ }
+
+ // Transfer ownership of the deletion context to the BackingStore
+ // This ensures the deletion context lives as long as the BackingStore and is properly cleaned up
+ deletion_context.release();
+
+ return store;
+#else
+ // When sandbox is not enabled, we can directly create the backing store
+ if (deleter != nullptr) {
+ return ArrayBuffer::NewBackingStore(data, byte_length, deleter, deleter_data);
+ } else {
+ return ArrayBuffer::NewBackingStore(isolate, byte_length);
+ }
+#endif
+}
+
namespace {

class CallbackInfo : public Cleanable {
@@ -122,7 +216,7 @@ Local<ArrayBuffer> CallbackInfo::CreateTrackedArrayBuffer(

CallbackInfo* self = new CallbackInfo(env, callback, data, hint);
std::unique_ptr<BackingStore> bs =
- ArrayBuffer::NewBackingStore(data, length, [](void*, size_t, void* arg) {
+ CreateBackingStore(env->isolate(), data, length, [](void*, size_t, void* arg) {
static_cast<CallbackInfo*>(arg)->OnBackingStoreFree();
}, self);
Local<ArrayBuffer> ab = ArrayBuffer::New(env->isolate(), std::move(bs));
@@ -309,7 +403,7 @@ MaybeLocal<Object> New(Isolate* isolate,
std::unique_ptr<BackingStore> store;

if (length > 0) {
- store = ArrayBuffer::NewBackingStore(isolate, length);
+ store = CreateBackingStore(isolate, nullptr, length, nullptr, nullptr);

if (!store) [[unlikely]] {
THROW_ERR_MEMORY_ALLOCATION_FAILED(isolate);
@@ -327,7 +421,7 @@ MaybeLocal<Object> New(Isolate* isolate,
if (actual > 0) [[likely]] {
if (actual < length) {
std::unique_ptr<BackingStore> old_store = std::move(store);
- store = ArrayBuffer::NewBackingStore(isolate, actual);
+ store = CreateBackingStore(isolate, nullptr, actual, nullptr, nullptr);
memcpy(store->Data(), old_store->Data(), actual);
}
Local<ArrayBuffer> buf = ArrayBuffer::New(isolate, std::move(store));
@@ -371,7 +465,7 @@ MaybeLocal<Object> New(Environment* env, size_t length) {
{
NoArrayBufferZeroFillScope no_zero_fill_scope(env->isolate_data());
std::unique_ptr<BackingStore> bs =
- ArrayBuffer::NewBackingStore(isolate, length);
+ CreateBackingStore(isolate, nullptr, length, nullptr, nullptr);

CHECK(bs);

@@ -414,7 +508,7 @@ MaybeLocal<Object> Copy(Environment* env, const char* data, size_t length) {
{
NoArrayBufferZeroFillScope no_zero_fill_scope(env->isolate_data());
std::unique_ptr<BackingStore> bs =
- ArrayBuffer::NewBackingStore(isolate, length);
+ CreateBackingStore(isolate, nullptr, length, nullptr, nullptr);

CHECK(bs);

@@ -515,7 +609,7 @@ MaybeLocal<Object> New(Environment* env,
free(data);
};
std::unique_ptr<BackingStore> bs =
- v8::ArrayBuffer::NewBackingStore(data, length, free_callback, nullptr);
+ CreateBackingStore(env->isolate(), data, length, free_callback, nullptr);

Local<ArrayBuffer> ab = v8::ArrayBuffer::New(env->isolate(), std::move(bs));

@@ -1242,10 +1336,11 @@ void GetZeroFillToggle(const FunctionCallbackInfo<Value>& args) {
} else {
uint32_t* zero_fill_field = allocator->zero_fill_field();
std::unique_ptr<BackingStore> backing =
- ArrayBuffer::NewBackingStore(zero_fill_field,
- sizeof(*zero_fill_field),
- [](void*, size_t, void*) {},
- nullptr);
+ CreateBackingStore(env->isolate(),
+ zero_fill_field,
+ sizeof(*zero_fill_field),
+ [](void*, size_t, void*) {},
+ nullptr);
ab = ArrayBuffer::New(env->isolate(), std::move(backing));
}

17 changes: 17 additions & 0 deletions src/patch/22.17.1/run_third_party_main.js.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--- /dev/null
+++ b/lib/internal/main/run_third_party_main.js
@@ -0,0 +1,14 @@
+'use strict';
+
+const {
+ prepareMainThreadExecution,
+ markBootstrapComplete
+} = require('internal/process/pre_execution');
+
+prepareMainThreadExecution();
+markBootstrapComplete();
+
+// Legacy _third_party_main.js support
+process.nextTick(() => {
+ require('_third_party_main');
+});
Loading