diff --git a/include/mio/detail/mmap.ipp b/include/mio/detail/mmap.ipp index 716a171..0db9b28 100644 --- a/include/mio/detail/mmap.ipp +++ b/include/mio/detail/mmap.ipp @@ -137,7 +137,7 @@ file_handle_type open_file(const String& path, const access_mode mode, 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(); #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; #ifdef _WIN32 const int64_t max_file_size = offset + length; + const SIZE_T sz_to_map = static_cast(length_to_map); + if (static_cast(sz_to_map) != length_to_map) + { + error = std::make_error_code(std::errc::invalid_argument); + return {}; + } const auto file_mapping_handle = ::CreateFileMapping( file_handle, 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, win::int64_high(aligned_offset), win::int64_low(aligned_offset), - length_to_map)); + sz_to_map)); if(mapping_start == nullptr) { // Close file handle if mapping it failed. diff --git a/include/mio/mmap.hpp b/include/mio/mmap.hpp index def559a..d0e1aeb 100644 --- a/include/mio/mmap.hpp +++ b/include/mio/mmap.hpp @@ -57,7 +57,7 @@ template struct basic_mmap { using value_type = ByteT; - using size_type = size_t; + using size_type = int64_t; using reference = value_type&; using const_reference = const value_type&; using pointer = value_type*; diff --git a/include/mio/page.hpp b/include/mio/page.hpp index cae7377..0a8f757 100644 --- a/include/mio/page.hpp +++ b/include/mio/page.hpp @@ -66,7 +66,7 @@ inline size_t page_size() * difference until the nearest page boundary before `offset`, or does nothing if * `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(); // Use integer division to round down to the nearest page alignment.