From 06ece5645c07471a740af8ee622da970845daae7 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Fri, 15 Sep 2023 00:17:01 +0200 Subject: [PATCH] fix: init v8 platform once on main thread (#20495) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a mitigation for segfaults happening in V8 on CPU with MPK (memory protected keys). After much trail and error we found that unless V8 platform is initialized on main thread the segfaults start appears once JIT kicks in. "deno test" and "deno bench" were affected by this problem. Fixes https://github.com/denoland/deno/issues/19926 Fixes https://github.com/denoland/deno/issues/20243 Fixes https://github.com/denoland/deno/issues/20450 --------- Co-authored-by: Bartek IwaƄczuk --- cli/main.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cli/main.rs b/cli/main.rs index 9044a14da3..df5dd0b261 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -264,6 +264,10 @@ pub fn main() { let args: Vec = env::args().collect(); + // NOTE(lucacasonato): due to new PKU feature introduced in V8 11.6 we need to + // initalize the V8 platform on a parent thread of all threads that will spawn + // V8 isolates. + let future = async move { let current_exe_path = current_exe()?; let standalone_res = @@ -296,6 +300,7 @@ pub fn main() { _ => vec![], }; init_v8_flags(&default_v8_flags, &flags.v8_flags, get_v8_flags_from_env()); + deno_core::JsRuntime::init_platform(None); util::logger::init(flags.log_level);