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

bootstrap: split NodeMainInstance::Run() and move handle checking code to the snapshot builder #39007

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 13 additions & 15 deletions src/node_main_instance.cc
Expand Up @@ -132,21 +132,24 @@ int NodeMainInstance::Run(const EnvSerializeInfo* env_info) {
int exit_code = 0;
DeleteFnPtr<Environment, FreeEnvironment> env =
CreateMainEnvironment(&exit_code, env_info);

CHECK_NOT_NULL(env);
{
Context::Scope context_scope(env->context());

if (exit_code == 0) {
LoadEnvironment(env.get(), StartExecutionCallback{});
Context::Scope context_scope(env->context());
Run(&exit_code, env.get());
return exit_code;
}

exit_code = SpinEventLoop(env.get()).FromMaybe(1);
}
void NodeMainInstance::Run(int* exit_code, Environment* env) {
if (*exit_code == 0) {
LoadEnvironment(env, StartExecutionCallback{});

ResetStdio();
*exit_code = SpinEventLoop(env).FromMaybe(1);
}

// TODO(addaleax): Neither NODE_SHARED_MODE nor HAVE_INSPECTOR really
// make sense here.
ResetStdio();

// TODO(addaleax): Neither NODE_SHARED_MODE nor HAVE_INSPECTOR really
// make sense here.
#if HAVE_INSPECTOR && defined(__POSIX__) && !defined(NODE_SHARED_MODE)
struct sigaction act;
memset(&act, 0, sizeof(act));
Expand All @@ -161,9 +164,6 @@ int NodeMainInstance::Run(const EnvSerializeInfo* env_info) {
#if defined(LEAK_SANITIZER)
__lsan_do_leak_check();
#endif
}

return exit_code;
}

DeleteFnPtr<Environment, FreeEnvironment>
Expand Down Expand Up @@ -224,8 +224,6 @@ NodeMainInstance::CreateMainEnvironment(int* exit_code,
}
}

CHECK(env->req_wrap_queue()->IsEmpty());
CHECK(env->handle_wrap_queue()->IsEmpty());
return env;
}

Expand Down
1 change: 1 addition & 0 deletions src/node_main_instance.h
Expand Up @@ -59,6 +59,7 @@ class NodeMainInstance {

// Start running the Node.js instances, return the exit code when finished.
int Run(const EnvSerializeInfo* env_info);
void Run(int* exit_code, Environment* env);

IsolateData* isolate_data() { return isolate_data_.get(); }

Expand Down
14 changes: 14 additions & 0 deletions src/node_snapshotable.cc
Expand Up @@ -157,7 +157,21 @@ void SnapshotBuilder::Generate(SnapshotData* out,
// Must be out of HandleScope
out->blob =
creator.CreateBlob(SnapshotCreator::FunctionCodeHandling::kClear);

// We must be able to rehash the blob when we restore it or otherwise
// the hash seed would be fixed by V8, introducing a vulnerability.
CHECK(out->blob.CanBeRehashed());

// We cannot resurrect the handles from the snapshot, so make sure that
// no handles are left open in the environment after the blob is created
// (which should trigger a GC and close all handles that can be closed).
if (!env->req_wrap_queue()->IsEmpty() || !env->handle_wrap_queue()->IsEmpty()
|| per_process::enabled_debug_list.enabled(DebugCategory::MKSNAPSHOT)) {
joyeecheung marked this conversation as resolved.
Show resolved Hide resolved
PrintLibuvHandleInformation(env->event_loop(), stderr);
}
CHECK(env->req_wrap_queue()->IsEmpty());
CHECK(env->handle_wrap_queue()->IsEmpty());

// Must be done while the snapshot creator isolate is entered i.e. the
// creator is still alive.
FreeEnvironment(env);
Expand Down