Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve support for 32-bit builds on Windows #105

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions include/mio/detail/mmap.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<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(
file_handle,
0,
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion include/mio/mmap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ template<access_mode AccessMode, typename ByteT>
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*;
Expand Down
2 changes: 1 addition & 1 deletion include/mio/page.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down