Merge d4af7d11bf389112ab4b149ddd2b2751feb969cb into 8b6b7d878c89e81614d05edca7936de41ccdd2da

This commit is contained in:
Pavel P 2024-02-11 19:37:49 +02:00 committed by GitHub
commit 914796cfa2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 4 deletions

View File

@ -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<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,
@ -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.

View File

@ -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*;

View File

@ -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.