Flutter Engine
dart_utils Namespace Reference

Classes

class  ElfSnapshot
 
class  MappedResource
 
class  RunnerTemp
 
class  VMServiceObject
 

Functions

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(), and dart_runner::DartComponentController::Main().

26  {
27  return SIZE;
28 }

◆ Check()

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

Definition at line 12 of file inlines.h.

Referenced by 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 107 of file handle_exception.cc.

References LOG_TAG.

Referenced by HandleIfException(), and flutter_runner::MakeDataFileMapping().

110  {
111  fuchsia::feedback::CrashReport crash_report =
112  BuildCrashReport(component_url, error, stack_trace);
113 
114  fuchsia::feedback::CrashReporterPtr crash_reporter =
115  services->Connect<fuchsia::feedback::CrashReporter>();
116  crash_reporter->File(
117  std::move(crash_report),
118  [](fuchsia::feedback::CrashReporter_File_Result result) {
119  if (result.is_err()) {
120  FX_LOGF(ERROR, LOG_TAG, "Failed to report Dart exception: %d (%s)",
121  result.err(), zx_status_get_string(result.err()));
122  }
123  });
124 }
FlMethodResponse GError ** error
#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 92 of file handle_exception.cc.

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

Referenced by dart_runner::DartComponentController::Main().

94  {
95  if (!Dart_IsError(result) || !Dart_ErrorHasException(result)) {
96  return;
97  }
98 
99  const std::string error =
100  tonic::StdStringFromDart(Dart_ToString(Dart_ErrorGetException(result)));
101  const std::string stack_trace =
102  tonic::StdStringFromDart(Dart_ToString(Dart_ErrorGetStackTrace(result)));
103 
104  return HandleException(services, component_url, error, stack_trace);
105 }
void HandleException(std::shared_ptr<::sys::ServiceDirectory > services, const std::string &component_url, const std::string &error, const std::string &stack_trace)
FlMethodResponse GError ** error
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 }

◆ 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, OPEN_RIGHT_EXECUTABLE, and OPEN_RIGHT_READABLE.

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(),
115  &fd);
116  } else {
117  dart_utils::Check(path[0] != '/', LOG_TAG);
118  result = fdio_open_fd_at(
119  dirfd, path.c_str(),
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
constexpr uint32_t OPEN_RIGHT_EXECUTABLE
Definition: component.cc:50
void Check(bool condition, const char *tag, const char *message="")
Definition: inlines.h:12
#define LOG_TAG
Definition: logging.h:11
constexpr uint32_t OPEN_RIGHT_READABLE
Definition: component.cc:47

◆ 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, 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
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::MakeDataFileMapping(), 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

◆ ReadFileToStringAt()

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

Definition at line 60 of file files.cc.

Referenced by flutter_runner::MakeDataFileMapping(), and 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

◆ VmoFromFilename()

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

Definition at line 54 of file vmo.cc.

References flutter::flags, LOG_TAG, OPEN_RIGHT_EXECUTABLE, and OPEN_RIGHT_READABLE.

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.
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 }
constexpr uint32_t OPEN_RIGHT_EXECUTABLE
Definition: component.cc:50
#define LOG_TAG
Definition: logging.h:11
constexpr uint32_t OPEN_RIGHT_READABLE
Definition: component.cc:47
DEF_SWITCHES_START snapshot asset Path to the directory containing the four files specified by VmSnapshotInstructions and IsolateSnapshotInstructions vm snapshot The VM instructions snapshot that will be memory mapped as read and executable SnapshotAssetPath must be present isolate snapshot The isolate instructions snapshot that will be memory mapped as read and executable SnapshotAssetPath must be present icu symbol Prefix for the symbols representing ICU data linked into the Flutter library dart flags
Definition: switches.h:66

◆ 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 flutter::flags, LOG_TAG, OPEN_RIGHT_EXECUTABLE, and OPEN_RIGHT_READABLE.

Referenced by OpenVmo().

79  {
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 }
constexpr uint32_t OPEN_RIGHT_EXECUTABLE
Definition: component.cc:50
#define LOG_TAG
Definition: logging.h:11
constexpr uint32_t OPEN_RIGHT_READABLE
Definition: component.cc:47
DEF_SWITCHES_START snapshot asset Path to the directory containing the four files specified by VmSnapshotInstructions and IsolateSnapshotInstructions vm snapshot The VM instructions snapshot that will be memory mapped as read and executable SnapshotAssetPath must be present isolate snapshot The isolate instructions snapshot that will be memory mapped as read and executable SnapshotAssetPath must be present icu symbol Prefix for the symbols representing ICU data linked into the Flutter library dart flags
Definition: switches.h:66

◆ 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_runner::CreateCompilationTrace().

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