Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: disable V8 PKU feature for 'deno test' and 'deno bench' #20491

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions cli/lsp/testing/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ impl TestRun {
specifier,
sender.clone(),
fail_fast_tracker,
None,
test::TestSpecifierOptions {
filter,
shuffle: None,
Expand Down
9 changes: 9 additions & 0 deletions cli/tools/bench/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,15 @@ async fn bench_specifier(
specifier: ModuleSpecifier,
sender: UnboundedSender<BenchEvent>,
filter: TestFilter,
v8_platform: Option<v8::SharedRef<v8::Platform>>,
) -> Result<(), AnyError> {
let mut worker = worker_factory
.create_custom_worker(
specifier.clone(),
PermissionsContainer::new(permissions),
vec![ops::bench::deno_bench::init_ops(sender.clone())],
Default::default(),
v8_platform,
)
.await?;

Expand Down Expand Up @@ -240,8 +242,14 @@ async fn bench_specifiers(
let (sender, mut receiver) = unbounded_channel::<BenchEvent>();
let log_level = options.log_level;
let option_for_handles = options.clone();
// NOTE(bartlomieju): due to new PKU feature introduced in V8 11.6 we need to
// use `new_unprotected` platform here, that disables the PKU. This is done,
// because we were getting segfaults if isolates were not created on the main
// thread.
let v8_platform = v8::Platform::new_unprotected(0, false).make_shared();

let join_handles = specifiers.into_iter().map(move |specifier| {
let v8_platform = v8_platform.clone();
let worker_factory = worker_factory.clone();
let permissions = permissions.clone();
let specifier = specifier;
Expand All @@ -254,6 +262,7 @@ async fn bench_specifiers(
specifier,
sender,
options.filter,
Some(v8_platform.clone()),
);
create_and_run_current_thread(future)
})
Expand Down
10 changes: 10 additions & 0 deletions cli/tools/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ pub async fn test_specifier(
specifier: ModuleSpecifier,
mut sender: TestEventSender,
fail_fast_tracker: FailFastTracker,
v8_platform: Option<v8::SharedRef<v8::Platform>>,
options: TestSpecifierOptions,
) -> Result<(), AnyError> {
if fail_fast_tracker.should_stop() {
Expand All @@ -428,6 +429,7 @@ pub async fn test_specifier(
stdout,
stderr,
},
v8_platform,
)
.await?;

Expand Down Expand Up @@ -815,6 +817,12 @@ async fn test_specifiers(
specifiers
};

// NOTE(bartlomieju): due to new PKU feature introduced in V8 11.6 we need to
// use `new_unprotected` platform here, that disables the PKU. This is done,
// because we were getting segfaults if isolates were not created on the main
// thread.
let v8_platform = v8::Platform::new_unprotected(0, false).make_shared();

let (sender, mut receiver) = unbounded_channel::<TestEvent>();
let sender = TestEventSender::new(sender);
let concurrent_jobs = options.concurrent_jobs;
Expand All @@ -828,6 +836,7 @@ async fn test_specifiers(
let mut reporter = get_test_reporter(&options);

let join_handles = specifiers.into_iter().map(move |specifier| {
let v8_platform = v8_platform.clone();
let worker_factory = worker_factory.clone();
let permissions = permissions.clone();
let sender = sender.clone();
Expand All @@ -840,6 +849,7 @@ async fn test_specifiers(
specifier,
sender.clone(),
fail_fast_tracker,
Some(v8_platform.clone()),
specifier_options,
))
})
Expand Down
3 changes: 3 additions & 0 deletions cli/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ impl CliMainWorkerFactory {
permissions,
vec![],
Default::default(),
None,
)
.await
}
Expand All @@ -339,6 +340,7 @@ impl CliMainWorkerFactory {
permissions: PermissionsContainer,
mut custom_extensions: Vec<Extension>,
stdio: deno_runtime::deno_io::Stdio,
v8_platform: Option<deno_core::v8::SharedRef<deno_core::v8::Platform>>,
) -> Result<CliMainWorker, AnyError> {
let shared = &self.shared;
let (main_module, is_main_cjs) = if let Ok(package_ref) =
Expand Down Expand Up @@ -455,6 +457,7 @@ impl CliMainWorkerFactory {
shared.compiled_wasm_module_store.clone(),
),
stdio,
v8_platform,
};

let worker = MainWorker::bootstrap_from_options(
Expand Down
6 changes: 5 additions & 1 deletion runtime/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ pub struct WorkerOptions {
/// Optional isolate creation parameters, such as heap limits.
pub create_params: Option<v8::CreateParams>,

// Optional `v8::Platform` to use to create the associated `JsRuntime`.
pub v8_platform: Option<v8::SharedRef<v8::Platform>>,

pub unsafely_ignore_certificate_errors: Option<Vec<String>>,
pub root_cert_store_provider: Option<Arc<dyn RootCertStoreProvider>>,
pub seed: Option<u64>,
Expand Down Expand Up @@ -170,6 +173,7 @@ impl Default for WorkerOptions {
extensions: Default::default(),
startup_snapshot: Default::default(),
create_params: Default::default(),
v8_platform: Default::default(),
bootstrap: Default::default(),
stdio: Default::default(),
}
Expand Down Expand Up @@ -333,6 +337,7 @@ impl MainWorker {
.startup_snapshot
.or_else(crate::js::deno_isolate_init),
create_params: options.create_params,
v8_platform: options.v8_platform,
source_map_getter: options.source_map_getter,
get_error_class_fn: options.get_error_class_fn,
shared_array_buffer_store: options.shared_array_buffer_store.clone(),
Expand All @@ -341,7 +346,6 @@ impl MainWorker {
preserve_snapshotted_modules,
inspector: options.maybe_inspector_server.is_some(),
is_main: true,
..Default::default()
});

if let Some(server) = options.maybe_inspector_server.clone() {
Expand Down