5#include "flutter/fml/mapping.h"
14#include "flutter/fml/build_config.h"
15#include "flutter/fml/eintr_wrapper.h"
16#include "flutter/fml/unique_fd.h"
21 std::initializer_list<FileMapping::Protection> protection_flags) {
23 for (
auto protection : protection_flags) {
32 flags |= PROT_READ | PROT_EXEC;
40 std::initializer_list<FileMapping::Protection> protection_flags) {
41 for (
auto protection : protection_flags) {
54 std::initializer_list<Protection> protection) {
59 struct stat stat_buffer = {};
61 if (::fstat(handle.
get(), &stat_buffer) != 0) {
65 if (stat_buffer.st_size == 0) {
70 const auto is_writable =
IsWritable(protection);
74 is_writable ? MAP_SHARED : MAP_PRIVATE, handle.
get(), 0);
76 if (mapping == MAP_FAILED) {
80 mapping_ =
static_cast<uint8_t*
>(mapping);
81 size_ = stat_buffer.st_size;
84 mutable_mapping_ = mapping_;
89 if (mapping_ !=
nullptr) {
90 ::munmap(mapping_, size_);
103 return mutable_mapping_ ==
nullptr;
FileMapping(const fml::UniqueFD &fd, std::initializer_list< Protection > protection={ Protection::kRead})
size_t GetSize() const override
bool IsDontNeedSafe() const override
const uint8_t * GetMapping() const override
FlutterSemanticsFlag flags
static bool IsWritable(std::initializer_list< FileMapping::Protection > protection_flags)
static int ToPosixProtectionFlags(std::initializer_list< FileMapping::Protection > protection_flags)