Flutter Engine
 
Loading...
Searching...
No Matches
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}

Referenced by dart_runner::DartRunner::DartRunner().

◆ 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:101

References FML_LOG, and i.

◆ 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

References error, and FML_LOG.

Referenced by HandleIfException().

◆ 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 {
93 if (!Dart_IsError(result) || !Dart_ErrorHasException(result)) {
94 return;
95 }
96
97 const std::string error =
98 tonic::StdStringFromDart(Dart_ToString(Dart_ErrorGetException(result)));
99 const std::string stack_trace =
100 tonic::StdStringFromDart(Dart_ToString(Dart_ErrorGetStackTrace(result)));
101
102 return HandleException(services, component_url, error, stack_trace);
103}
std::string StdStringFromDart(Dart_Handle handle)

References error, HandleException(), and tonic::StdStringFromDart().

◆ IsSizeValid()

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

Definition at line 90 of file vmo.cc.

90 {
91 size_t vmo_size;
92 zx_status_t status = buffer.vmo.get_size(&vmo_size);
93 if (status == ZX_OK) {
94 *is_valid = vmo_size >= buffer.size;
95 } else {
96 *is_valid = false;
97 }
98 return status;
99}

◆ 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 // fdio_open3_fd_at only allows relative paths
107 const char* path_ptr = path.c_str();
108 if (path_ptr && path_ptr[0] == '/') {
109 ++path_ptr;
110 }
111 zx_status_t result = fdio_open3_fd_at(
112 dirfd, path_ptr,
113 uint64_t{fuchsia::io::PERM_READABLE | fuchsia::io::PERM_EXECUTABLE}, &fd);
114 if (result != ZX_OK) {
115 FML_LOG(ERROR) << "fdio_open3_fd_at(" << path << ") "
116 << "failed: " << zx_status_get_string(result);
117 return -1;
118 }
119 return fd;
120}
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 switch_defs.h:52

References FML_LOG.

Referenced by dart_utils::ElfSnapshot::Load().

◆ 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}
#define FML_CHECK(condition)
Definition logging.h:104
bool VmoFromFilenameAt(int dirfd, const std::string &filename, bool executable, fuchsia::mem::Buffer *buffer)
Definition vmo.cc:63
bool VmoFromFilename(const std::string &filename, bool executable, fuchsia::mem::Buffer *buffer)
Definition vmo.cc:57

References FML_CHECK, FML_LOG, VmoFromFilename(), and VmoFromFilenameAt().

Referenced by dart_utils::MappedResource::LoadFromNamespace().

◆ 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

References ReadFileToStringAt().

Referenced by RegisterProfilerSymbols(), and flutter_runner::RegisterProfilerSymbols().

◆ 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}

Referenced by ReadFileToString().

◆ 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}

References dart_utils::BuildInfo::DartSdkGitRevision(), dart_utils::BuildInfo::DartSdkSemanticVersion(), dart_utils::BuildInfo::FlutterEngineGitRevision(), and dart_utils::BuildInfo::FuchsiaSdkVersion().

◆ 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}
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)

References checkProperty(), dart_utils::RootInspectNode::CreateRootChild(), dart_utils::BuildInfo::DartSdkGitRevision(), dart_utils::BuildInfo::DartSdkSemanticVersion(), dart_utils::BuildInfo::Dump(), dart_utils::BuildInfo::FlutterEngineGitRevision(), dart_utils::BuildInfo::FuchsiaSdkVersion(), dart_utils::RootInspectNode::GetInspector(), and inspect_node_name.

◆ 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 return VmoFromFilenameAt(AT_FDCWD, filename, executable, buffer);
61}

References VmoFromFilenameAt().

Referenced by OpenVmo().

◆ VmoFromFilenameAt()

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

Definition at line 63 of file vmo.cc.

66 {
67 fuchsia::io::Flags flags = fuchsia::io::PERM_READABLE;
68 if (executable) {
69 flags |= fuchsia::io::PERM_EXECUTABLE;
70 }
71 // fdio_open3_fd_at only allows relative paths
72 const char* path = filename.c_str();
73 if (path && path[0] == '/') {
74 ++path;
75 }
76 int fd;
77 const zx_status_t status =
78 fdio_open3_fd_at(dirfd, path, uint64_t{flags}, &fd);
79 if (status != ZX_OK) {
80 FML_LOG(ERROR) << "fdio_open3_fd_at(" << dirfd << ", \"" << filename
81 << "\", " << std::hex << uint64_t{flags}
82 << ") failed: " << zx_status_get_string(status);
83 return false;
84 }
85 bool result = VmoFromFd(fd, executable, buffer);
86 close(fd);
87 return result;
88}

References FML_LOG.

Referenced by flutter_runner::FileInNamespaceBuffer::FileInNamespaceBuffer(), OpenVmo(), and VmoFromFilename().

◆ 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}
std::shared_ptr< const fml::Mapping > data

References data.