Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | List of all members
fml::FileMapping Class Referencefinal

#include <mapping.h>

Inheritance diagram for fml::FileMapping:
fml::Mapping

Public Types

enum class  Protection { kRead , kWrite , kExecute }
 

Public Member Functions

 FileMapping (const fml::UniqueFD &fd, std::initializer_list< Protection > protection={ Protection::kRead})
 
 ~FileMapping () override
 
size_t GetSize () const override
 
const uint8_t * GetMapping () const override
 
bool IsDontNeedSafe () const override
 
uint8_t * GetMutableMapping ()
 
bool IsValid () const
 
- Public Member Functions inherited from fml::Mapping
 Mapping ()
 
virtual ~Mapping ()
 

Static Public Member Functions

static std::unique_ptr< FileMappingCreateReadOnly (const std::string &path)
 
static std::unique_ptr< FileMappingCreateReadOnly (const fml::UniqueFD &base_fd, const std::string &sub_path="")
 
static std::unique_ptr< FileMappingCreateReadExecute (const std::string &path)
 
static std::unique_ptr< FileMappingCreateReadExecute (const fml::UniqueFD &base_fd, const std::string &sub_path="")
 

Detailed Description

Definition at line 39 of file mapping.h.

Member Enumeration Documentation

◆ Protection

enum class fml::FileMapping::Protection
strong
Enumerator
kRead 
kWrite 
kExecute 

Definition at line 41 of file mapping.h.

Constructor & Destructor Documentation

◆ FileMapping()

fml::FileMapping::FileMapping ( const fml::UniqueFD fd,
std::initializer_list< Protection protection = Protection::kRead} 
)
explicit

Definition at line 53 of file mapping_posix.cc.

54 {
55 if (!handle.is_valid()) {
56 return;
57 }
58
59 struct stat stat_buffer = {};
60
61 if (::fstat(handle.get(), &stat_buffer) != 0) {
62 return;
63 }
64
65 if (stat_buffer.st_size == 0) {
66 valid_ = true;
67 return;
68 }
69
70 const auto is_writable = IsWritable(protection);
71
72 auto* mapping =
73 ::mmap(nullptr, stat_buffer.st_size, ToPosixProtectionFlags(protection),
74 is_writable ? MAP_SHARED : MAP_PRIVATE, handle.get(), 0);
75
76 if (mapping == MAP_FAILED) {
77 return;
78 }
79
80 mapping_ = static_cast<uint8_t*>(mapping);
81 size_ = stat_buffer.st_size;
82 valid_ = true;
83 if (is_writable) {
84 mutable_mapping_ = mapping_;
85 }
86}
static bool IsWritable(std::initializer_list< FileMapping::Protection > protection_flags)
static int ToPosixProtectionFlags(std::initializer_list< FileMapping::Protection > protection_flags)
const myers::Point & get(const myers::Segment &)

◆ ~FileMapping()

fml::FileMapping::~FileMapping ( )
override

Definition at line 88 of file mapping_posix.cc.

88 {
89 if (mapping_ != nullptr) {
90 ::munmap(mapping_, size_);
91 }
92}

Member Function Documentation

◆ CreateReadExecute() [1/2]

std::unique_ptr< FileMapping > fml::FileMapping::CreateReadExecute ( const fml::UniqueFD base_fd,
const std::string &  sub_path = "" 
)
static

Definition at line 50 of file mapping.cc.

52 {
53 if (!sub_path.empty()) {
54 return CreateReadExecute(
55 OpenFile(base_fd, sub_path.c_str(), false, FilePermission::kRead), "");
56 }
57
58 auto mapping = std::make_unique<FileMapping>(
59 base_fd, std::initializer_list<Protection>{Protection::kRead,
61
62 if (!mapping->IsValid()) {
63 return nullptr;
64 }
65
66 return mapping;
67}
static std::unique_ptr< FileMapping > CreateReadExecute(const std::string &path)
Definition mapping.cc:44
fml::UniqueFD OpenFile(const char *path, bool create_if_necessary, FilePermission permission)
This can open a directory on POSIX, but not on Windows.
Definition file_posix.cc:66

◆ CreateReadExecute() [2/2]

std::unique_ptr< FileMapping > fml::FileMapping::CreateReadExecute ( const std::string &  path)
static

Definition at line 44 of file mapping.cc.

45 {
46 return CreateReadExecute(
47 OpenFile(path.c_str(), false, FilePermission::kRead));
48}
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

◆ CreateReadOnly() [1/2]

std::unique_ptr< FileMapping > fml::FileMapping::CreateReadOnly ( const fml::UniqueFD base_fd,
const std::string &  sub_path = "" 
)
static

Definition at line 26 of file mapping.cc.

28 {
29 if (!sub_path.empty()) {
30 return CreateReadOnly(
31 OpenFile(base_fd, sub_path.c_str(), false, FilePermission::kRead), "");
32 }
33
34 auto mapping = std::make_unique<FileMapping>(
35 base_fd, std::initializer_list<Protection>{Protection::kRead});
36
37 if (!mapping->IsValid()) {
38 return nullptr;
39 }
40
41 return mapping;
42}
static std::unique_ptr< FileMapping > CreateReadOnly(const std::string &path)
Definition mapping.cc:20

◆ CreateReadOnly() [2/2]

std::unique_ptr< FileMapping > fml::FileMapping::CreateReadOnly ( const std::string &  path)
static

Definition at line 20 of file mapping.cc.

21 {
22 return CreateReadOnly(OpenFile(path.c_str(), false, FilePermission::kRead),
23 "");
24}

◆ GetMapping()

const uint8_t * fml::FileMapping::GetMapping ( ) const
overridevirtual

Implements fml::Mapping.

Definition at line 98 of file mapping_posix.cc.

98 {
99 return mapping_;
100}

◆ GetMutableMapping()

uint8_t * fml::FileMapping::GetMutableMapping ( )

Definition at line 16 of file mapping.cc.

16 {
17 return mutable_mapping_;
18}

◆ GetSize()

size_t fml::FileMapping::GetSize ( ) const
overridevirtual

Implements fml::Mapping.

Definition at line 94 of file mapping_posix.cc.

94 {
95 return size_;
96}

◆ IsDontNeedSafe()

bool fml::FileMapping::IsDontNeedSafe ( ) const
overridevirtual

Implements fml::Mapping.

Definition at line 102 of file mapping_posix.cc.

102 {
103 return mutable_mapping_ == nullptr;
104}

◆ IsValid()

bool fml::FileMapping::IsValid ( ) const

Definition at line 106 of file mapping_posix.cc.

106 {
107 return valid_;
108}

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