diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index a323d42e1ae..265dca257bf 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -383,6 +383,8 @@ FILE: ../../../flutter/runtime/dart_service_isolate.h FILE: ../../../flutter/runtime/dart_service_isolate_unittests.cc FILE: ../../../flutter/runtime/dart_snapshot.cc FILE: ../../../flutter/runtime/dart_snapshot.h +FILE: ../../../flutter/runtime/dart_snapshot_buffer.cc +FILE: ../../../flutter/runtime/dart_snapshot_buffer.h FILE: ../../../flutter/runtime/dart_vm.cc FILE: ../../../flutter/runtime/dart_vm.h FILE: ../../../flutter/runtime/dart_vm_data.cc diff --git a/fml/mapping.cc b/fml/mapping.cc index 75ca1b39691..11882b6662b 100644 --- a/fml/mapping.cc +++ b/fml/mapping.cc @@ -4,18 +4,12 @@ #include "flutter/fml/mapping.h" -#include - namespace fml { -// FileMapping - uint8_t* FileMapping::GetMutableMapping() { return mutable_mapping_; } -// Data Mapping - DataMapping::DataMapping(std::vector data) : data_(std::move(data)) {} DataMapping::~DataMapping() = default; @@ -28,8 +22,6 @@ const uint8_t* DataMapping::GetMapping() const { return data_.data(); } -// NonOwnedMapping - size_t NonOwnedMapping::GetSize() const { return size_; } @@ -38,37 +30,4 @@ const uint8_t* NonOwnedMapping::GetMapping() const { return data_; } -// Symbol Mapping - -SymbolMapping::SymbolMapping(fml::RefPtr native_library, - const char* symbol_name) - : native_library_(std::move(native_library)) { - if (native_library_ && symbol_name != nullptr) { - mapping_ = native_library_->ResolveSymbol(symbol_name); - - if (mapping_ == nullptr) { - // Apparently, dart_bootstrap seems to account for the Mac behavior of - // requiring the underscore prefixed symbol name on non-Mac platforms as - // well. As a fallback, check the underscore prefixed variant of the - // symbol name and allow callers to not have handle this on a per platform - // toolchain quirk basis. - - std::stringstream underscore_symbol_name; - underscore_symbol_name << "_" << symbol_name; - mapping_ = - native_library_->ResolveSymbol(underscore_symbol_name.str().c_str()); - } - } -} - -SymbolMapping::~SymbolMapping() = default; - -size_t SymbolMapping::GetSize() const { - return 0; -} - -const uint8_t* SymbolMapping::GetMapping() const { - return mapping_; -} - } // namespace fml diff --git a/fml/mapping.h b/fml/mapping.h index f7e6bbd4231..05894a5c219 100644 --- a/fml/mapping.h +++ b/fml/mapping.h @@ -13,7 +13,6 @@ #include "flutter/fml/build_config.h" #include "flutter/fml/file.h" #include "flutter/fml/macros.h" -#include "flutter/fml/native_library.h" #include "flutter/fml/unique_fd.h" namespace fml { @@ -32,7 +31,7 @@ class Mapping { FML_DISALLOW_COPY_AND_ASSIGN(Mapping); }; -class FileMapping final : public Mapping { +class FileMapping : public Mapping { public: enum class Protection { kRead, @@ -46,10 +45,8 @@ class FileMapping final : public Mapping { ~FileMapping() override; - // |Mapping| size_t GetSize() const override; - // |Mapping| const uint8_t* GetMapping() const override; uint8_t* GetMutableMapping(); @@ -66,16 +63,14 @@ class FileMapping final : public Mapping { FML_DISALLOW_COPY_AND_ASSIGN(FileMapping); }; -class DataMapping final : public Mapping { +class DataMapping : public Mapping { public: DataMapping(std::vector data); ~DataMapping() override; - // |Mapping| size_t GetSize() const override; - // |Mapping| const uint8_t* GetMapping() const override; private: @@ -84,15 +79,13 @@ class DataMapping final : public Mapping { FML_DISALLOW_COPY_AND_ASSIGN(DataMapping); }; -class NonOwnedMapping final : public Mapping { +class NonOwnedMapping : public Mapping { public: NonOwnedMapping(const uint8_t* data, size_t size) : data_(data), size_(size) {} - // |Mapping| size_t GetSize() const override; - // |Mapping| const uint8_t* GetMapping() const override; private: @@ -102,26 +95,6 @@ class NonOwnedMapping final : public Mapping { FML_DISALLOW_COPY_AND_ASSIGN(NonOwnedMapping); }; -class SymbolMapping final : public Mapping { - public: - SymbolMapping(fml::RefPtr native_library, - const char* symbol_name); - - ~SymbolMapping() override; - - // |Mapping| - size_t GetSize() const override; - - // |Mapping| - const uint8_t* GetMapping() const override; - - private: - fml::RefPtr native_library_; - const uint8_t* mapping_ = nullptr; - - FML_DISALLOW_COPY_AND_ASSIGN(SymbolMapping); -}; - } // namespace fml #endif // FLUTTER_FML_MAPPING_H_ diff --git a/runtime/BUILD.gn b/runtime/BUILD.gn index bcfd7e399d5..9d6f0d80ea6 100644 --- a/runtime/BUILD.gn +++ b/runtime/BUILD.gn @@ -46,6 +46,8 @@ source_set("runtime") { "dart_service_isolate.h", "dart_snapshot.cc", "dart_snapshot.h", + "dart_snapshot_buffer.cc", + "dart_snapshot_buffer.h", "dart_vm.cc", "dart_vm.h", "dart_vm_data.cc", diff --git a/runtime/dart_isolate.cc b/runtime/dart_isolate.cc index 8de6bca542c..20b7c960ee2 100644 --- a/runtime/dart_isolate.cc +++ b/runtime/dart_isolate.cc @@ -679,11 +679,14 @@ DartIsolate::CreateDartVMAndEmbedderObjectPair( Dart_Isolate isolate = Dart_CreateIsolate( advisory_script_uri, // advisory_script_entrypoint, // - (*embedder_isolate)->GetIsolateSnapshot()->GetDataMapping(), - (*embedder_isolate)->GetIsolateSnapshot()->GetInstructionsMapping(), - (*embedder_isolate)->GetSharedSnapshot()->GetDataMapping(), - (*embedder_isolate)->GetSharedSnapshot()->GetInstructionsMapping(), flags, - embedder_isolate.get(), error); + (*embedder_isolate) + ->GetIsolateSnapshot() + ->GetData() + ->GetSnapshotPointer(), + (*embedder_isolate)->GetIsolateSnapshot()->GetInstructionsIfPresent(), + (*embedder_isolate)->GetSharedSnapshot()->GetDataIfPresent(), + (*embedder_isolate)->GetSharedSnapshot()->GetInstructionsIfPresent(), + flags, embedder_isolate.get(), error); if (isolate == nullptr) { FML_DLOG(ERROR) << *error; diff --git a/runtime/dart_snapshot.cc b/runtime/dart_snapshot.cc index 61d2b85a6ca..c2d6d400171 100644 --- a/runtime/dart_snapshot.cc +++ b/runtime/dart_snapshot.cc @@ -10,6 +10,7 @@ #include "flutter/fml/paths.h" #include "flutter/fml/trace_event.h" #include "flutter/lib/snapshot/snapshot.h" +#include "flutter/runtime/dart_snapshot_buffer.h" #include "flutter/runtime/dart_vm.h" namespace flutter { @@ -20,137 +21,151 @@ const char* DartSnapshot::kIsolateDataSymbol = "kDartIsolateSnapshotData"; const char* DartSnapshot::kIsolateInstructionsSymbol = "kDartIsolateSnapshotInstructions"; -static std::unique_ptr GetFileMapping( - const std::string path, - bool executable) { - fml::UniqueFD file = - fml::OpenFile(path.c_str(), // file path - false, // create file if necessary - fml::FilePermission::kRead // file permissions - ); +#if defined(OS_ANDROID) +// When assembling the .S file of the application, dart_bootstrap will prefix +// symbols via an `_` to ensure Mac's `dlsym()` can find it (Mac ABI prefixes C +// symbols with underscores). +// But Linux ABI does not prefix C symbols with underscores, so we have to +// explicitly look up the prefixed version. +#define SYMBOL_PREFIX "_" +#else +#define SYMBOL_PREFIX "" +#endif - if (!file.is_valid()) { - return nullptr; +static const char* kVMDataSymbolSo = SYMBOL_PREFIX "kDartVmSnapshotData"; +static const char* kVMInstructionsSymbolSo = + SYMBOL_PREFIX "kDartVmSnapshotInstructions"; +static const char* kIsolateDataSymbolSo = + SYMBOL_PREFIX "kDartIsolateSnapshotData"; +static const char* kIsolateInstructionsSymbolSo = + SYMBOL_PREFIX "kDartIsolateSnapshotInstructions"; + +std::unique_ptr ResolveVMData(const Settings& settings) { + if (settings.vm_snapshot_data) { + return DartSnapshotBuffer::CreateWithMapping(settings.vm_snapshot_data()); } - using Prot = fml::FileMapping::Protection; - std::unique_ptr mapping; - if (executable) { - mapping = std::make_unique( - file, std::initializer_list{Prot::kRead, Prot::kExecute}); - } else { - mapping = std::make_unique( - file, std::initializer_list{Prot::kRead}); - } - - if (mapping->GetSize() == 0 || mapping->GetMapping() == nullptr) { - return nullptr; - } - - return mapping; -} - -// The first party embedders don't yet use the stable embedder API and depend on -// the engine figuring out the locations of the various heap and instructions -// buffers. Consequently, the engine had baked in opinions about where these -// buffers would reside and how they would be packaged (examples, in an external -// dylib, in the same dylib, at a path, at a path relative to and FD, etc..). As -// the needs of the platforms changed, the lack of an API meant that the engine -// had to be patched to look for new fields in the settings object. This grew -// untenable and with the addition of the new Fuchsia embedder and the generic C -// embedder API, embedders could specify the mapping directly. Once everyone -// moves to the embedder API, this method can effectively be reduced to just -// invoking the embedder_mapping_callback directly. -static std::shared_ptr SearchMapping( - MappingCallback embedder_mapping_callback, - const std::string& file_path, - const std::string& native_library_path, - const char* native_library_symbol_name, - bool is_executable) { - // Ask the embedder. There is no fallback as we expect the embedders (via - // their embedding APIs) to just specify the mappings directly. - if (embedder_mapping_callback) { - return embedder_mapping_callback(); - } - - // Attempt to open file at path specified. - if (file_path.size() > 0) { - if (auto file_mapping = GetFileMapping(file_path, is_executable)) { - return file_mapping; + if (settings.vm_snapshot_data_path.size() > 0) { + if (auto source = DartSnapshotBuffer::CreateWithContentsOfFile( + fml::OpenFile(settings.vm_snapshot_data_path.c_str(), false, + fml::FilePermission::kRead), + {fml::FileMapping::Protection::kRead})) { + return source; } } - // Look in application specified native library if specified. - if (native_library_path.size() > 0) { - auto native_library = - fml::NativeLibrary::Create(native_library_path.c_str()); - auto symbol_mapping = std::make_unique( - native_library, native_library_symbol_name); - if (symbol_mapping->GetMapping() != nullptr) { - return symbol_mapping; + if (settings.application_library_path.size() > 0) { + auto shared_library = + fml::NativeLibrary::Create(settings.application_library_path.c_str()); + if (auto source = DartSnapshotBuffer::CreateWithSymbolInLibrary( + shared_library, kVMDataSymbolSo)) { + return source; } } - // Look inside the currently loaded process. - { - auto loaded_process = fml::NativeLibrary::CreateForCurrentProcess(); - auto symbol_mapping = std::make_unique( - loaded_process, native_library_symbol_name); - if (symbol_mapping->GetMapping() != nullptr) { - return symbol_mapping; + auto loaded_process = fml::NativeLibrary::CreateForCurrentProcess(); + return DartSnapshotBuffer::CreateWithSymbolInLibrary( + loaded_process, DartSnapshot::kVMDataSymbol); +} + +std::unique_ptr ResolveVMInstructions( + const Settings& settings) { + if (settings.vm_snapshot_instr) { + return DartSnapshotBuffer::CreateWithMapping(settings.vm_snapshot_instr()); + } + + if (settings.vm_snapshot_instr_path.size() > 0) { + if (auto source = DartSnapshotBuffer::CreateWithContentsOfFile( + fml::OpenFile(settings.vm_snapshot_instr_path.c_str(), false, + fml::FilePermission::kRead), + {fml::FileMapping::Protection::kExecute})) { + return source; } } - return nullptr; + if (settings.application_library_path.size() > 0) { + auto library = + fml::NativeLibrary::Create(settings.application_library_path.c_str()); + if (auto source = DartSnapshotBuffer::CreateWithSymbolInLibrary( + library, kVMInstructionsSymbolSo)) { + return source; + } + } + + auto loaded_process = fml::NativeLibrary::CreateForCurrentProcess(); + return DartSnapshotBuffer::CreateWithSymbolInLibrary( + loaded_process, DartSnapshot::kVMInstructionsSymbol); } -static std::shared_ptr ResolveVMData( +std::unique_ptr ResolveIsolateData( const Settings& settings) { - return SearchMapping( - settings.vm_snapshot_data, // embedder_mapping_callback - settings.vm_snapshot_data_path, // file_path - settings.application_library_path, // native_library_path - DartSnapshot::kVMDataSymbol, // native_library_symbol_name - false // is_executable - ); + if (settings.isolate_snapshot_data) { + return DartSnapshotBuffer::CreateWithMapping( + settings.isolate_snapshot_data()); + } + + if (settings.isolate_snapshot_data_path.size() > 0) { + if (auto source = DartSnapshotBuffer::CreateWithContentsOfFile( + fml::OpenFile(settings.isolate_snapshot_data_path.c_str(), false, + fml::FilePermission::kRead), + {fml::FileMapping::Protection::kRead})) { + return source; + } + } + + if (settings.application_library_path.size() > 0) { + auto library = + fml::NativeLibrary::Create(settings.application_library_path.c_str()); + if (auto source = DartSnapshotBuffer::CreateWithSymbolInLibrary( + library, kIsolateDataSymbolSo)) { + return source; + } + } + + auto loaded_process = fml::NativeLibrary::CreateForCurrentProcess(); + return DartSnapshotBuffer::CreateWithSymbolInLibrary( + loaded_process, DartSnapshot::kIsolateDataSymbol); } -static std::shared_ptr ResolveVMInstructions( +std::unique_ptr ResolveIsolateInstructions( const Settings& settings) { - return SearchMapping( - settings.vm_snapshot_instr, // embedder_mapping_callback - settings.vm_snapshot_instr_path, // file_path - settings.application_library_path, // native_library_path - DartSnapshot::kVMInstructionsSymbol, // native_library_symbol_name - true // is_executable - ); -} + if (settings.isolate_snapshot_data) { + return DartSnapshotBuffer::CreateWithMapping( + settings.isolate_snapshot_instr()); + } -static std::shared_ptr ResolveIsolateData( - const Settings& settings) { - return SearchMapping( - settings.isolate_snapshot_data, // embedder_mapping_callback - settings.isolate_snapshot_data_path, // file_path - settings.application_library_path, // native_library_path - DartSnapshot::kIsolateDataSymbol, // native_library_symbol_name - false // is_executable - ); -} + if (settings.isolate_snapshot_instr_path.size() > 0) { + if (auto source = DartSnapshotBuffer::CreateWithContentsOfFile( + fml::OpenFile(settings.isolate_snapshot_instr_path.c_str(), false, + fml::FilePermission::kRead), + {fml::FileMapping::Protection::kExecute})) { + return source; + } + } -static std::shared_ptr ResolveIsolateInstructions( - const Settings& settings) { - return SearchMapping( - settings.isolate_snapshot_instr, // embedder_mapping_callback - settings.isolate_snapshot_instr_path, // file_path - settings.application_library_path, // native_library_path - DartSnapshot::kIsolateInstructionsSymbol, // native_library_symbol_name - true // is_executable - ); + if (settings.application_library_path.size() > 0) { + auto library = + fml::NativeLibrary::Create(settings.application_library_path.c_str()); + if (auto source = DartSnapshotBuffer::CreateWithSymbolInLibrary( + library, kIsolateInstructionsSymbolSo)) { + return source; + } + } + + auto loaded_process = fml::NativeLibrary::CreateForCurrentProcess(); + return DartSnapshotBuffer::CreateWithSymbolInLibrary( + loaded_process, DartSnapshot::kIsolateInstructionsSymbol); } fml::RefPtr DartSnapshot::VMSnapshotFromSettings( const Settings& settings) { TRACE_EVENT0("flutter", "DartSnapshot::VMSnapshotFromSettings"); +#if OS_WIN + return fml::MakeRefCounted( + DartSnapshotBuffer::CreateWithUnmanagedAllocation(kDartVmSnapshotData), + DartSnapshotBuffer::CreateWithUnmanagedAllocation( + kDartVmSnapshotInstructions)); +#else // OS_WIN auto snapshot = fml::MakeRefCounted(ResolveVMData(settings), // ResolveVMInstructions(settings) // @@ -159,11 +174,19 @@ fml::RefPtr DartSnapshot::VMSnapshotFromSettings( return snapshot; } return nullptr; +#endif // OS_WIN } fml::RefPtr DartSnapshot::IsolateSnapshotFromSettings( const Settings& settings) { TRACE_EVENT0("flutter", "DartSnapshot::IsolateSnapshotFromSettings"); +#if OS_WIN + return fml::MakeRefCounted( + DartSnapshotBuffer::CreateWithUnmanagedAllocation( + kDartIsolateSnapshotData), + DartSnapshotBuffer::CreateWithUnmanagedAllocation( + kDartIsolateSnapshotInstructions)); +#else // OS_WIN auto snapshot = fml::MakeRefCounted(ResolveIsolateData(settings), // ResolveIsolateInstructions(settings) // @@ -172,14 +195,15 @@ fml::RefPtr DartSnapshot::IsolateSnapshotFromSettings( return snapshot; } return nullptr; +#endif } fml::RefPtr DartSnapshot::Empty() { return fml::MakeRefCounted(nullptr, nullptr); } -DartSnapshot::DartSnapshot(std::shared_ptr data, - std::shared_ptr instructions) +DartSnapshot::DartSnapshot(std::unique_ptr data, + std::unique_ptr instructions) : data_(std::move(data)), instructions_(std::move(instructions)) {} DartSnapshot::~DartSnapshot() = default; @@ -192,12 +216,20 @@ bool DartSnapshot::IsValidForAOT() const { return data_ && instructions_; } -const uint8_t* DartSnapshot::GetDataMapping() const { - return data_ ? data_->GetMapping() : nullptr; +const DartSnapshotBuffer* DartSnapshot::GetData() const { + return data_.get(); } -const uint8_t* DartSnapshot::GetInstructionsMapping() const { - return instructions_ ? instructions_->GetMapping() : nullptr; +const DartSnapshotBuffer* DartSnapshot::GetInstructions() const { + return instructions_.get(); +} + +const uint8_t* DartSnapshot::GetDataIfPresent() const { + return data_ ? data_->GetSnapshotPointer() : nullptr; +} + +const uint8_t* DartSnapshot::GetInstructionsIfPresent() const { + return instructions_ ? instructions_->GetSnapshotPointer() : nullptr; } } // namespace flutter diff --git a/runtime/dart_snapshot.h b/runtime/dart_snapshot.h index 9e5f1a551e5..29ab3f035b5 100644 --- a/runtime/dart_snapshot.h +++ b/runtime/dart_snapshot.h @@ -11,6 +11,7 @@ #include "flutter/common/settings.h" #include "flutter/fml/macros.h" #include "flutter/fml/memory/ref_counted.h" +#include "flutter/runtime/dart_snapshot_buffer.h" namespace flutter { @@ -33,16 +34,20 @@ class DartSnapshot : public fml::RefCountedThreadSafe { bool IsValidForAOT() const; - const uint8_t* GetDataMapping() const; + const DartSnapshotBuffer* GetData() const; - const uint8_t* GetInstructionsMapping() const; + const DartSnapshotBuffer* GetInstructions() const; + + const uint8_t* GetDataIfPresent() const; + + const uint8_t* GetInstructionsIfPresent() const; private: - std::shared_ptr data_; - std::shared_ptr instructions_; + std::unique_ptr data_; + std::unique_ptr instructions_; - DartSnapshot(std::shared_ptr data, - std::shared_ptr instructions); + DartSnapshot(std::unique_ptr data, + std::unique_ptr instructions); ~DartSnapshot(); diff --git a/runtime/dart_snapshot_buffer.cc b/runtime/dart_snapshot_buffer.cc new file mode 100644 index 00000000000..fcd71e95004 --- /dev/null +++ b/runtime/dart_snapshot_buffer.cc @@ -0,0 +1,102 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "flutter/runtime/dart_snapshot_buffer.h" + +#include + +#include "flutter/fml/mapping.h" + +namespace flutter { + +class NativeLibrarySnapshotBuffer final : public DartSnapshotBuffer { + public: + NativeLibrarySnapshotBuffer(fml::RefPtr library, + const char* symbol_name) + : library_(std::move(library)) { + if (library_) { + symbol_ = library_->ResolveSymbol(symbol_name); + } + } + + const uint8_t* GetSnapshotPointer() const override { return symbol_; } + + size_t GetSnapshotSize() const override { return 0; } + + private: + fml::RefPtr library_; + const uint8_t* symbol_ = nullptr; + + FML_DISALLOW_COPY_AND_ASSIGN(NativeLibrarySnapshotBuffer); +}; + +class MappingBuffer final : public DartSnapshotBuffer { + public: + MappingBuffer(std::unique_ptr mapping) + : mapping_(std::move(mapping)) { + FML_DCHECK(mapping_); + } + + const uint8_t* GetSnapshotPointer() const override { + return mapping_->GetMapping(); + } + + size_t GetSnapshotSize() const override { return mapping_->GetSize(); } + + private: + std::unique_ptr mapping_; + + FML_DISALLOW_COPY_AND_ASSIGN(MappingBuffer); +}; + +class UnmanagedAllocation final : public DartSnapshotBuffer { + public: + UnmanagedAllocation(const uint8_t* allocation) : allocation_(allocation) {} + + const uint8_t* GetSnapshotPointer() const override { return allocation_; } + + size_t GetSnapshotSize() const override { return 0; } + + private: + const uint8_t* allocation_; + + FML_DISALLOW_COPY_AND_ASSIGN(UnmanagedAllocation); +}; + +std::unique_ptr +DartSnapshotBuffer::CreateWithSymbolInLibrary( + fml::RefPtr library, + const char* symbol_name) { + auto source = std::make_unique( + std::move(library), symbol_name); + return source->GetSnapshotPointer() == nullptr ? nullptr : std::move(source); +} + +std::unique_ptr +DartSnapshotBuffer::CreateWithContentsOfFile( + const fml::UniqueFD& fd, + std::initializer_list protection) { + return CreateWithMapping(std::make_unique(fd, protection)); +} + +std::unique_ptr DartSnapshotBuffer::CreateWithMapping( + std::unique_ptr mapping) { + if (mapping == nullptr || mapping->GetSize() == 0 || + mapping->GetMapping() == nullptr) { + return nullptr; + } + return std::make_unique(std::move(mapping)); +} + +std::unique_ptr +DartSnapshotBuffer::CreateWithUnmanagedAllocation(const uint8_t* allocation) { + if (allocation == nullptr) { + return nullptr; + } + return std::make_unique(allocation); +} + +DartSnapshotBuffer::~DartSnapshotBuffer() = default; + +} // namespace flutter diff --git a/runtime/dart_snapshot_buffer.h b/runtime/dart_snapshot_buffer.h new file mode 100644 index 00000000000..2c5887ad7e3 --- /dev/null +++ b/runtime/dart_snapshot_buffer.h @@ -0,0 +1,45 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FLUTTER_RUNTIME_DART_SNAPSHOT_BUFFER_H_ +#define FLUTTER_RUNTIME_DART_SNAPSHOT_BUFFER_H_ + +#include +#include + +#include "flutter/fml/file.h" +#include "flutter/fml/macros.h" +#include "flutter/fml/mapping.h" +#include "flutter/fml/native_library.h" + +namespace flutter { + +// TODO(chinmaygarde): Replace this with just |fml::Mapping|. +// https://github.com/flutter/flutter/issues/26782 +class DartSnapshotBuffer { + public: + static std::unique_ptr CreateWithSymbolInLibrary( + fml::RefPtr library, + const char* symbol_name); + + static std::unique_ptr CreateWithContentsOfFile( + const fml::UniqueFD& fd, + std::initializer_list protection); + + static std::unique_ptr CreateWithUnmanagedAllocation( + const uint8_t* allocation); + + static std::unique_ptr CreateWithMapping( + std::unique_ptr mapping); + + virtual ~DartSnapshotBuffer(); + + virtual const uint8_t* GetSnapshotPointer() const = 0; + + virtual size_t GetSnapshotSize() const = 0; +}; + +} // namespace flutter + +#endif // FLUTTER_RUNTIME_DART_SNAPSHOT_BUFFER_H_ diff --git a/runtime/dart_vm.cc b/runtime/dart_vm.cc index 0872ebd2801..973d5d8e86e 100644 --- a/runtime/dart_vm.cc +++ b/runtime/dart_vm.cc @@ -371,9 +371,10 @@ DartVM::DartVM(std::shared_ptr vm_data, TRACE_EVENT0("flutter", "Dart_Initialize"); Dart_InitializeParams params = {}; params.version = DART_INITIALIZE_PARAMS_CURRENT_VERSION; - params.vm_snapshot_data = vm_data_->GetVMSnapshot().GetDataMapping(); + params.vm_snapshot_data = + vm_data_->GetVMSnapshot().GetData()->GetSnapshotPointer(); params.vm_snapshot_instructions = - vm_data_->GetVMSnapshot().GetInstructionsMapping(); + vm_data_->GetVMSnapshot().GetInstructionsIfPresent(); params.create = reinterpret_cast( DartIsolate::DartIsolateCreateCallback); params.shutdown = reinterpret_cast(