Flutter Engine
dart_utils::MappedResource Class Reference

#include <mapped_resource.h>

Public Member Functions

 MappedResource ()
 
 MappedResource (MappedResource &&other)
 
MappedResourceoperator= (MappedResource &&other)
 
 ~MappedResource ()
 
const uint8_t * address () const
 
size_t size () const
 

Static Public Member Functions

static bool LoadFromNamespace (fdio_ns_t *namespc, const std::string &path, MappedResource &resource, bool executable=false)
 
static bool LoadFromDir (int dirfd, const std::string &path, MappedResource &resource, bool executable=false)
 
static bool LoadFromVmo (const std::string &path, fuchsia::mem::Buffer resource_vmo, MappedResource &resource, bool executable=false)
 

Detailed Description

Definition at line 50 of file mapped_resource.h.

Constructor & Destructor Documentation

◆ MappedResource() [1/2]

dart_utils::MappedResource::MappedResource ( )
inline

Definition at line 52 of file mapped_resource.h.

52 : address_(nullptr), size_(0) {}

◆ MappedResource() [2/2]

dart_utils::MappedResource::MappedResource ( MappedResource &&  other)
inline

Definition at line 53 of file mapped_resource.h.

54  : address_(other.address_), size_(other.size_) {
55  other.address_ = nullptr;
56  other.size_ = 0;
57  }

◆ ~MappedResource()

dart_utils::MappedResource::~MappedResource ( )

Definition at line 97 of file mapped_resource.cc.

97  {
98  if (address_ != nullptr) {
99  zx::vmar::root_self()->unmap(reinterpret_cast<uintptr_t>(address_), size_);
100  address_ = nullptr;
101  size_ = 0;
102  }
103 }

Member Function Documentation

◆ address()

const uint8_t* dart_utils::MappedResource::address ( ) const
inline

◆ LoadFromDir()

static bool dart_utils::MappedResource::LoadFromDir ( int  dirfd,
const std::string &  path,
MappedResource resource,
bool  executable = false 
)
static

◆ LoadFromNamespace()

bool dart_utils::MappedResource::LoadFromNamespace ( fdio_ns_t *  namespc,
const std::string &  path,
MappedResource resource,
bool  executable = false 
)
static

Definition at line 63 of file mapped_resource.cc.

References LoadFromVmo(), and dart_utils::OpenVmo().

Referenced by dart_runner::CreateServiceIsolate(), dart_runner::DartRunner::DartRunner(), dart_runner::GetVMServiceAssetsArchiveCallback(), dart_runner::DartComponentControllerV2::SetUp(), and dart_runner::DartTestComponentControllerV2::SetUp().

66  {
67  fuchsia::mem::Buffer resource_vmo;
68  return OpenVmo(&resource_vmo, namespc, path, executable) &&
69  LoadFromVmo(path, std::move(resource_vmo), resource, executable);
70 }
static bool OpenVmo(fuchsia::mem::Buffer *resource_vmo, fdio_ns_t *namespc, const std::string &path, bool executable)
static bool LoadFromVmo(const std::string &path, fuchsia::mem::Buffer resource_vmo, MappedResource &resource, bool executable=false)
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

◆ LoadFromVmo()

bool dart_utils::MappedResource::LoadFromVmo ( const std::string &  path,
fuchsia::mem::Buffer  resource_vmo,
MappedResource resource,
bool  executable = false 
)
static

Definition at line 72 of file mapped_resource.cc.

References flags, and LOG_TAG.

Referenced by LoadFromNamespace().

75  {
76  if (resource_vmo.size == 0) {
77  return true;
78  }
79 
80  uint32_t flags = ZX_VM_PERM_READ;
81  if (executable) {
82  flags |= ZX_VM_PERM_EXECUTE;
83  }
84  uintptr_t addr;
85  zx_status_t status = zx::vmar::root_self()->map(flags, 0, resource_vmo.vmo, 0,
86  resource_vmo.size, &addr);
87  if (status != ZX_OK) {
88  FX_LOGF(ERROR, LOG_TAG, "Failed to map: %s", zx_status_get_string(status));
89  return false;
90  }
91 
92  resource.address_ = reinterpret_cast<void*>(addr);
93  resource.size_ = resource_vmo.size;
94  return true;
95 }
FlutterSemanticsFlag flags
#define LOG_TAG
Definition: logging.h:11

◆ operator=()

MappedResource& dart_utils::MappedResource::operator= ( MappedResource &&  other)
inline

Definition at line 58 of file mapped_resource.h.

58  {
59  address_ = other.address_;
60  size_ = other.size_;
61  other.address_ = nullptr;
62  other.size_ = 0;
63  return *this;
64  }

◆ size()

size_t dart_utils::MappedResource::size ( ) const
inline

The documentation for this class was generated from the following files: