Modify

Ticket #1612 (closed Feature Requests: fixed)

Opened 6 years ago

Last modified 4 years ago

Support for PAGE_WRITECOPY(Windows) and MAP_PRIVATE(POSIX) flags

Reported by: Jorge Lodos Owned by: turkanis
Milestone: Boost 1.36.0 Component: iostreams
Version: Boost 1.34.1 Severity: Not Applicable
Keywords: Cc:

Description

The use of these flags allos for opening the file in read mode and creating the mapping so it could be written to without really changing the underlying physical object. Currently they are infered from the open mode in the OS primitives, defaulting to read only (in) or synchronized read/write (out). An additional flag parameter could be added to the mapped_file_params structure and open methods. Possible portable values for this flags could be PRIVATE and SHARED, defaulting to SHARED which is the current behavior. A bool parameter could be used instead.

Sample implementation:

You might want to pass objects of this class by reference most of the time, now they are being passed by value everywhere struct mapped_file_params {

explicit mapped_file_params()

: mode(), offset(0), length(static_cast<std::size_t>(-1)),

new_file_size(0), hint(0), flags(SHARED)

{ }

explicit mapped_file_params(const std::string& path)

: path(path), mode(), offset(0),

length(static_cast<std::size_t>(-1)), new_file_size(0), hint(0), flags(SHARED)

{ }

std::string path; BOOST_IOS::openmode mode; stream_offset offset; std::size_t length; stream_offset new_file_size; const char* hint; int flags;

};

Modified functions in mapped_file_source (assign flgas in the implementation)

explicit mapped_file_source( const std::string& path,

size_type length = max_length, boost::intmax_t offset = 0, int flags = SHARED );

void open( const std::string& path,

size_type length = max_length, boost::intmax_t offset = 0, int flags = SHARED );

Modified functions in mapped_file (assign flgas in the implementation)

explicit mapped_file( const std::string& path,

BOOST_IOS::openmode mode =

BOOST_IOS::in | BOOST_IOS::out,

size_type length = max_length, stream_offset offset = 0, int flags = SHARED );

void open( const std::string& path,

BOOST_IOS::openmode mode =

BOOST_IOS::in | BOOST_IOS::out,

size_type length = max_length, stream_offset offset = 0, int flags = SHARED );

Modified functions in mapped_file_sik (assign flgas in the implementation)

explicit mapped_file_sink( const std::string& path,

size_type length = max_length, boost::intmax_t offset = 0, int flags = SHARED );

void open( const std::string& path,

size_type length = max_length, boost::intmax_t offset = 0, int flags = SHARED);

In mapped_file_source::open_impl(mapped_file_params p) implementation, the lines pimpl_->mapped_handle_ = ::CreateFileMappingA( pimpl_->handle_, NULL, readonly ? PAGE_READONLY : PAGE_READWRITE, 0, 0, NULL ); should be replaced by:

DWORD protect = readonly ? PAGE_READONLY : PAGE_READWRITE; if (p.flags == PRIVATE)

protect = PAGE_WRITECOPY;

pimpl_->mapped_handle_ =

::CreateFileMappingA( pimpl_->handle_, NULL,

protect, 0, 0, NULL );

The lines void* data = ::mmap( hint, pimpl_->size_, readonly ? PROT_READ : (PROT_READ | PROT_WRITE), readonly ? MAP_PRIVATE : MAP_SHARED, pimpl_->handle_, p.offset ); should be replaced by:

void* data = ::mmap( hint, pimpl_->size_,

readonly ? PROT_READ : (PROT_READ | PROT_WRITE), p.flags == PRIVATE ? MAP_PRIVATE : MAP_SHARED, pimpl_->handle_, p.offset );

Thank you!

Attachments

mapped_file.hpp Download (9.9 KB) - added by Jorge Lodos 6 years ago.
Modified with the bool variant
mapped_file.zip Download (3.3 KB) - added by Jorge Lodos 6 years ago.
Modified with the bool variant
mapped_file.2.zip Download (5.9 KB) - added by lodos at segurmatica.cu 6 years ago.
Implementation that allows for different flags for the underlying file and the mapping.

Change History

Changed 6 years ago by Jorge Lodos

Modified with the bool variant

Changed 6 years ago by Jorge Lodos

Modified with the bool variant

Changed 6 years ago by lodos at segurmatica.cu

Implementation that allows for different flags for the underlying file and the mapping.

comment:1 Changed 4 years ago by danieljames

Was this fixed in [46692]? Also, the boost license information was removed in that change, presumably by mistake. Is it okay to put it back? Thanks.

comment:2 Changed 4 years ago by steven_watanabe

Since Jonathan is listed in more/blanket-permission.txt, I'd just add the Boost license back.

comment:3 Changed 4 years ago by steven_watanabe

Hmmm. The functionality is undocumented, even though it exists.

comment:4 Changed 4 years ago by steven_watanabe

I added documentation in [63298].

comment:5 Changed 4 years ago by steven_watanabe

  • Status changed from new to closed
  • Resolution set to fixed
View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.