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

◆ Check()

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

Definition at line 12 of file inlines.h.

Referenced by base::internal::CheckMathOp(), base::internal::DstRangeRelationToSrcRange(), OpenFdExec(), OpenVmo(), and flutter_runner::VulkanSurface::SignalWritesFinished().

12  {
13  if (!condition) {
14  FX_LOG(FATAL, tag, message);
15  }
16 }

◆ 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(), and dart_runner::DartComponentControllerV2::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 95 of file vmo.cc.

95  {
96  size_t vmo_size;
97  zx_status_t status = buffer.vmo.get_size(&vmo_size);
98  if (status == ZX_OK) {
99  *is_valid = vmo_size >= buffer.size;
100  } else {
101  *is_valid = false;
102  }
103  return status;
104 }
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  fuchsia::io::OPEN_RIGHT_READABLE | fuchsia::io::OPEN_RIGHT_EXECUTABLE,
115  &fd);
116  } else {
117  dart_utils::Check(path[0] != '/', LOG_TAG);
118  result = fdio_open_fd_at(
119  dirfd, path.c_str(),
120  fuchsia::io::OPEN_RIGHT_READABLE | fuchsia::io::OPEN_RIGHT_EXECUTABLE,
121  &fd);
122  }
123  if (result != ZX_OK) {
124  FX_LOGF(ERROR, LOG_TAG, "fdio_open_fd_at(%s) failed: %s", path.c_str(),
125  zx_status_get_string(result));
126  return -1;
127  }
128  return fd;
129 }
DEF_SWITCHES_START snapshot asset path
Definition: switches.h:32
GAsyncResult * result
void Check(bool condition, const char *tag, const char *message="")
Definition: inlines.h:12
#define LOG_TAG
Definition: logging.h:11

◆ 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 }
DEF_SWITCHES_START snapshot asset path
Definition: switches.h:32
GAsyncResult * result
bool VmoFromFilenameAt(int dirfd, const std::string &filename, bool executable, fuchsia::mem::Buffer *buffer)
Definition: vmo.cc:76
void Check(bool condition, const char *tag, const char *message="")
Definition: inlines.h:12
#define LOG_TAG
Definition: logging.h:11
bool VmoFromFilename(const std::string &filename, bool executable, fuchsia::mem::Buffer *buffer)
Definition: vmo.cc:54

◆ 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 }
DEF_SWITCHES_START snapshot asset path
Definition: switches.h:32
bool ReadFileToStringAt(int dirfd, const std::string &path, std::string *result)
Definition: files.cc:60
GAsyncResult * result

◆ 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 }
DEF_SWITCHES_START snapshot asset path
Definition: switches.h:32
GAsyncResult * result

◆ 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()
const FlutterSemanticsNode * node
Definition: fl_view.cc:83
static inspect::Node CreateRootChild(const std::string &name)

◆ VmoFromFilename()

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

Definition at line 54 of file vmo.cc.

References flags, LOG_TAG, and result.

Referenced by OpenVmo().

56  {
57  // Note: the implementation here cannot be shared with VmoFromFilenameAt
58  // because fdio_open_fd_at does not aim to provide POSIX compatibility, and
59  // thus does not handle AT_FDCWD as dirfd.
60  uint32_t flags = fuchsia::io::OPEN_RIGHT_READABLE |
61  (executable ? fuchsia::io::OPEN_RIGHT_EXECUTABLE : 0);
62  zx_status_t status;
63  int fd;
64 
65  status = fdio_open_fd(filename.c_str(), flags, &fd);
66  if (status != ZX_OK) {
67  FX_LOGF(ERROR, LOG_TAG, "fdio_open_fd(\"%s\", %08x) failed: %s",
68  filename.c_str(), flags, zx_status_get_string(status));
69  return false;
70  }
71  bool result = VmoFromFd(fd, executable, buffer);
72  close(fd);
73  return result;
74 }
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 76 of file vmo.cc.

References flags, LOG_TAG, and result.

Referenced by OpenVmo().

79  {
80  uint32_t flags = fuchsia::io::OPEN_RIGHT_READABLE |
81  (executable ? fuchsia::io::OPEN_RIGHT_EXECUTABLE : 0);
82  zx_status_t status;
83  int fd;
84  status = fdio_open_fd_at(dirfd, filename.c_str(), flags, &fd);
85  if (status != ZX_OK) {
86  FX_LOGF(ERROR, LOG_TAG, "fdio_open_fd_at(%d, \"%s\", %08x) failed: %s",
87  dirfd, filename.c_str(), flags, zx_status_get_string(status));
88  return false;
89  }
90  bool result = VmoFromFd(fd, executable, buffer);
91  close(fd);
92  return result;
93 }
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.

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 snapshot asset path
Definition: switches.h:32
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13