From e65d693c7c887161b5cd9fbd172c215ade4b6877 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Thu, 4 Aug 2022 18:25:34 +0800 Subject: [PATCH 1/4] bootstrap: check more metadata when loading the snapshot This patch stores the metadata about the Node.js binary into the SnapshotData and adds fields denoting how the snapshot was generated, on what platform it was generated as well as the V8 cached data version flag. Instead of simply crashing when the metadata doesn't match, Node.js now prints an error message and exit with 1 for the customized snapshot, or ignore the snapshot and start from scratch if it's the default one. --- doc/api/cli.md | 9 +++ src/env.cc | 15 +++++ src/env.h | 20 +++++- src/node.cc | 14 +++- src/node_internals.h | 1 + src/node_snapshotable.cc | 142 +++++++++++++++++++++++++++++++++++---- 6 files changed, 184 insertions(+), 17 deletions(-) diff --git a/doc/api/cli.md b/doc/api/cli.md index 97864f15a64daf..dd7cbbd12fc1b2 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -1198,6 +1198,15 @@ in the current working directory. When used without `--build-snapshot`, `--snapshot-blob` specifies the path to the blob that will be used to restore the application state. +When loading a snapshot, Node.js checks that: + +1. The version, architecture and platform of the running Node.js binary + are exactly the same as that of the binary that generates the snapshot. +2. The V8 flags and CPU features are compatible with that of the binary + that generates the snapshot. + +If they don't match, Node.js would refuse to load the snapshot and exit with 1. + ### `--test`