diff --git a/include/psi/vm/mappable_objects/file/file.posix.hpp b/include/psi/vm/mappable_objects/file/file.posix.hpp index 55c45ce..d326e00 100644 --- a/include/psi/vm/mappable_objects/file/file.posix.hpp +++ b/include/psi/vm/mappable_objects/file/file.posix.hpp @@ -74,7 +74,14 @@ mapping BOOST_CC_REG create_mapping { // Apple guidelines http://developer.apple.com/library/mac/#documentation/Performance/Conceptual/FileSystem/Articles/MappingFiles.html (void)child_access; //...mrmlj...figure out what to do with this... - return { std::forward( file ), flags::viewing::create( object_access, share_mode ), size }; + auto view_flags{ flags::viewing::create( object_access, share_mode ) }; + if ( !file ) + { + // emulate the Windows interface: null file signifies that the user + // wants a temporary/non-persisted 'anonymous'/pagefile-backed mapping + view_flags.flags |= MAP_ANONYMOUS; + } + return { std::forward( file ), view_flags, size }; } #endif // POSIX impl level diff --git a/include/psi/vm/mapping/mapping.posix.hpp b/include/psi/vm/mapping/mapping.posix.hpp index e25986e..39f03c1 100644 --- a/include/psi/vm/mapping/mapping.posix.hpp +++ b/include/psi/vm/mapping/mapping.posix.hpp @@ -59,7 +59,7 @@ struct [[ clang::trivial_abi ]] mapping ) == 0; } - bool is_file_based() const noexcept { return this->get() != posix::handle::invalid_value; } + bool is_file_based() const noexcept { return posix::handle::operator bool(); } 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,6 +74,9 @@ struct [[ clang::trivial_abi ]] mapping return *this; } + // 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 ); } + flags::viewing view_mapping_flags{}; std ::size_t maximum_size {}; }; // struct mapping