mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
This reverts commit 905ddb6ca9f9dcb6b1a7cea67d502da094867623.
This commit is contained in:
parent
9a53f5f79a
commit
0fcfa0df2a
@ -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
|
||||
|
||||
@ -4,18 +4,12 @@
|
||||
|
||||
#include "flutter/fml/mapping.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace fml {
|
||||
|
||||
// FileMapping
|
||||
|
||||
uint8_t* FileMapping::GetMutableMapping() {
|
||||
return mutable_mapping_;
|
||||
}
|
||||
|
||||
// Data Mapping
|
||||
|
||||
DataMapping::DataMapping(std::vector<uint8_t> 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<fml::NativeLibrary> 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
|
||||
|
||||
@ -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<uint8_t> 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<fml::NativeLibrary> native_library,
|
||||
const char* symbol_name);
|
||||
|
||||
~SymbolMapping() override;
|
||||
|
||||
// |Mapping|
|
||||
size_t GetSize() const override;
|
||||
|
||||
// |Mapping|
|
||||
const uint8_t* GetMapping() const override;
|
||||
|
||||
private:
|
||||
fml::RefPtr<fml::NativeLibrary> native_library_;
|
||||
const uint8_t* mapping_ = nullptr;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(SymbolMapping);
|
||||
};
|
||||
|
||||
} // namespace fml
|
||||
|
||||
#endif // FLUTTER_FML_MAPPING_H_
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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<const fml::Mapping> 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<DartSnapshotBuffer> ResolveVMData(const Settings& settings) {
|
||||
if (settings.vm_snapshot_data) {
|
||||
return DartSnapshotBuffer::CreateWithMapping(settings.vm_snapshot_data());
|
||||
}
|
||||
|
||||
using Prot = fml::FileMapping::Protection;
|
||||
std::unique_ptr<fml::FileMapping> mapping;
|
||||
if (executable) {
|
||||
mapping = std::make_unique<fml::FileMapping>(
|
||||
file, std::initializer_list<Prot>{Prot::kRead, Prot::kExecute});
|
||||
} else {
|
||||
mapping = std::make_unique<fml::FileMapping>(
|
||||
file, std::initializer_list<Prot>{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<const fml::Mapping> 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<const fml::SymbolMapping>(
|
||||
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<const fml::SymbolMapping>(
|
||||
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<DartSnapshotBuffer> 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<const fml::Mapping> ResolveVMData(
|
||||
std::unique_ptr<DartSnapshotBuffer> 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<const fml::Mapping> ResolveVMInstructions(
|
||||
std::unique_ptr<DartSnapshotBuffer> 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<const fml::Mapping> 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<const fml::Mapping> 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> DartSnapshot::VMSnapshotFromSettings(
|
||||
const Settings& settings) {
|
||||
TRACE_EVENT0("flutter", "DartSnapshot::VMSnapshotFromSettings");
|
||||
#if OS_WIN
|
||||
return fml::MakeRefCounted<DartSnapshot>(
|
||||
DartSnapshotBuffer::CreateWithUnmanagedAllocation(kDartVmSnapshotData),
|
||||
DartSnapshotBuffer::CreateWithUnmanagedAllocation(
|
||||
kDartVmSnapshotInstructions));
|
||||
#else // OS_WIN
|
||||
auto snapshot =
|
||||
fml::MakeRefCounted<DartSnapshot>(ResolveVMData(settings), //
|
||||
ResolveVMInstructions(settings) //
|
||||
@ -159,11 +174,19 @@ fml::RefPtr<DartSnapshot> DartSnapshot::VMSnapshotFromSettings(
|
||||
return snapshot;
|
||||
}
|
||||
return nullptr;
|
||||
#endif // OS_WIN
|
||||
}
|
||||
|
||||
fml::RefPtr<DartSnapshot> DartSnapshot::IsolateSnapshotFromSettings(
|
||||
const Settings& settings) {
|
||||
TRACE_EVENT0("flutter", "DartSnapshot::IsolateSnapshotFromSettings");
|
||||
#if OS_WIN
|
||||
return fml::MakeRefCounted<DartSnapshot>(
|
||||
DartSnapshotBuffer::CreateWithUnmanagedAllocation(
|
||||
kDartIsolateSnapshotData),
|
||||
DartSnapshotBuffer::CreateWithUnmanagedAllocation(
|
||||
kDartIsolateSnapshotInstructions));
|
||||
#else // OS_WIN
|
||||
auto snapshot =
|
||||
fml::MakeRefCounted<DartSnapshot>(ResolveIsolateData(settings), //
|
||||
ResolveIsolateInstructions(settings) //
|
||||
@ -172,14 +195,15 @@ fml::RefPtr<DartSnapshot> DartSnapshot::IsolateSnapshotFromSettings(
|
||||
return snapshot;
|
||||
}
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
fml::RefPtr<DartSnapshot> DartSnapshot::Empty() {
|
||||
return fml::MakeRefCounted<DartSnapshot>(nullptr, nullptr);
|
||||
}
|
||||
|
||||
DartSnapshot::DartSnapshot(std::shared_ptr<const fml::Mapping> data,
|
||||
std::shared_ptr<const fml::Mapping> instructions)
|
||||
DartSnapshot::DartSnapshot(std::unique_ptr<DartSnapshotBuffer> data,
|
||||
std::unique_ptr<DartSnapshotBuffer> 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
|
||||
|
||||
@ -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<DartSnapshot> {
|
||||
|
||||
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<const fml::Mapping> data_;
|
||||
std::shared_ptr<const fml::Mapping> instructions_;
|
||||
std::unique_ptr<DartSnapshotBuffer> data_;
|
||||
std::unique_ptr<DartSnapshotBuffer> instructions_;
|
||||
|
||||
DartSnapshot(std::shared_ptr<const fml::Mapping> data,
|
||||
std::shared_ptr<const fml::Mapping> instructions);
|
||||
DartSnapshot(std::unique_ptr<DartSnapshotBuffer> data,
|
||||
std::unique_ptr<DartSnapshotBuffer> instructions);
|
||||
|
||||
~DartSnapshot();
|
||||
|
||||
|
||||
102
runtime/dart_snapshot_buffer.cc
Normal file
102
runtime/dart_snapshot_buffer.cc
Normal file
@ -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 <utility>
|
||||
|
||||
#include "flutter/fml/mapping.h"
|
||||
|
||||
namespace flutter {
|
||||
|
||||
class NativeLibrarySnapshotBuffer final : public DartSnapshotBuffer {
|
||||
public:
|
||||
NativeLibrarySnapshotBuffer(fml::RefPtr<fml::NativeLibrary> 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<fml::NativeLibrary> library_;
|
||||
const uint8_t* symbol_ = nullptr;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(NativeLibrarySnapshotBuffer);
|
||||
};
|
||||
|
||||
class MappingBuffer final : public DartSnapshotBuffer {
|
||||
public:
|
||||
MappingBuffer(std::unique_ptr<fml::Mapping> 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<fml::Mapping> 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>
|
||||
DartSnapshotBuffer::CreateWithSymbolInLibrary(
|
||||
fml::RefPtr<fml::NativeLibrary> library,
|
||||
const char* symbol_name) {
|
||||
auto source = std::make_unique<NativeLibrarySnapshotBuffer>(
|
||||
std::move(library), symbol_name);
|
||||
return source->GetSnapshotPointer() == nullptr ? nullptr : std::move(source);
|
||||
}
|
||||
|
||||
std::unique_ptr<DartSnapshotBuffer>
|
||||
DartSnapshotBuffer::CreateWithContentsOfFile(
|
||||
const fml::UniqueFD& fd,
|
||||
std::initializer_list<fml::FileMapping::Protection> protection) {
|
||||
return CreateWithMapping(std::make_unique<fml::FileMapping>(fd, protection));
|
||||
}
|
||||
|
||||
std::unique_ptr<DartSnapshotBuffer> DartSnapshotBuffer::CreateWithMapping(
|
||||
std::unique_ptr<fml::Mapping> mapping) {
|
||||
if (mapping == nullptr || mapping->GetSize() == 0 ||
|
||||
mapping->GetMapping() == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
return std::make_unique<MappingBuffer>(std::move(mapping));
|
||||
}
|
||||
|
||||
std::unique_ptr<DartSnapshotBuffer>
|
||||
DartSnapshotBuffer::CreateWithUnmanagedAllocation(const uint8_t* allocation) {
|
||||
if (allocation == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
return std::make_unique<UnmanagedAllocation>(allocation);
|
||||
}
|
||||
|
||||
DartSnapshotBuffer::~DartSnapshotBuffer() = default;
|
||||
|
||||
} // namespace flutter
|
||||
45
runtime/dart_snapshot_buffer.h
Normal file
45
runtime/dart_snapshot_buffer.h
Normal file
@ -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 <initializer_list>
|
||||
#include <memory>
|
||||
|
||||
#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<DartSnapshotBuffer> CreateWithSymbolInLibrary(
|
||||
fml::RefPtr<fml::NativeLibrary> library,
|
||||
const char* symbol_name);
|
||||
|
||||
static std::unique_ptr<DartSnapshotBuffer> CreateWithContentsOfFile(
|
||||
const fml::UniqueFD& fd,
|
||||
std::initializer_list<fml::FileMapping::Protection> protection);
|
||||
|
||||
static std::unique_ptr<DartSnapshotBuffer> CreateWithUnmanagedAllocation(
|
||||
const uint8_t* allocation);
|
||||
|
||||
static std::unique_ptr<DartSnapshotBuffer> CreateWithMapping(
|
||||
std::unique_ptr<fml::Mapping> 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_
|
||||
@ -371,9 +371,10 @@ DartVM::DartVM(std::shared_ptr<const DartVMData> 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<decltype(params.create)>(
|
||||
DartIsolate::DartIsolateCreateCallback);
|
||||
params.shutdown = reinterpret_cast<decltype(params.shutdown)>(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user