1 //////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2005-2012. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // See http://www.boost.org/libs/interprocess for documentation.
9 //////////////////////////////////////////////////////////////////////////////
11 #ifndef BOOST_INTERPROCESS_MAPPED_REGION_HPP
12 #define BOOST_INTERPROCESS_MAPPED_REGION_HPP
14 #ifndef BOOST_CONFIG_HPP
15 # include <boost/config.hpp>
18 #if defined(BOOST_HAS_PRAGMA_ONCE)
22 #include <boost/interprocess/detail/config_begin.hpp>
23 #include <boost/interprocess/detail/workaround.hpp>
25 #include <boost/interprocess/interprocess_fwd.hpp>
26 #include <boost/interprocess/exceptions.hpp>
27 #include <boost/move/utility_core.hpp>
28 #include <boost/interprocess/detail/utilities.hpp>
29 #include <boost/interprocess/detail/os_file_functions.hpp>
31 #include <boost/cstdint.hpp>
32 #include <boost/assert.hpp>
33 #include <boost/move/adl_move_swap.hpp>
35 //Some Unixes use caddr_t instead of void * in madvise
36 // SunOS Tru64 HP-UX AIX
37 #if defined(sun) || defined(__sun) || defined(__osf__) || defined(__osf) || defined(_hpux) || defined(hpux) || defined(_AIX)
38 #define BOOST_INTERPROCESS_MADVISE_USES_CADDR_T
39 #include <sys/types.h>
42 //A lot of UNIXes have destructive semantics for MADV_DONTNEED, so
43 //we need to be careful to allow it.
44 #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__)
45 #define BOOST_INTERPROCESS_MADV_DONTNEED_HAS_NONDESTRUCTIVE_SEMANTICS
48 #if defined (BOOST_INTERPROCESS_WINDOWS)
49 # include <boost/interprocess/detail/win32_api.hpp>
50 # include <boost/interprocess/sync/windows/sync_utils.hpp>
52 # ifdef BOOST_HAS_UNISTD_H
54 # include <sys/mman.h> //mmap
56 # include <sys/stat.h>
57 # include <sys/types.h>
58 # if defined(BOOST_INTERPROCESS_XSI_SHARED_MEMORY_OBJECTS)
59 # include <sys/shm.h> //System V shared memory...
61 # include <boost/assert.hpp>
63 # error Unknown platform
66 #endif //#if defined (BOOST_INTERPROCESS_WINDOWS)
69 //!Describes mapped region class
72 namespace interprocess {
74 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
76 //Solaris declares madvise only in some configurations but defines MADV_XXX, a bit confusing.
77 //Predeclare it here to avoid any compilation error
78 #if (defined(sun) || defined(__sun)) && defined(MADV_NORMAL)
79 extern "C" int madvise(caddr_t, size_t, int);
82 namespace ipcdetail{ class interprocess_tester; }
83 namespace ipcdetail{ class raw_mapped_region_creator; }
85 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
87 //!The mapped_region class represents a portion or region created from a
88 //!memory_mappable object.
90 //!The OS can map a region bigger than the requested one, as region must
91 //!be multiple of the page size, but mapped_region will always refer to
92 //!the region specified by the user.
95 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
97 BOOST_MOVABLE_BUT_NOT_COPYABLE(mapped_region)
98 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
102 //!Creates a mapping region of the mapped memory "mapping", starting in
103 //!offset "offset", and the mapping's size will be "size". The mapping
104 //!can be opened for read only, read-write or copy-on-write.
106 //!If an address is specified, both the offset and the address must be
107 //!multiples of the page size.
109 //!The map is created using "default_map_options". This flag is OS
110 //!dependant and it should not be changed unless the user needs to
111 //!specify special options.
113 //!In Windows systems "map_options" is a DWORD value passed as
114 //!"dwDesiredAccess" to "MapViewOfFileEx". If "default_map_options" is passed
115 //!it's initialized to zero. "map_options" is XORed with FILE_MAP_[COPY|READ|WRITE].
117 //!In UNIX systems and POSIX mappings "map_options" is an int value passed as "flags"
118 //!to "mmap". If "default_map_options" is specified it's initialized to MAP_NOSYNC
119 //!if that option exists and to zero otherwise. "map_options" XORed with MAP_PRIVATE or MAP_SHARED.
121 //!In UNIX systems and XSI mappings "map_options" is an int value passed as "shmflg"
122 //!to "shmat". If "default_map_options" is specified it's initialized to zero.
123 //!"map_options" is XORed with SHM_RDONLY if needed.
125 //!The OS could allocate more pages than size/page_size(), but get_address()
126 //!will always return the address passed in this function (if not null) and
127 //!get_size() will return the specified size.
128 template<class MemoryMappable>
129 mapped_region(const MemoryMappable& mapping
132 ,std::size_t size = 0
133 ,const void *address = 0
134 ,map_options_t map_options = default_map_options);
136 //!Default constructor. Address will be 0 (nullptr).
141 //!Move constructor. *this will be constructed taking ownership of "other"'s
142 //!region and "other" will be left in default constructor state.
143 mapped_region(BOOST_RV_REF(mapped_region) other)
144 #if defined (BOOST_INTERPROCESS_WINDOWS)
145 : m_base(0), m_size(0)
148 , m_file_or_mapping_hnd(ipcdetail::invalid_file())
150 : m_base(0), m_size(0), m_page_offset(0), m_mode(read_only), m_is_xsi(false)
152 { this->swap(other); }
154 //!Destroys the mapped region.
158 //!Move assignment. If *this owns a memory mapped region, it will be
159 //!destroyed and it will take ownership of "other"'s memory mapped region.
160 mapped_region &operator=(BOOST_RV_REF(mapped_region) other)
162 mapped_region tmp(boost::move(other));
167 //!Swaps the mapped_region with another
169 void swap(mapped_region &other);
171 //!Returns the size of the mapping. Never throws.
172 std::size_t get_size() const;
174 //!Returns the base address of the mapping.
176 void* get_address() const;
178 //!Returns the mode of the mapping used to construct the mapped region.
180 mode_t get_mode() const;
182 //!Flushes to the disk a byte range within the mapped memory.
183 //!If 'async' is true, the function will return before flushing operation is completed
184 //!If 'async' is false, function will return once data has been written into the underlying
185 //!device (i.e., in mapped files OS cached information is written to disk).
186 //!Never throws. Returns false if operation could not be performed.
187 bool flush(std::size_t mapping_offset = 0, std::size_t numbytes = 0, bool async = true);
189 //!Shrinks current mapped region. If after shrinking there is no longer need for a previously
190 //!mapped memory page, accessing that page can trigger a segmentation fault.
191 //!Depending on the OS, this operation might fail (XSI shared memory), it can decommit storage
192 //!and free a portion of the virtual address space (e.g.POSIX) or this
193 //!function can release some physical memory wihout freeing any virtual address space(Windows).
194 //!Returns true on success. Never throws.
195 bool shrink_by(std::size_t bytes, bool from_back = true);
197 //!This enum specifies region usage behaviors that an application can specify
198 //!to the mapped region implementation.
200 //!Specifies that the application has no advice to give on its behavior with respect to
201 //!the region. It is the default characteristic if no advice is given for a range of memory.
203 //!Specifies that the application expects to access the region sequentially from
204 //!lower addresses to higher addresses. The implementation can lower the priority of
205 //!preceding pages within the region once a page have been accessed.
207 //!Specifies that the application expects to access the region in a random order,
208 //!and prefetching is likely not advantageous.
210 //!Specifies that the application expects to access the region in the near future.
211 //!The implementation can prefetch pages of the region.
213 //!Specifies that the application expects that it will not access the region in the near future.
214 //!The implementation can unload pages within the range to save system resources.
218 //!Advises the implementation on the expected behavior of the application with respect to the data
219 //!in the region. The implementation may use this information to optimize handling of the region data.
220 //!This function has no effect on the semantics of access to memory in the region, although it may affect
221 //!the performance of access.
222 //!If the advise type is not known to the implementation, the function returns false. True otherwise.
223 bool advise(advice_types advise);
225 //!Returns the size of the page. This size is the minimum memory that
226 //!will be used by the system when mapping a memory mappable source and
227 //!will restrict the address and the offset to map.
228 static std::size_t get_page_size();
230 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
232 //!Closes a previously opened memory mapping. Never throws
235 void* priv_map_address() const;
236 std::size_t priv_map_size() const;
237 bool priv_flush_param_check(std::size_t mapping_offset, void *&addr, std::size_t &numbytes) const;
238 bool priv_shrink_param_check(std::size_t bytes, bool from_back, void *&shrink_page_start, std::size_t &shrink_page_bytes);
239 static void priv_size_from_mapping_size
240 (offset_t mapping_size, offset_t offset, offset_t page_offset, std::size_t &size);
241 static offset_t priv_page_offset_addr_fixup(offset_t page_offset, const void *&addr);
244 struct page_size_holder
246 static const std::size_t PageSize;
247 static std::size_t get_page_size();
252 std::size_t m_page_offset;
254 #if defined(BOOST_INTERPROCESS_WINDOWS)
255 file_handle_t m_file_or_mapping_hnd;
260 friend class ipcdetail::interprocess_tester;
261 friend class ipcdetail::raw_mapped_region_creator;
262 void dont_close_on_destruction();
263 #if defined(BOOST_INTERPROCESS_WINDOWS) && !defined(BOOST_INTERPROCESS_FORCE_GENERIC_EMULATION)
265 static void destroy_syncs_in_range(const void *addr, std::size_t size);
267 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
270 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
272 inline void swap(mapped_region &x, mapped_region &y)
275 inline mapped_region::~mapped_region()
276 { this->priv_close(); }
278 inline std::size_t mapped_region::get_size() const
281 inline mode_t mapped_region::get_mode() const
284 inline void* mapped_region::get_address() const
287 inline void* mapped_region::priv_map_address() const
288 { return static_cast<char*>(m_base) - m_page_offset; }
290 inline std::size_t mapped_region::priv_map_size() const
291 { return m_size + m_page_offset; }
293 inline bool mapped_region::priv_flush_param_check
294 (std::size_t mapping_offset, void *&addr, std::size_t &numbytes) const
300 if(mapping_offset >= m_size || (mapping_offset + numbytes) > m_size){
304 //Update flush size if the user does not provide it
306 numbytes = m_size - mapping_offset;
308 addr = (char*)this->priv_map_address() + mapping_offset;
309 numbytes += m_page_offset;
313 inline bool mapped_region::priv_shrink_param_check
314 (std::size_t bytes, bool from_back, void *&shrink_page_start, std::size_t &shrink_page_bytes)
317 if(m_base == 0 || bytes > m_size){
320 else if(bytes == m_size){
325 const std::size_t page_size = mapped_region::get_page_size();
327 const std::size_t new_pages = (m_size + m_page_offset - bytes - 1)/page_size + 1;
328 shrink_page_start = static_cast<char*>(this->priv_map_address()) + new_pages*page_size;
329 shrink_page_bytes = m_page_offset + m_size - new_pages*page_size;
333 shrink_page_start = this->priv_map_address();
334 m_page_offset += bytes;
335 shrink_page_bytes = (m_page_offset/page_size)*page_size;
336 m_page_offset = m_page_offset % page_size;
338 m_base = static_cast<char *>(m_base) + bytes;
339 BOOST_ASSERT(shrink_page_bytes%page_size == 0);
345 inline void mapped_region::priv_size_from_mapping_size
346 (offset_t mapping_size, offset_t offset, offset_t page_offset, std::size_t &size)
348 //Check if mapping size fits in the user address space
349 //as offset_t is the maximum file size and its signed.
350 if(mapping_size < offset ||
351 boost::uintmax_t(mapping_size - (offset - page_offset)) >
352 boost::uintmax_t(std::size_t(-1))){
353 error_info err(size_error);
354 throw interprocess_exception(err);
356 size = static_cast<std::size_t>(mapping_size - (offset - page_offset));
359 inline offset_t mapped_region::priv_page_offset_addr_fixup(offset_t offset, const void *&address)
361 //We can't map any offset so we have to obtain system's
363 const std::size_t page_size = mapped_region::get_page_size();
365 //We calculate the difference between demanded and valid offset
366 //(always less than a page in std::size_t, thus, representable by std::size_t)
367 const std::size_t page_offset =
368 static_cast<std::size_t>(offset - (offset / page_size) * page_size);
369 //Update the mapping address
371 address = static_cast<const char*>(address) - page_offset;
376 #if defined (BOOST_INTERPROCESS_WINDOWS)
378 inline mapped_region::mapped_region()
379 : m_base(0), m_size(0), m_page_offset(0), m_mode(read_only)
380 , m_file_or_mapping_hnd(ipcdetail::invalid_file())
384 inline std::size_t mapped_region::page_size_holder<dummy>::get_page_size()
386 winapi::system_info info;
387 winapi::get_system_info(&info);
388 return std::size_t(info.dwAllocationGranularity);
391 template<class MemoryMappable>
392 inline mapped_region::mapped_region
393 (const MemoryMappable &mapping
398 ,map_options_t map_options)
399 : m_base(0), m_size(0), m_page_offset(0), m_mode(mode)
400 , m_file_or_mapping_hnd(ipcdetail::invalid_file())
402 mapping_handle_t mhandle = mapping.get_mapping_handle();
404 file_handle_t native_mapping_handle = 0;
407 //For "create_file_mapping"
408 unsigned long protection = 0;
409 //For "mapviewoffile"
410 unsigned long map_access = map_options == default_map_options ? 0 : map_options;
416 protection |= winapi::page_readonly;
417 map_access |= winapi::file_map_read;
420 protection |= winapi::page_readwrite;
421 map_access |= winapi::file_map_write;
424 protection |= winapi::page_writecopy;
425 map_access |= winapi::file_map_copy;
429 error_info err(mode_error);
430 throw interprocess_exception(err);
435 //For file mapping (including emulated shared memory through temporary files),
436 //the device is a file handle so we need to obtain file's size and call create_file_mapping
437 //to obtain the mapping handle.
438 //For files we don't need the file mapping after mapping the memory, as the file is there
439 //so we'll program the handle close
440 void * handle_to_close = winapi::invalid_handle_value;
442 //Create mapping handle
443 native_mapping_handle = winapi::create_file_mapping
444 ( ipcdetail::file_handle_from_mapping_handle(mapping.get_mapping_handle())
445 , protection, 0, 0, 0);
447 //Check if all is correct
448 if(!native_mapping_handle){
449 error_info err = winapi::get_last_error();
450 throw interprocess_exception(err);
452 handle_to_close = native_mapping_handle;
455 //For windows_shared_memory the device handle is already a mapping handle
456 //and we need to maintain it
457 native_mapping_handle = mhandle.handle;
459 //RAII handle close on scope exit
460 const winapi::handle_closer close_handle(handle_to_close);
463 const offset_t page_offset = priv_page_offset_addr_fixup(offset, address);
465 //Obtain mapping size if user provides 0 size
467 offset_t mapping_size;
468 if(!winapi::get_file_mapping_size(native_mapping_handle, mapping_size)){
469 error_info err = winapi::get_last_error();
470 throw interprocess_exception(err);
473 priv_size_from_mapping_size(mapping_size, offset, page_offset, size);
476 //Map with new offsets and size
477 void *base = winapi::map_view_of_file_ex
478 (native_mapping_handle,
480 offset - page_offset,
481 static_cast<std::size_t>(page_offset + size),
482 const_cast<void*>(address));
485 error_info err = winapi::get_last_error();
486 throw interprocess_exception(err);
489 //Calculate new base for the user
490 m_base = static_cast<char*>(base) + page_offset;
491 m_page_offset = page_offset;
494 //Windows shared memory needs the duplication of the handle if we want to
495 //make mapped_region independent from the mappable device
497 //For mapped files, we duplicate the file handle to be able to FlushFileBuffers
498 if(!winapi::duplicate_current_process_handle(mhandle.handle, &m_file_or_mapping_hnd)){
499 error_info err = winapi::get_last_error();
501 throw interprocess_exception(err);
505 inline bool mapped_region::flush(std::size_t mapping_offset, std::size_t numbytes, bool async)
508 if(!this->priv_flush_param_check(mapping_offset, addr, numbytes)){
512 if(!winapi::flush_view_of_file(addr, numbytes)){
515 //m_file_or_mapping_hnd can be a file handle or a mapping handle.
516 //so flushing file buffers has only sense for files...
517 else if(!async && m_file_or_mapping_hnd != winapi::invalid_handle_value &&
518 winapi::get_file_type(m_file_or_mapping_hnd) == winapi::file_type_disk){
519 return winapi::flush_file_buffers(m_file_or_mapping_hnd);
524 inline bool mapped_region::shrink_by(std::size_t bytes, bool from_back)
526 void *shrink_page_start = 0;
527 std::size_t shrink_page_bytes = 0;
528 if(!this->priv_shrink_param_check(bytes, from_back, shrink_page_start, shrink_page_bytes)){
531 else if(shrink_page_bytes){
532 //In Windows, we can't decommit the storage or release the virtual address space,
533 //the best we can do is try to remove some memory from the process working set.
534 //With a bit of luck we can free some physical memory.
535 unsigned long old_protect_ignored;
536 bool b_ret = winapi::virtual_unlock(shrink_page_start, shrink_page_bytes)
537 || (winapi::get_last_error() == winapi::error_not_locked);
538 (void)old_protect_ignored;
539 //Change page protection to forbid any further access
540 b_ret = b_ret && winapi::virtual_protect
541 (shrink_page_start, shrink_page_bytes, winapi::page_noaccess, old_protect_ignored);
549 inline bool mapped_region::advise(advice_types)
551 //Windows has no madvise/posix_madvise equivalent
555 inline void mapped_region::priv_close()
558 void *addr = this->priv_map_address();
559 #if !defined(BOOST_INTERPROCESS_FORCE_GENERIC_EMULATION)
560 mapped_region::destroy_syncs_in_range<0>(addr, m_size);
562 winapi::unmap_view_of_file(addr);
565 if(m_file_or_mapping_hnd != ipcdetail::invalid_file()){
566 winapi::close_handle(m_file_or_mapping_hnd);
567 m_file_or_mapping_hnd = ipcdetail::invalid_file();
571 inline void mapped_region::dont_close_on_destruction()
574 #else //#if defined (BOOST_INTERPROCESS_WINDOWS)
576 inline mapped_region::mapped_region()
577 : m_base(0), m_size(0), m_page_offset(0), m_mode(read_only), m_is_xsi(false)
581 inline std::size_t mapped_region::page_size_holder<dummy>::get_page_size()
582 { return std::size_t(sysconf(_SC_PAGESIZE)); }
584 template<class MemoryMappable>
585 inline mapped_region::mapped_region
586 ( const MemoryMappable &mapping
590 , const void *address
591 , map_options_t map_options)
592 : m_base(0), m_size(0), m_page_offset(0), m_mode(mode), m_is_xsi(false)
594 mapping_handle_t map_hnd = mapping.get_mapping_handle();
596 //Some systems dont' support XSI shared memory
597 #ifdef BOOST_INTERPROCESS_XSI_SHARED_MEMORY_OBJECTS
601 int ret = ::shmctl(map_hnd.handle, IPC_STAT, &xsi_ds);
603 error_info err(system_error_code());
604 throw interprocess_exception(err);
608 size = (std::size_t)xsi_ds.shm_segsz;
610 else if(size != (std::size_t)xsi_ds.shm_segsz){
611 error_info err(size_error);
612 throw interprocess_exception(err);
615 int flag = map_options == default_map_options ? 0 : map_options;
616 if(m_mode == read_only){
619 else if(m_mode != read_write){
620 error_info err(mode_error);
621 throw interprocess_exception(err);
624 void *base = ::shmat(map_hnd.handle, (void*)address, flag);
625 if(base == (void*)-1){
626 error_info err(system_error_code());
627 throw interprocess_exception(err);
637 #endif //ifdef BOOST_INTERPROCESS_XSI_SHARED_MEMORY_OBJECTS
639 //We calculate the difference between demanded and valid offset
640 const offset_t page_offset = priv_page_offset_addr_fixup(offset, address);
644 if(0 != fstat(map_hnd.handle, &buf)){
645 error_info err(system_error_code());
646 throw interprocess_exception(err);
649 priv_size_from_mapping_size(buf.st_size, offset, page_offset, size);
653 #define BOOST_INTERPROCESS_MAP_NOSYNC MAP_NOSYNC
655 #define BOOST_INTERPROCESS_MAP_NOSYNC 0
660 int flags = map_options == default_map_options ? BOOST_INTERPROCESS_MAP_NOSYNC : map_options;
662 #undef BOOST_INTERPROCESS_MAP_NOSYNC
673 flags |= MAP_PRIVATE;
677 prot |= (PROT_WRITE | PROT_READ);
682 prot |= (PROT_WRITE | PROT_READ);
683 flags |= MAP_PRIVATE;
688 error_info err(mode_error);
689 throw interprocess_exception(err);
694 //Map it to the address space
695 void* base = mmap ( const_cast<void*>(address)
696 , static_cast<std::size_t>(page_offset + size)
699 , mapping.get_mapping_handle().handle
700 , offset - page_offset);
702 //Check if mapping was successful
703 if(base == MAP_FAILED){
704 error_info err = system_error_code();
705 throw interprocess_exception(err);
708 //Calculate new base for the user
709 m_base = static_cast<char*>(base) + page_offset;
710 m_page_offset = page_offset;
713 //Check for fixed mapping error
714 if(address && (base != address)){
715 error_info err(busy_error);
717 throw interprocess_exception(err);
721 inline bool mapped_region::shrink_by(std::size_t bytes, bool from_back)
723 void *shrink_page_start = 0;
724 std::size_t shrink_page_bytes = 0;
725 if(m_is_xsi || !this->priv_shrink_param_check(bytes, from_back, shrink_page_start, shrink_page_bytes)){
728 else if(shrink_page_bytes){
729 //In UNIX we can decommit and free virtual address space.
730 return 0 == munmap(shrink_page_start, shrink_page_bytes);
737 inline bool mapped_region::flush(std::size_t mapping_offset, std::size_t numbytes, bool async)
740 if(m_is_xsi || !this->priv_flush_param_check(mapping_offset, addr, numbytes)){
744 return msync(addr, numbytes, async ? MS_ASYNC : MS_SYNC) == 0;
747 inline bool mapped_region::advise(advice_types advice)
750 //Modes; 0: none, 2: posix, 1: madvise
751 const unsigned int mode_none = 0;
752 const unsigned int mode_padv = 1;
753 const unsigned int mode_madv = 2;
754 // Suppress "unused variable" warnings
757 unsigned int mode = mode_none;
758 //Choose advice either from POSIX (preferred) or native Unix
761 #if defined(POSIX_MADV_NORMAL)
762 unix_advice = POSIX_MADV_NORMAL;
764 #elif defined(MADV_NORMAL)
765 unix_advice = MADV_NORMAL;
769 case advice_sequential:
770 #if defined(POSIX_MADV_SEQUENTIAL)
771 unix_advice = POSIX_MADV_SEQUENTIAL;
773 #elif defined(MADV_SEQUENTIAL)
774 unix_advice = MADV_SEQUENTIAL;
779 #if defined(POSIX_MADV_RANDOM)
780 unix_advice = POSIX_MADV_RANDOM;
782 #elif defined(MADV_RANDOM)
783 unix_advice = MADV_RANDOM;
787 case advice_willneed:
788 #if defined(POSIX_MADV_WILLNEED)
789 unix_advice = POSIX_MADV_WILLNEED;
791 #elif defined(MADV_WILLNEED)
792 unix_advice = MADV_WILLNEED;
796 case advice_dontneed:
797 #if defined(POSIX_MADV_DONTNEED)
798 unix_advice = POSIX_MADV_DONTNEED;
800 #elif defined(MADV_DONTNEED) && defined(BOOST_INTERPROCESS_MADV_DONTNEED_HAS_NONDESTRUCTIVE_SEMANTICS)
801 unix_advice = MADV_DONTNEED;
809 #if defined(POSIX_MADV_NORMAL)
811 return 0 == posix_madvise(this->priv_map_address(), this->priv_map_size(), unix_advice);
813 #if defined(MADV_NORMAL)
816 #if defined(BOOST_INTERPROCESS_MADVISE_USES_CADDR_T)
819 this->priv_map_address(), this->priv_map_size(), unix_advice);
827 inline void mapped_region::priv_close()
830 #ifdef BOOST_INTERPROCESS_XSI_SHARED_MEMORY_OBJECTS
832 int ret = ::shmdt(m_base);
833 BOOST_ASSERT(ret == 0);
837 #endif //#ifdef BOOST_INTERPROCESS_XSI_SHARED_MEMORY_OBJECTS
838 munmap(this->priv_map_address(), this->priv_map_size());
843 inline void mapped_region::dont_close_on_destruction()
846 #endif //#if defined (BOOST_INTERPROCESS_WINDOWS)
849 const std::size_t mapped_region::page_size_holder<dummy>::PageSize
850 = mapped_region::page_size_holder<dummy>::get_page_size();
852 inline std::size_t mapped_region::get_page_size()
854 if(!page_size_holder<0>::PageSize)
855 return page_size_holder<0>::get_page_size();
857 return page_size_holder<0>::PageSize;
860 inline void mapped_region::swap(mapped_region &other)
862 ::boost::adl_move_swap(this->m_base, other.m_base);
863 ::boost::adl_move_swap(this->m_size, other.m_size);
864 ::boost::adl_move_swap(this->m_page_offset, other.m_page_offset);
865 ::boost::adl_move_swap(this->m_mode, other.m_mode);
866 #if defined (BOOST_INTERPROCESS_WINDOWS)
867 ::boost::adl_move_swap(this->m_file_or_mapping_hnd, other.m_file_or_mapping_hnd);
869 ::boost::adl_move_swap(this->m_is_xsi, other.m_is_xsi);
874 struct null_mapped_region_function
876 bool operator()(void *, std::size_t , bool) const
879 static std::size_t get_min_size()
883 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
885 } //namespace interprocess {
886 } //namespace boost {
888 #include <boost/interprocess/detail/config_end.hpp>
890 #endif //BOOST_INTERPROCESS_MAPPED_REGION_HPP
892 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
894 #ifndef BOOST_INTERPROCESS_MAPPED_REGION_EXT_HPP
895 #define BOOST_INTERPROCESS_MAPPED_REGION_EXT_HPP
897 #if defined(BOOST_INTERPROCESS_WINDOWS) && !defined(BOOST_INTERPROCESS_FORCE_GENERIC_EMULATION)
898 # include <boost/interprocess/sync/windows/sync_utils.hpp>
899 # include <boost/interprocess/detail/windows_intermodule_singleton.hpp>
902 namespace interprocess {
905 inline void mapped_region::destroy_syncs_in_range(const void *addr, std::size_t size)
907 ipcdetail::sync_handles &handles =
908 ipcdetail::windows_intermodule_singleton<ipcdetail::sync_handles>::get();
909 handles.destroy_syncs_in_range(addr, size);
912 } //namespace interprocess {
913 } //namespace boost {
915 #endif //defined(BOOST_INTERPROCESS_WINDOWS) && !defined(BOOST_INTERPROCESS_FORCE_GENERIC_EMULATION)
917 #endif //#ifdef BOOST_INTERPROCESS_MAPPED_REGION_EXT_HPP
919 #endif //#if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)