From 49d9af1f08f5f0e3c49a284f49d158de65a16b9a Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Mon, 9 Aug 2021 18:44:51 +0200 Subject: [PATCH 1/3] repl: fix crash when SharedArrayBuffer disabled --- patches/node/.patches | 4 ++ ...rash_when_sharedarraybuffer_disabled.patch | 63 +++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 patches/node/repl_fix_crash_when_sharedarraybuffer_disabled.patch diff --git a/patches/node/.patches b/patches/node/.patches index 0275693b13434..f0ec6996688a4 100644 --- a/patches/node/.patches +++ b/patches/node/.patches @@ -35,3 +35,7 @@ fix_handle_new_tostring_behavior_in_v8_serdes_test.patch node-api_faster_threadsafe_function.patch src_remove_extra_semi_after_member_fn.patch errors_refactor_to_use_more_primordials.patch +fix_account_for_debugger_agent_race_condition.patch +fix_use_new_v8_error_message_property_access_format.patch +add_should_read_node_options_from_env_option_to_disable_node_options.patch +repl_fix_crash_when_sharedarraybuffer_disabled.patch diff --git a/patches/node/repl_fix_crash_when_sharedarraybuffer_disabled.patch b/patches/node/repl_fix_crash_when_sharedarraybuffer_disabled.patch new file mode 100644 index 0000000000000..c08c1e8bad224 --- /dev/null +++ b/patches/node/repl_fix_crash_when_sharedarraybuffer_disabled.patch @@ -0,0 +1,63 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Shelley Vohr +Date: Mon, 9 Aug 2021 18:42:15 +0200 +Subject: repl: fix crash when SharedArrayBuffer disabled + +It's possible for SharedArrayBuffers to be disabled with +--no-harmony-sharedarraybuffer so we first need to check that this +isn't the case before attempting to use them in the repl or a crash occurs. + +Upstreamed at https://github.com/nodejs/node/pull/39718. + +diff --git a/benchmark/worker/atomics-wait.js b/benchmark/worker/atomics-wait.js +index a771b1813731edf4f0dd60f3505799e389f1d876..b9461677e2d7d1df192e752496e62cca837717b5 100644 +--- a/benchmark/worker/atomics-wait.js ++++ b/benchmark/worker/atomics-wait.js +@@ -7,6 +7,10 @@ const bench = common.createBenchmark(main, { + }); + + function main({ n }) { ++ if (typeof SharedArrayBuffer === 'undefined') { ++ throw new Error('SharedArrayBuffers must be enabled to run this benchmark'); ++ } ++ + const i32arr = new Int32Array(new SharedArrayBuffer(4)); + bench.start(); + for (let i = 0; i < n; i++) +diff --git a/lib/internal/main/worker_thread.js b/lib/internal/main/worker_thread.js +index d6434ff96e118535bc6ded88ee4d2f0ff253a8f7..1b8894f44e71c6f25f1f50e84293006afe158513 100644 +--- a/lib/internal/main/worker_thread.js ++++ b/lib/internal/main/worker_thread.js +@@ -9,7 +9,7 @@ const { + ArrayPrototypeSplice, + ObjectDefineProperty, + PromisePrototypeCatch, +- globalThis: { Atomics }, ++ globalThis: { Atomics, SharedArrayBuffer }, + } = primordials; + + const { +@@ -140,6 +140,9 @@ port.on('message', (message) => { + const originalCwd = process.cwd; + + process.cwd = function() { ++ // SharedArrayBuffers can be disabled with --no-harmony-sharedarraybuffer. ++ if (typeof SharedArrayBuffer === 'undefined') return originalCwd(); ++ + const currentCounter = Atomics.load(cwdCounter, 0); + if (currentCounter === lastCounter) + return cachedCwd; +diff --git a/lib/internal/worker.js b/lib/internal/worker.js +index 931bce0c518fc3355a9f94a7760556b6f0b75b96..99baa3e7f747bb3b351cb13c6ed512f2bb88812a 100644 +--- a/lib/internal/worker.js ++++ b/lib/internal/worker.js +@@ -92,7 +92,8 @@ let cwdCounter; + + const environmentData = new SafeMap(); + +-if (isMainThread) { ++// SharedArrayBuffers can be disabled with --no-harmony-sharedarraybuffer. ++if (isMainThread && typeof SharedArrayBuffer !== 'undefined') { + cwdCounter = new Uint32Array(new SharedArrayBuffer(4)); + const originalChdir = process.chdir; + process.chdir = function(path) { From fcf486388cd2cb2f1ebde422f5e6dcd13f6a09f6 Mon Sep 17 00:00:00 2001 From: John Kleinschmidt Date: Mon, 16 Aug 2021 13:22:00 -0400 Subject: [PATCH 2/3] fixup node .patches file --- patches/node/.patches | 3 --- 1 file changed, 3 deletions(-) diff --git a/patches/node/.patches b/patches/node/.patches index f0ec6996688a4..3ea2422035146 100644 --- a/patches/node/.patches +++ b/patches/node/.patches @@ -35,7 +35,4 @@ fix_handle_new_tostring_behavior_in_v8_serdes_test.patch node-api_faster_threadsafe_function.patch src_remove_extra_semi_after_member_fn.patch errors_refactor_to_use_more_primordials.patch -fix_account_for_debugger_agent_race_condition.patch -fix_use_new_v8_error_message_property_access_format.patch -add_should_read_node_options_from_env_option_to_disable_node_options.patch repl_fix_crash_when_sharedarraybuffer_disabled.patch From cb624eeaa7c0f10a3271bdca34054f0b922e073d Mon Sep 17 00:00:00 2001 From: John Kleinschmidt Date: Mon, 30 Aug 2021 09:49:44 -0400 Subject: [PATCH 3/3] update patch for 14-x-y --- ...rash_when_sharedarraybuffer_disabled.patch | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/patches/node/repl_fix_crash_when_sharedarraybuffer_disabled.patch b/patches/node/repl_fix_crash_when_sharedarraybuffer_disabled.patch index c08c1e8bad224..93dbc8ceb3fc9 100644 --- a/patches/node/repl_fix_crash_when_sharedarraybuffer_disabled.patch +++ b/patches/node/repl_fix_crash_when_sharedarraybuffer_disabled.patch @@ -25,19 +25,10 @@ index a771b1813731edf4f0dd60f3505799e389f1d876..b9461677e2d7d1df192e752496e62cca bench.start(); for (let i = 0; i < n; i++) diff --git a/lib/internal/main/worker_thread.js b/lib/internal/main/worker_thread.js -index d6434ff96e118535bc6ded88ee4d2f0ff253a8f7..1b8894f44e71c6f25f1f50e84293006afe158513 100644 +index 6f8cb6b942b5f295e6195e18059736df4bff8756..a2faa5c4a12f3af84dbfc4a3e4485d4ee5ce0167 100644 --- a/lib/internal/main/worker_thread.js +++ b/lib/internal/main/worker_thread.js -@@ -9,7 +9,7 @@ const { - ArrayPrototypeSplice, - ObjectDefineProperty, - PromisePrototypeCatch, -- globalThis: { Atomics }, -+ globalThis: { Atomics, SharedArrayBuffer }, - } = primordials; - - const { -@@ -140,6 +140,9 @@ port.on('message', (message) => { +@@ -132,6 +132,9 @@ port.on('message', (message) => { const originalCwd = process.cwd; process.cwd = function() { @@ -48,12 +39,12 @@ index d6434ff96e118535bc6ded88ee4d2f0ff253a8f7..1b8894f44e71c6f25f1f50e84293006a if (currentCounter === lastCounter) return cachedCwd; diff --git a/lib/internal/worker.js b/lib/internal/worker.js -index 931bce0c518fc3355a9f94a7760556b6f0b75b96..99baa3e7f747bb3b351cb13c6ed512f2bb88812a 100644 +index d38649c7fb158361096d5a7a3b5bd629ba7b6d0b..468e85cacb09f3e4b3dd5603d5f54a010c7ff751 100644 --- a/lib/internal/worker.js +++ b/lib/internal/worker.js -@@ -92,7 +92,8 @@ let cwdCounter; +@@ -81,7 +81,8 @@ let debug = require('internal/util/debuglog').debuglog('worker', (fn) => { - const environmentData = new SafeMap(); + let cwdCounter; -if (isMainThread) { +// SharedArrayBuffers can be disabled with --no-harmony-sharedarraybuffer.