5#include "flutter/fml/mapping.h"
13#include "flutter/fml/file.h"
14#include "flutter/fml/platform/win/errors_win.h"
15#include "flutter/fml/platform/win/wstring_conversion.h"
24 std::initializer_list<FileMapping::Protection> protection_flags) {
25 for (
auto protection : protection_flags) {
34 std::initializer_list<FileMapping::Protection> protection_flags) {
35 for (
auto protection : protection_flags) {
44 std::initializer_list<Protection> protections)
45 : size_(0), mapping_(nullptr) {
50 const auto mapping_size = ::GetFileSize(fd.
get(),
nullptr);
52 if (mapping_size == INVALID_FILE_SIZE) {
57 if (mapping_size == 0) {
62 DWORD protect_flags = 0;
66 protect_flags = PAGE_EXECUTE_READ;
67 }
else if (read_only) {
68 protect_flags = PAGE_READONLY;
70 protect_flags = PAGE_READWRITE;
73 mapping_handle_.reset(::CreateFileMapping(fd.
get(),
81 if (!mapping_handle_.is_valid()) {
85 const DWORD desired_access = read_only ? FILE_MAP_READ : FILE_MAP_WRITE;
87 auto mapping =
reinterpret_cast<uint8_t*
>(
88 MapViewOfFile(mapping_handle_.get(), desired_access, 0, 0, mapping_size));
90 if (mapping ==
nullptr) {
100 mutable_mapping_ = mapping_;
104FileMapping::~FileMapping() {
105 if (mapping_ !=
nullptr) {
106 UnmapViewOfFile(mapping_);
110size_t FileMapping::GetSize()
const {
114const uint8_t* FileMapping::GetMapping()
const {
118bool FileMapping::IsDontNeedSafe()
const {
119 return mutable_mapping_ ==
nullptr;
122bool FileMapping::IsValid()
const {
FileMapping(const fml::UniqueFD &fd, std::initializer_list< Protection > protection={ Protection::kRead})
#define FML_DLOG(severity)
static bool IsExecutable(std::initializer_list< FileMapping::Protection > protection_flags)
static bool IsWritable(std::initializer_list< FileMapping::Protection > protection_flags)
std::string GetLastErrorMessage()