Skip to content

Commit

Permalink
Fix snapshot sniffing code to give better error messages.
Browse files Browse the repository at this point in the history
TEST=ci

Change-Id: If5097c74e7e4f85de2ca8cfc2cab3283f8328ae3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/402202
Reviewed-by: Alexander Aprelev <[email protected]>
Commit-Queue: Siva Annamalai <[email protected]>
  • Loading branch information
a-siva authored and Commit Queue committed Jan 2, 2025
1 parent 0d63c97 commit cd66003
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
12 changes: 12 additions & 0 deletions runtime/bin/main_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1296,10 +1296,22 @@ void main(int argc, char** argv) {
script_name);
Platform::Exit(kErrorExitCode);
}
if (app_snapshot->IsJIT() && Dart_IsPrecompiledRuntime()) {
Syslog::PrintErr(
"%s is a JIT snapshot, it cannot be run with 'dartaotruntime'\n",
script_name);
Platform::Exit(kErrorExitCode);
}
vm_run_app_snapshot = true;
app_snapshot->SetBuffers(&vm_snapshot_data, &vm_snapshot_instructions,
&app_isolate_snapshot_data,
&app_isolate_snapshot_instructions);
} else if (app_snapshot == nullptr && Dart_IsPrecompiledRuntime()) {
Syslog::PrintErr(
"%s is not an AOT snapshot,"
" it cannot be run with 'dartaotruntime'\n",
script_name);
Platform::Exit(kErrorExitCode);
}
};

Expand Down
10 changes: 5 additions & 5 deletions runtime/bin/snapshot_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class DummySnapshot : public AppSnapshot {

private:
};
#endif // !defined(DART_PRECOMPILED_RUNTIME)

class MappedAppSnapshot : public AppSnapshot {
public:
Expand Down Expand Up @@ -143,6 +142,7 @@ static AppSnapshot* TryReadAppSnapshotBlobs(const char* script_name,
nullptr, nullptr, isolate_data_mapping, isolate_instr_mapping);
return app_snapshot;
}
#endif // !defined(DART_PRECOMPILED_RUNTIME)

#if defined(DART_PRECOMPILED_RUNTIME)
class ElfAppSnapshot : public AppSnapshot {
Expand Down Expand Up @@ -594,10 +594,6 @@ AppSnapshot* Snapshot::TryReadAppSnapshot(const char* script_uri,
}
DartUtils::MagicNumber magic_number =
DartUtils::SniffForMagicNumber(header, sizeof(header));
if (magic_number == DartUtils::kAppJITMagicNumber) {
// Return the JIT snapshot.
return TryReadAppSnapshotBlobs(script_name, file);
}
#if defined(DART_PRECOMPILED_RUNTIME)
if (!DartUtils::IsAotMagicNumber(magic_number)) {
return nullptr;
Expand All @@ -623,6 +619,10 @@ AppSnapshot* Snapshot::TryReadAppSnapshot(const char* script_uri,
return TryReadAppSnapshotElf(script_name, /*file_offset=*/0,
force_load_elf_from_memory);
#else
if (magic_number == DartUtils::kAppJITMagicNumber) {
// Return the JIT snapshot.
return TryReadAppSnapshotBlobs(script_name, file);
}
// We create a dummy snapshot object just to remember the type which
// has already been identified by sniffing the magic number.
return new DummySnapshot(magic_number);
Expand Down

0 comments on commit cd66003

Please sign in to comment.