Flutter Engine
The Flutter Engine
Classes | Functions
dart_utils Namespace Reference

Classes

class  BuildInfo
 
class  BuildInfoTest
 
class  ElfSnapshot
 
class  MappedResource
 
class  RootInspectNode
 
class  VMServiceObject
 

Functions

 TEST_F (BuildInfoTest, AllPropertiesAreDefined)
 
 TEST_F (BuildInfoTest, AllPropertiesAreDumped)
 
bool ReadFileToString (const std::string &path, std::string *result)
 
bool ReadFileToStringAt (int dirfd, const std::string &path, std::string *result)
 
bool WriteFile (const std::string &path, const char *data, ssize_t size)
 
void HandleIfException (std::shared_ptr<::sys::ServiceDirectory > services, const std::string &component_url, Dart_Handle result)
 
void HandleException (std::shared_ptr<::sys::ServiceDirectory > services, const std::string &component_url, const std::string &error, const std::string &stack_trace)
 
template<size_t SIZE, typename T >
size_t ArraySize (T(&array)[SIZE])
 
static bool OpenVmo (fuchsia::mem::Buffer *resource_vmo, fdio_ns_t *namespc, const std::string &path, bool executable)
 
static int OpenFdExec (const std::string &path, int dirfd)
 
void BindTemp (fdio_ns_t *ns)
 
bool VmoFromFilename (const std::string &filename, bool executable, fuchsia::mem::Buffer *buffer)
 
bool VmoFromFilenameAt (int dirfd, const std::string &filename, bool executable, fuchsia::mem::Buffer *buffer)
 
zx_status_t IsSizeValid (const fuchsia::mem::Buffer &buffer, bool *is_valid)
 

Function Documentation

◆ ArraySize()

template<size_t SIZE, typename T >
size_t dart_utils::ArraySize ( T(&)  array[SIZE])
inline

Definition at line 11 of file inlines.h.

11 {
12 return SIZE;
13}
#define SIZE

◆ BindTemp()

void dart_utils::BindTemp ( fdio_ns_t *  ns)

Definition at line 23 of file tempfs.cc.

23 {
24 // TODO(zra): Should isolates share a /tmp file system within a process, or
25 // should isolates each get their own private file system for /tmp? For now,
26 // sharing the process-wide /tmp simplifies hot reload since the hot reload
27 // devfs requires sharing between the service isolate and the app isolates.
28 fdio_flat_namespace_t* rootns;
29 if (zx_status_t status = fdio_ns_export_root(&rootns); status != ZX_OK) {
30 FML_LOG(ERROR) << "Failed to export root ns: "
31 << zx_status_get_string(status);
32 return;
33 }
34
35 zx_handle_t tmp_dir_handle;
36 for (size_t i = 0; i < rootns->count; i++) {
37 if (std::string_view{rootns->path[i]} == kTmpPath) {
38 tmp_dir_handle = std::exchange(rootns->handle[i], ZX_HANDLE_INVALID);
39 }
40 }
41 fdio_ns_free_flat_ns(rootns);
42
43 if (zx_status_t status = fdio_ns_bind(ns, kTmpPath, tmp_dir_handle);
44 status != ZX_OK) {
45 zx_handle_close(tmp_dir_handle);
46 FML_LOG(ERROR) << "Failed to bind /tmp directory into isolate namespace: "
47 << zx_status_get_string(status);
48 }
49}
#define FML_LOG(severity)
Definition: logging.h:82
#define ERROR(message)
Definition: elf_loader.cc:260

◆ HandleException()

void dart_utils::HandleException ( std::shared_ptr<::sys::ServiceDirectory >  services,
const std::string &  component_url,
const std::string &  error,
const std::string &  stack_trace 
)

Definition at line 105 of file handle_exception.cc.

108 {
109 fuchsia::feedback::CrashReport crash_report =
110 BuildCrashReport(component_url, error, stack_trace);
111
112 fuchsia::feedback::CrashReporterPtr crash_reporter =
113 services->Connect<fuchsia::feedback::CrashReporter>();
114 crash_reporter->FileReport(
115 std::move(crash_report),
116 [](fuchsia::feedback::CrashReporter_FileReport_Result result) {
117 if (result.is_err()) {
118 FML_LOG(ERROR) << "Failed to report Dart exception: "
119 << static_cast<uint32_t>(result.err());
120 }
121 });
122}
const uint8_t uint32_t uint32_t GError ** error
GAsyncResult * result

◆ HandleIfException()

void dart_utils::HandleIfException ( std::shared_ptr<::sys::ServiceDirectory >  services,
const std::string &  component_url,
Dart_Handle  result 
)

Definition at line 90 of file handle_exception.cc.

92 {
94 return;
95 }
96
97 const std::string error =
99 const std::string stack_trace =
101
102 return HandleException(services, component_url, error, stack_trace);
103}
DART_EXPORT Dart_Handle Dart_ErrorGetStackTrace(Dart_Handle handle)
DART_EXPORT Dart_Handle Dart_ErrorGetException(Dart_Handle handle)
DART_EXPORT bool Dart_ErrorHasException(Dart_Handle handle)
DART_EXPORT bool Dart_IsError(Dart_Handle handle)
DART_EXPORT Dart_Handle Dart_ToString(Dart_Handle object)
void HandleException(std::shared_ptr<::sys::ServiceDirectory > services, const std::string &component_url, const std::string &error, const std::string &stack_trace)
std::string StdStringFromDart(Dart_Handle handle)

◆ IsSizeValid()

zx_status_t dart_utils::IsSizeValid ( const fuchsia::mem::Buffer &  buffer,
bool *  is_valid 
)

Definition at line 105 of file vmo.cc.

105 {
106 size_t vmo_size;
107 zx_status_t status = buffer.vmo.get_size(&vmo_size);
108 if (status == ZX_OK) {
109 *is_valid = vmo_size >= buffer.size;
110 } else {
111 *is_valid = false;
112 }
113 return status;
114}
static bool is_valid(SkISize dim)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126

◆ OpenFdExec()

static int dart_utils::OpenFdExec ( const std::string &  path,
int  dirfd 
)
static

Definition at line 104 of file mapped_resource.cc.

104 {
105 int fd = -1;
106 zx_status_t result;
107 if (dirfd == AT_FDCWD) {
108 // fdio_open_fd_at does not support AT_FDCWD, by design. Use fdio_open_fd
109 // and expect an absolute path for that usage pattern.
110 FML_CHECK(path[0] == '/');
111 result = fdio_open_fd(
112 path.c_str(),
113 static_cast<uint32_t>(fuchsia::io::OpenFlags::RIGHT_READABLE |
114 fuchsia::io::OpenFlags::RIGHT_EXECUTABLE),
115 &fd);
116 } else {
117 FML_CHECK(path[0] != '/');
118 result = fdio_open_fd_at(
119 dirfd, path.c_str(),
120 static_cast<uint32_t>(fuchsia::io::OpenFlags::RIGHT_READABLE |
121 fuchsia::io::OpenFlags::RIGHT_EXECUTABLE),
122 &fd);
123 }
124 if (result != ZX_OK) {
125 FML_LOG(ERROR) << "fdio_open_fd_at(" << path << ") "
126 << "failed: " << zx_status_get_string(result);
127 return -1;
128 }
129 return fd;
130}
#define FML_CHECK(condition)
Definition: logging.h:85
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57

◆ OpenVmo()

static bool dart_utils::OpenVmo ( fuchsia::mem::Buffer *  resource_vmo,
fdio_ns_t *  namespc,
const std::string &  path,
bool  executable 
)
static

Definition at line 28 of file mapped_resource.cc.

31 {
32 TRACE_DURATION("dart", "LoadFromNamespace", "path", path);
33
34 if (namespc == nullptr) {
35 // Opening a file in the root namespace expects an absolute path.
36 FML_CHECK(path[0] == '/');
37 if (!VmoFromFilename(path, executable, resource_vmo)) {
38 return false;
39 }
40 } else {
41 // openat of a path with a leading '/' ignores the namespace fd.
42 // require a relative path.
43 FML_CHECK(path[0] != '/');
44
45 auto root_dir = fdio_ns_opendir(namespc);
46 if (root_dir < 0) {
47 FML_LOG(ERROR) << "Failed to open namespace directory";
48 return false;
49 }
50
51 bool result =
52 dart_utils::VmoFromFilenameAt(root_dir, path, executable, resource_vmo);
53 close(root_dir);
54 if (!result) {
55 return result;
56 }
57 }
58
59 return true;
60}
bool VmoFromFilenameAt(int dirfd, const std::string &filename, bool executable, fuchsia::mem::Buffer *buffer)
Definition: vmo.cc:82
bool VmoFromFilename(const std::string &filename, bool executable, fuchsia::mem::Buffer *buffer)
Definition: vmo.cc:57

◆ ReadFileToString()

bool dart_utils::ReadFileToString ( const std::string &  path,
std::string *  result 
)

Definition at line 56 of file files.cc.

56 {
57 return ReadFileToStringAt(AT_FDCWD, path, result);
58}
bool ReadFileToStringAt(int dirfd, const std::string &path, std::string *result)
Definition: files.cc:60

◆ ReadFileToStringAt()

bool dart_utils::ReadFileToStringAt ( int  dirfd,
const std::string &  path,
std::string *  result 
)

Definition at line 60 of file files.cc.

62 {
63 int fd = openat(dirfd, path.c_str(), O_RDONLY);
64 bool status = ReadFileDescriptor(fd, result);
65 close(fd);
66 return status;
67}

◆ TEST_F() [1/2]

dart_utils::TEST_F ( BuildInfoTest  ,
AllPropertiesAreDefined   
)

Definition at line 37 of file build_info_unittests.cc.

37 {
38 EXPECT_NE(BuildInfo::DartSdkGitRevision(), "{{DART_SDK_GIT_REVISION}}");
39 EXPECT_NE(BuildInfo::DartSdkSemanticVersion(),
40 "{{DART_SDK_SEMANTIC_VERSION}}");
41 EXPECT_NE(BuildInfo::FlutterEngineGitRevision(),
42 "{{FLUTTER_ENGINE_GIT_REVISION}}");
43 EXPECT_NE(BuildInfo::FuchsiaSdkVersion(), "{{FUCHSIA_SDK_VERSION}}");
44}

◆ TEST_F() [2/2]

dart_utils::TEST_F ( BuildInfoTest  ,
AllPropertiesAreDumped   
)

Definition at line 46 of file build_info_unittests.cc.

46 {
47 inspect::Node node =
49 BuildInfo::Dump(node);
50 inspect::Hierarchy root =
51 inspect::ReadFromVmo(
52 std::move(
54 .take_value();
55 checkProperty(root, "dart_sdk_git_revision", BuildInfo::DartSdkGitRevision());
56 checkProperty(root, "dart_sdk_semantic_version",
57 BuildInfo::DartSdkSemanticVersion());
58 checkProperty(root, "flutter_engine_git_revision",
59 BuildInfo::FlutterEngineGitRevision());
60 checkProperty(root, "fuchsia_sdk_version", BuildInfo::FuchsiaSdkVersion());
61}
void Dump(const SkPath &path)
const std::string & inspect_node_name
void checkProperty(inspect::Hierarchy &root, const std::string &name, const std::string &expected_value)
static inspect::Inspector * GetInspector()
static inspect::Node CreateRootChild(const std::string &name)
string root
Definition: scale_cpu.py:20

◆ VmoFromFilename()

bool dart_utils::VmoFromFilename ( const std::string &  filename,
bool  executable,
fuchsia::mem::Buffer *  buffer 
)

Definition at line 57 of file vmo.cc.

59 {
60 // Note: the implementation here cannot be shared with VmoFromFilenameAt
61 // because fdio_open_fd_at does not aim to provide POSIX compatibility, and
62 // thus does not handle AT_FDCWD as dirfd.
63 auto flags = fuchsia::io::OpenFlags::RIGHT_READABLE;
64 if (executable) {
65 flags |= fuchsia::io::OpenFlags::RIGHT_EXECUTABLE;
66 }
67
68 int fd;
69 const zx_status_t status =
70 fdio_open_fd(filename.c_str(), static_cast<uint32_t>(flags), &fd);
71 if (status != ZX_OK) {
72 FML_LOG(ERROR) << "fdio_open_fd(\"" << filename << "\", " << std::hex
73 << static_cast<uint32_t>(flags)
74 << ") failed: " << zx_status_get_string(status);
75 return false;
76 }
77 bool result = VmoFromFd(fd, executable, buffer);
78 close(fd);
79 return result;
80}
FlutterSemanticsFlag flags

◆ VmoFromFilenameAt()

bool dart_utils::VmoFromFilenameAt ( int  dirfd,
const std::string &  filename,
bool  executable,
fuchsia::mem::Buffer *  buffer 
)

Definition at line 82 of file vmo.cc.

85 {
86 auto flags = fuchsia::io::OpenFlags::RIGHT_READABLE;
87 if (executable) {
88 flags |= fuchsia::io::OpenFlags::RIGHT_EXECUTABLE;
89 }
90
91 int fd;
92 const zx_status_t status = fdio_open_fd_at(dirfd, filename.c_str(),
93 static_cast<uint32_t>(flags), &fd);
94 if (status != ZX_OK) {
95 FML_LOG(ERROR) << "fdio_open_fd_at(" << dirfd << ", \"" << filename
96 << "\", " << std::hex << static_cast<uint32_t>(flags)
97 << ") failed: " << zx_status_get_string(status);
98 return false;
99 }
100 bool result = VmoFromFd(fd, executable, buffer);
101 close(fd);
102 return result;
103}

◆ WriteFile()

bool dart_utils::WriteFile ( const std::string &  path,
const char *  data,
ssize_t  size 
)

Definition at line 69 of file files.cc.

69 {
70 int fd = openat(AT_FDCWD, path.c_str(), O_CREAT | O_TRUNC | O_WRONLY, 0666);
71 if (fd < 0) {
72 return false;
73 }
74 bool status = WriteFileDescriptor(fd, data, size);
75 close(fd);
76 return status;
77}
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63