Flutter Engine
dart_utils Namespace Reference

Classes

class  BuildInfo
 
class  BuildInfoTest
 
class  ElfSnapshot
 
class  MappedResource
 
class  RootInspectNode
 
class  RunnerTemp
 
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)
 
void Check (bool condition, const char *tag, const char *message="")
 
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)
 
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 26 of file inlines.h.

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

26  {
27  return SIZE;
28 }

◆ Check()

void dart_utils::Check ( bool  condition,
const char *  tag,
const char *  message = "" 
)
inline

◆ 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 108 of file handle_exception.cc.

References LOG_TAG, and result.

Referenced by flutter_runner::ComponentV1::Create(), flutter_runner::ComponentV2::Create(), and HandleIfException().

111  {
112  fuchsia::feedback::CrashReport crash_report =
113  BuildCrashReport(component_url, error, stack_trace);
114 
115  fuchsia::feedback::CrashReporterPtr crash_reporter =
116  services->Connect<fuchsia::feedback::CrashReporter>();
117  crash_reporter->File(
118  std::move(crash_report),
119  [](fuchsia::feedback::CrashReporter_File_Result result) {
120  if (result.is_err()) {
121  FX_LOGF(ERROR, LOG_TAG, "Failed to report Dart exception: %d (%s)",
122  result.err(), zx_status_get_string(result.err()));
123  }
124  });
125 }
const uint8_t uint32_t uint32_t GError ** error
GAsyncResult * result
#define LOG_TAG
Definition: logging.h:11

◆ HandleIfException()

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

Definition at line 93 of file handle_exception.cc.

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

Referenced by dart_runner::DartComponentController::Main(), dart_runner::DartComponentControllerV2::Run(), and dart_runner::DartTestComponentControllerV2::Run().

95  {
96  if (!Dart_IsError(result) || !Dart_ErrorHasException(result)) {
97  return;
98  }
99 
100  const std::string error =
101  tonic::StdStringFromDart(Dart_ToString(Dart_ErrorGetException(result)));
102  const std::string stack_trace =
103  tonic::StdStringFromDart(Dart_ToString(Dart_ErrorGetStackTrace(result)));
104 
105  return HandleException(services, component_url, error, stack_trace);
106 }
const uint8_t uint32_t uint32_t GError ** error
void HandleException(std::shared_ptr<::sys::ServiceDirectory > services, const std::string &component_url, const std::string &error, const std::string &stack_trace)
GAsyncResult * result
std::string StdStringFromDart(Dart_Handle handle)

◆ IsSizeValid()

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

Definition at line 102 of file vmo.cc.

102  {
103  size_t vmo_size;
104  zx_status_t status = buffer.vmo.get_size(&vmo_size);
105  if (status == ZX_OK) {
106  *is_valid = vmo_size >= buffer.size;
107  } else {
108  *is_valid = false;
109  }
110  return status;
111 }
static const uint8_t buffer[]

◆ OpenFdExec()

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

Definition at line 105 of file mapped_resource.cc.

References Check(), LOG_TAG, and result.

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

105  {
106  int fd = -1;
107  zx_status_t result;
108  if (dirfd == AT_FDCWD) {
109  // fdio_open_fd_at does not support AT_FDCWD, by design. Use fdio_open_fd
110  // and expect an absolute path for that usage pattern.
111  dart_utils::Check(path[0] == '/', LOG_TAG);
112  result = fdio_open_fd(
113  path.c_str(),
114  static_cast<uint32_t>(fuchsia::io::OpenFlags::RIGHT_READABLE |
115  fuchsia::io::OpenFlags::RIGHT_EXECUTABLE),
116  &fd);
117  } else {
118  dart_utils::Check(path[0] != '/', LOG_TAG);
119  result = fdio_open_fd_at(
120  dirfd, path.c_str(),
121  static_cast<uint32_t>(fuchsia::io::OpenFlags::RIGHT_READABLE |
122  fuchsia::io::OpenFlags::RIGHT_EXECUTABLE),
123  &fd);
124  }
125  if (result != ZX_OK) {
126  FX_LOGF(ERROR, LOG_TAG, "fdio_open_fd_at(%s) failed: %s", path.c_str(),
127  zx_status_get_string(result));
128  return -1;
129  }
130  return fd;
131 }
GAsyncResult * result
void Check(bool condition, const char *tag, const char *message="")
Definition: inlines.h:12
#define LOG_TAG
Definition: logging.h:11
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 29 of file mapped_resource.cc.

References Check(), LOG_TAG, result, VmoFromFilename(), and VmoFromFilenameAt().

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

32  {
33  TRACE_DURATION("dart", "LoadFromNamespace", "path", path);
34 
35  if (namespc == nullptr) {
36  // Opening a file in the root namespace expects an absolute path.
37  dart_utils::Check(path[0] == '/', LOG_TAG);
38  if (!VmoFromFilename(path, executable, resource_vmo)) {
39  return false;
40  }
41  } else {
42  // openat of a path with a leading '/' ignores the namespace fd.
43  // require a relative path.
44  dart_utils::Check(path[0] != '/', LOG_TAG);
45 
46  auto root_dir = fdio_ns_opendir(namespc);
47  if (root_dir < 0) {
48  FX_LOG(ERROR, LOG_TAG, "Failed to open namespace directory");
49  return false;
50  }
51 
52  bool result =
53  dart_utils::VmoFromFilenameAt(root_dir, path, executable, resource_vmo);
54  close(root_dir);
55  if (!result) {
56  return result;
57  }
58  }
59 
60  return true;
61 }
GAsyncResult * result
bool VmoFromFilenameAt(int dirfd, const std::string &filename, bool executable, fuchsia::mem::Buffer *buffer)
Definition: vmo.cc:80
void Check(bool condition, const char *tag, const char *message="")
Definition: inlines.h:12
#define LOG_TAG
Definition: logging.h:11
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
bool VmoFromFilename(const std::string &filename, bool executable, fuchsia::mem::Buffer *buffer)
Definition: vmo.cc:56

◆ ReadFileToString()

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

Definition at line 56 of file files.cc.

References ReadFileToStringAt().

Referenced by flutter_runner::ComponentV1::Create(), flutter_runner::ComponentV2::Create(), RegisterProfilerSymbols(), and flutter_runner::RegisterProfilerSymbols().

56  {
57  return ReadFileToStringAt(AT_FDCWD, path, result);
58 }
bool ReadFileToStringAt(int dirfd, const std::string &path, std::string *result)
Definition: files.cc:60
GAsyncResult * result
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

◆ ReadFileToStringAt()

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

Definition at line 60 of file files.cc.

Referenced by ReadFileToString().

62  {
63  int fd = openat(dirfd, path.c_str(), O_RDONLY);
64  bool status = ReadFileDescriptor(fd, result);
65  close(fd);
66  return status;
67 }
GAsyncResult * result
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

◆ TEST_F() [1/2]

dart_utils::TEST_F ( BuildInfoTest  ,
AllPropertiesAreDefined   
)

Definition at line 37 of file build_info_unittests.cc.

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

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.

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(), inspect_node_name, and node.

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)
G_BEGIN_DECLS const FlutterSemanticsNode * node

◆ VmoFromFilename()

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

Definition at line 56 of file vmo.cc.

References flags, LOG_TAG, and result.

Referenced by OpenVmo().

58  {
59  // Note: the implementation here cannot be shared with VmoFromFilenameAt
60  // because fdio_open_fd_at does not aim to provide POSIX compatibility, and
61  // thus does not handle AT_FDCWD as dirfd.
62  auto flags = fuchsia::io::OpenFlags::RIGHT_READABLE;
63  if (executable) {
64  flags |= fuchsia::io::OpenFlags::RIGHT_EXECUTABLE;
65  }
66 
67  int fd;
68  const zx_status_t status =
69  fdio_open_fd(filename.c_str(), static_cast<uint32_t>(flags), &fd);
70  if (status != ZX_OK) {
71  FX_LOGF(ERROR, LOG_TAG, "fdio_open_fd(\"%s\", %08x) failed: %s",
72  filename.c_str(), flags, zx_status_get_string(status));
73  return false;
74  }
75  bool result = VmoFromFd(fd, executable, buffer);
76  close(fd);
77  return result;
78 }
GAsyncResult * result
FlutterSemanticsFlag flags
#define LOG_TAG
Definition: logging.h:11
static const uint8_t buffer[]

◆ VmoFromFilenameAt()

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

Definition at line 80 of file vmo.cc.

References flags, LOG_TAG, and result.

Referenced by OpenVmo().

83  {
84  auto flags = fuchsia::io::OpenFlags::RIGHT_READABLE;
85  if (executable) {
86  flags |= fuchsia::io::OpenFlags::RIGHT_EXECUTABLE;
87  }
88 
89  int fd;
90  const zx_status_t status = fdio_open_fd_at(dirfd, filename.c_str(),
91  static_cast<uint32_t>(flags), &fd);
92  if (status != ZX_OK) {
93  FX_LOGF(ERROR, LOG_TAG, "fdio_open_fd_at(%d, \"%s\", %08x) failed: %s",
94  dirfd, filename.c_str(), flags, zx_status_get_string(status));
95  return false;
96  }
97  bool result = VmoFromFd(fd, executable, buffer);
98  close(fd);
99  return result;
100 }
GAsyncResult * result
FlutterSemanticsFlag flags
#define LOG_TAG
Definition: logging.h:11
static const uint8_t buffer[]

◆ WriteFile()

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

Definition at line 69 of file files.cc.

Referenced by flutter::DartVM::GetVMLaunchCount().

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 }
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 observatory The hostname IP address on which the Dart Observatory should be served If not defaults to or::depending on whether ipv6 is specified disable Disable the Dart Observatory The observatory is never available in release mode Bind to the IPv6 localhost address for the Dart Observatory Ignored if observatory host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets Path to the Flutter assets directory enable service port Allow the VM service to fallback to automatic port selection if binding to a specified port fails trace Trace early application lifecycle Automatically switches to an endless trace buffer trace skia Filters out all Skia trace event categories except those that are specified in this comma separated list dump skp on shader Automatically dump the skp that triggers new shader compilations This is useful for writing custom ShaderWarmUp to reduce jank By this is not enabled to reduce the overhead purge persistent Remove all existing persistent cache This is mainly for debugging purposes such as reproducing the shader compilation jank use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all 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:226
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition: switches.h:41
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