mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
ResourceMapping-related code is no longer used.Moreover, there is an ASan related-error in ResourceMappingDarwin: https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket.appspot.com/8940466063445826656/+/steps/test_results/0/steps/s___out_release-x64_host_tests_dart_schema_tests/0/logs/stdio/0
78 lines
2.0 KiB
C++
78 lines
2.0 KiB
C++
// Copyright 2017 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "flutter/fml/mapping.h"
|
|
|
|
#include <fcntl.h>
|
|
#include <io.h>
|
|
#include <windows.h>
|
|
|
|
#include <type_traits>
|
|
|
|
#include "flutter/fml/file.h"
|
|
#include "flutter/fml/platform/win/wstring_conversion.h"
|
|
|
|
namespace fml {
|
|
|
|
Mapping::Mapping() = default;
|
|
|
|
Mapping::~Mapping() = default;
|
|
|
|
FileMapping::FileMapping(const std::string& path, bool executable)
|
|
: FileMapping(OpenFile(path.c_str(),
|
|
executable ? OpenPermission::kExecute
|
|
: OpenPermission::kRead,
|
|
false),
|
|
executable) {}
|
|
|
|
FileMapping::FileMapping(const fml::UniqueFD& fd, bool executable)
|
|
: size_(0), mapping_(nullptr) {
|
|
if (!fd.is_valid()) {
|
|
return;
|
|
}
|
|
|
|
if (auto size = ::GetFileSize(fd.get(), nullptr)) {
|
|
if (size > 0) {
|
|
size_ = size;
|
|
} else {
|
|
return;
|
|
}
|
|
}
|
|
|
|
const DWORD protect = executable ? PAGE_EXECUTE_READ : PAGE_READONLY;
|
|
|
|
mapping_handle_.reset(::CreateFileMapping(fd.get(), // hFile
|
|
nullptr, // lpAttributes
|
|
protect, // flProtect
|
|
0, // dwMaximumSizeHigh
|
|
0, // dwMaximumSizeLow
|
|
nullptr // lpName
|
|
));
|
|
|
|
if (!mapping_handle_.is_valid()) {
|
|
return;
|
|
}
|
|
|
|
const DWORD desired_access = executable ? FILE_MAP_ALL_ACCESS : FILE_MAP_READ;
|
|
|
|
mapping_ = reinterpret_cast<uint8_t*>(
|
|
MapViewOfFile(mapping_handle_.get(), desired_access, 0, 0, size_));
|
|
}
|
|
|
|
FileMapping::~FileMapping() {
|
|
if (mapping_ != nullptr) {
|
|
UnmapViewOfFile(mapping_);
|
|
}
|
|
}
|
|
|
|
size_t FileMapping::GetSize() const {
|
|
return size_;
|
|
}
|
|
|
|
const uint8_t* FileMapping::GetMapping() const {
|
|
return mapping_;
|
|
}
|
|
|
|
} // namespace fml
|