Skip to content

Commit

Permalink
POSIX: quick-fix to support anonymous/pagefile backed mappings.
Browse files Browse the repository at this point in the history
  • Loading branch information
psiha committed Sep 16, 2024
1 parent 37c8fdd commit e9fe3d5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 8 additions & 1 deletion include/psi/vm/mappable_objects/file/file.posix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Handle>( 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<Handle>( file ), view_flags, size };
}
#endif // POSIX impl level

Expand Down
5 changes: 4 additions & 1 deletion include/psi/vm/mapping/mapping.posix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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
Expand Down

0 comments on commit e9fe3d5

Please sign in to comment.