diff --git a/include/psi/vm/mapping/mapping.posix.hpp b/include/psi/vm/mapping/mapping.posix.hpp index e24bc44..f117a3a 100644 --- a/include/psi/vm/mapping/mapping.posix.hpp +++ b/include/psi/vm/mapping/mapping.posix.hpp @@ -60,6 +60,8 @@ struct [[ clang::trivial_abi ]] mapping bool is_file_based() const noexcept { return posix::handle::operator bool(); } + bool is_anonymous() const noexcept { return view_mapping_flags.flags & MAP_ANONYMOUS; } + posix::handle:: reference underlying_file() noexcept { BOOST_ASSERT( is_file_based() ); return *this; } posix::handle::const_reference underlying_file() const noexcept { BOOST_ASSERT( is_file_based() ); return *this; } @@ -74,7 +76,7 @@ struct [[ clang::trivial_abi ]] mapping } // override Handle operator bool to allow for anonymous mappings - explicit operator bool() const noexcept { return posix::handle::operator bool() || ( view_mapping_flags.flags & MAP_ANONYMOUS ); } + explicit operator bool() const noexcept { return posix::handle::operator bool() || is_anonymous(); } flags::viewing view_mapping_flags{}; std ::size_t maximum_size {}; @@ -84,6 +86,10 @@ struct [[ clang::trivial_abi ]] mapping err::fallible_result set_size( handle:: reference, std::uint64_t desired_size ) noexcept; std::uint64_t get_size( handle::const_reference ) noexcept; +// (temporary) special overloads to handle anonymous mappings (until a dedicated mapping type sees the light of day) +err::fallible_result set_size( mapping &, std::size_t desired_size ) noexcept; +std::size_t get_size( mapping const & ) noexcept; + //------------------------------------------------------------------------------ } // namespace posix //------------------------------------------------------------------------------ diff --git a/src/mappable_objects/file/file.posix.cpp b/src/mappable_objects/file/file.posix.cpp index 704c2ec..d0e2ef5 100644 --- a/src/mappable_objects/file/file.posix.cpp +++ b/src/mappable_objects/file/file.posix.cpp @@ -121,6 +121,29 @@ mapping create_mapping } return { std::move( file ), view_flags, size }; } + +// mapping_posix.cpp (not yet existent file) contents////////////////////////// +err::fallible_result set_size( mapping & mapping, std::size_t const desired_size ) noexcept +{ + if ( mapping.is_anonymous() ) + { + mapping.maximum_size = align_up( desired_size, reserve_granularity ); + return err::success; + } + auto result{ set_size( mapping.underlying_file(), desired_size ) }; + if ( std::move( result ) ) + mapping.maximum_size = align_up( desired_size, reserve_granularity ); + return result; +} +std::size_t get_size( mapping const & mapping ) noexcept +{ + if ( mapping.is_anonymous() ) + return mapping.maximum_size; + // TODO update or verify&return mapping.maximum_size? + return static_cast( get_size( mapping.underlying_file() ) ); +} +/////////////////////////////////////////////////////////////////////////////// + #endif // POSIX impl level //------------------------------------------------------------------------------