mirror of
https://github.com/vimpunk/mio.git
synced 2026-02-11 12:49:56 +08:00
Improve support for 32-bit builds on Windows
This change allows mapping large files with offsets exceeding 32-bit boundary
This commit is contained in:
parent
8b6b7d878c
commit
d4af7d11bf
@ -137,7 +137,7 @@ file_handle_type open_file(const String& path, const access_mode mode,
|
|||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline size_t query_file_size(file_handle_type handle, std::error_code& error)
|
inline int64_t query_file_size(file_handle_type handle, std::error_code& error)
|
||||||
{
|
{
|
||||||
error.clear();
|
error.clear();
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@ -176,6 +176,12 @@ inline mmap_context memory_map(const file_handle_type file_handle, const int64_t
|
|||||||
const int64_t length_to_map = offset - aligned_offset + length;
|
const int64_t length_to_map = offset - aligned_offset + length;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
const int64_t max_file_size = offset + length;
|
const int64_t max_file_size = offset + length;
|
||||||
|
const SIZE_T sz_to_map = static_cast<SIZE_T>(length_to_map);
|
||||||
|
if (static_cast<int64_t>(sz_to_map) != length_to_map)
|
||||||
|
{
|
||||||
|
error = std::make_error_code(std::errc::invalid_argument);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
const auto file_mapping_handle = ::CreateFileMapping(
|
const auto file_mapping_handle = ::CreateFileMapping(
|
||||||
file_handle,
|
file_handle,
|
||||||
0,
|
0,
|
||||||
@ -193,7 +199,7 @@ inline mmap_context memory_map(const file_handle_type file_handle, const int64_t
|
|||||||
mode == access_mode::read ? FILE_MAP_READ : FILE_MAP_WRITE,
|
mode == access_mode::read ? FILE_MAP_READ : FILE_MAP_WRITE,
|
||||||
win::int64_high(aligned_offset),
|
win::int64_high(aligned_offset),
|
||||||
win::int64_low(aligned_offset),
|
win::int64_low(aligned_offset),
|
||||||
length_to_map));
|
sz_to_map));
|
||||||
if(mapping_start == nullptr)
|
if(mapping_start == nullptr)
|
||||||
{
|
{
|
||||||
// Close file handle if mapping it failed.
|
// Close file handle if mapping it failed.
|
||||||
|
|||||||
@ -57,7 +57,7 @@ template<access_mode AccessMode, typename ByteT>
|
|||||||
struct basic_mmap
|
struct basic_mmap
|
||||||
{
|
{
|
||||||
using value_type = ByteT;
|
using value_type = ByteT;
|
||||||
using size_type = size_t;
|
using size_type = int64_t;
|
||||||
using reference = value_type&;
|
using reference = value_type&;
|
||||||
using const_reference = const value_type&;
|
using const_reference = const value_type&;
|
||||||
using pointer = value_type*;
|
using pointer = value_type*;
|
||||||
|
|||||||
@ -66,7 +66,7 @@ inline size_t page_size()
|
|||||||
* difference until the nearest page boundary before `offset`, or does nothing if
|
* difference until the nearest page boundary before `offset`, or does nothing if
|
||||||
* `offset` is already page aligned.
|
* `offset` is already page aligned.
|
||||||
*/
|
*/
|
||||||
inline size_t make_offset_page_aligned(size_t offset) noexcept
|
inline int64_t make_offset_page_aligned(int64_t offset) noexcept
|
||||||
{
|
{
|
||||||
const size_t page_size_ = page_size();
|
const size_t page_size_ = page_size();
|
||||||
// Use integer division to round down to the nearest page alignment.
|
// Use integer division to round down to the nearest page alignment.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user