#include <Mem_Map.h>
Public Member Functions | |
| ACE_Mem_Map (void) | |
| Default constructor. | |
| ACE_Mem_Map (ACE_HANDLE handle, size_t length=static_cast< size_t >(-1), int prot=PROT_RDWR, int share=ACE_MAP_PRIVATE, void *addr=0, ACE_OFF_T offset=0, LPSECURITY_ATTRIBUTES sa=0) | |
| ACE_Mem_Map (const ACE_TCHAR *filename, size_t length=static_cast< size_t >(-1), int flags=O_RDWR|O_CREAT, mode_t mode=ACE_DEFAULT_FILE_PERMS, int prot=PROT_RDWR, int share=ACE_MAP_PRIVATE, void *addr=0, ACE_OFF_T offset=0, LPSECURITY_ATTRIBUTES sa=0) | |
| Map a file specified by file_name. | |
| int | map (ACE_HANDLE handle, size_t length=static_cast< size_t >(-1), int prot=PROT_RDWR, int share=ACE_MAP_PRIVATE, void *addr=0, ACE_OFF_T offset=0, LPSECURITY_ATTRIBUTES sa=0) |
| int | map (size_t length=static_cast< size_t >(-1), int prot=PROT_RDWR, int share=ACE_MAP_PRIVATE, void *addr=0, ACE_OFF_T offset=0, LPSECURITY_ATTRIBUTES sa=0) |
| Remap the file associated with . | |
| int | map (const ACE_TCHAR *filename, size_t length=static_cast< size_t >(-1), int flags=O_RDWR|O_CREAT, mode_t mode=ACE_DEFAULT_FILE_PERMS, int prot=PROT_RDWR, int share=ACE_MAP_PRIVATE, void *addr=0, ACE_OFF_T offset=0, LPSECURITY_ATTRIBUTES sa=0) |
| Map a file specified by . | |
| ~ACE_Mem_Map (void) | |
| Destructor. | |
| int | open (const ACE_TCHAR *filename, int flags=O_RDWR|O_CREAT, mode_t perms=ACE_DEFAULT_FILE_PERMS, LPSECURITY_ATTRIBUTES sa=0) |
| Open the file without mapping it. | |
| int | close (void) |
| Close down the if necessary and unmap the mapping. | |
| int | close_handle (void) |
| Close down the if necessary. | |
| int | close_filemapping_handle (void) |
| int | operator() (void *&addr) |
| void * | addr (void) const |
| Return the base address. | |
| size_t | size (void) const |
| int | unmap (ssize_t len=-1) |
| Unmap the region starting at . | |
| int | unmap (void *addr, ssize_t len) |
| Unmap the region starting at . | |
| int | sync (size_t len, int flags=MS_SYNC) |
| int | sync (int flags=MS_SYNC) |
| int | sync (void *addr, size_t len, int flags=MS_SYNC) |
| int | protect (size_t len, int prot=PROT_RDWR) |
| int | protect (int prot=PROT_RDWR) |
| int | protect (void *addr, size_t len, int prot=PROT_RDWR) |
| int | remove (void) |
| Close and remove the file from the file system. | |
| int | advise (int behavior, int len=-1) |
| Hook into the underlying VM system. | |
| ACE_HANDLE | handle (void) const |
| Return the underlying . | |
| const ACE_TCHAR * | filename (void) const |
| Return the name of file that is mapped (if any). | |
| void | dump (void) const |
| Dump the state of an object. | |
Public Attributes | |
| ACE_ALLOC_HOOK_DECLARE | |
| Declare the dynamic allocation hooks. | |
Private Member Functions | |
| int | map_it (ACE_HANDLE handle, size_t len=static_cast< size_t >(-1), int prot=PROT_RDWR, int share=MAP_SHARED, void *addr=0, ACE_OFF_T offset=0, LPSECURITY_ATTRIBUTES sa=0) |
| ACE_Mem_Map (const ACE_Mem_Map &) | |
| void | operator= (const ACE_Mem_Map &) |
Private Attributes | |
| void * | base_addr_ |
| Base address of the memory-mapped file. | |
| ACE_TCHAR | filename_ [MAXPATHLEN+1] |
| Name of the file that is mapped. | |
| size_t | length_ |
| Length of the mapping. | |
| ACE_HANDLE | handle_ |
| HANDLE for the open file. | |
| ACE_HANDLE | file_mapping_ |
| HANDLE for the open mapping. | |
| bool | close_handle_ |
This class works with both the mmap(2) UNIX system and the Win32 family of memory mapping system calls.
Definition at line 40 of file Mem_Map.h.
|
|
Default constructor.
Definition at line 213 of file Mem_Map.cpp. References ACE_TRACE, MAP_FAILED, and ACE_OS::memset().
00214 : base_addr_ (MAP_FAILED), 00215 length_ (0), 00216 handle_ (ACE_INVALID_HANDLE), 00217 file_mapping_ (ACE_INVALID_HANDLE), 00218 close_handle_ (false) 00219 { 00220 ACE_TRACE ("ACE_Mem_Map::ACE_Mem_Map"); 00221 ACE_OS::memset (this->filename_, 0, sizeof this->filename_); 00222 } |
|
||||||||||||||||||||||||||||||||
|
Map a file from an open file descriptor handle. This function will lookup the length of the file if it is not given. Definition at line 259 of file Mem_Map.cpp. References ACE_ERROR, ACE_OFF_T, ACE_TEXT, ACE_TRACE, LM_ERROR, map(), MAP_FAILED, and ACE_OS::memset().
00266 : base_addr_ (MAP_FAILED), 00267 length_ (0), 00268 handle_ (ACE_INVALID_HANDLE), 00269 file_mapping_ (ACE_INVALID_HANDLE), 00270 close_handle_ (false) 00271 { 00272 ACE_TRACE ("ACE_Mem_Map::ACE_Mem_Map"); 00273 00274 ACE_OS::memset (this->filename_, 00275 0, 00276 sizeof this->filename_); 00277 if (this->map (handle, 00278 len, 00279 prot, 00280 share, 00281 addr, 00282 offset, 00283 sa) < 0) 00284 ACE_ERROR ((LM_ERROR, 00285 ACE_TEXT ("%p\n"), 00286 ACE_TEXT ("ACE_Mem_Map::ACE_Mem_Map"))); 00287 } |
|
||||||||||||||||||||||||||||||||||||||||
|
Map a file specified by file_name.
Definition at line 226 of file Mem_Map.cpp. References ACE_ERROR, ACE_OFF_T, ACE_TCHAR, ACE_TEXT, ACE_TRACE, LM_ERROR, map(), MAP_FAILED, and mode_t.
00235 : base_addr_ (MAP_FAILED), 00236 length_ (0), 00237 handle_ (ACE_INVALID_HANDLE), 00238 file_mapping_ (ACE_INVALID_HANDLE), 00239 close_handle_ (false) 00240 { 00241 ACE_TRACE ("ACE_Mem_Map::ACE_Mem_Map"); 00242 if (this->map (file_name, 00243 len, 00244 flags, 00245 mode, 00246 prot, 00247 share, 00248 addr, 00249 offset, 00250 sa) < 0) 00251 ACE_ERROR ((LM_ERROR, 00252 ACE_TEXT ("%p\n"), 00253 ACE_TEXT ("ACE_Mem_Map::ACE_Mem_Map"))); 00254 } |
|
|
Destructor.
Definition at line 50 of file Mem_Map.cpp. References ACE_TRACE, and close().
|
|
|
|
|
|
Return the base address.
Definition at line 81 of file Mem_Map.inl. References ACE_TRACE, and base_addr_. Referenced by ACE_MMAP_Memory_Pool::acquire(), ACE_Filecache_Object::address(), ACE_MMAP_Memory_Pool::init_acquire(), ACE_MMAP_Memory_Pool::map_file(), and ACE_MMAP_Memory_Pool::remap().
00082 {
00083 ACE_TRACE ("ACE_Mem_Map::addr");
00084
00085 return this->base_addr_;
00086 }
|
|
||||||||||||
|
Hook into the underlying VM system.
Definition at line 212 of file Mem_Map.inl. References ACE_TRACE, caddr_t, and ACE_OS::madvise().
00213 {
00214 ACE_TRACE ("ACE_Mem_Map::advise");
00215 const size_t advise_len =
00216 len < 0 ? this->length_ : static_cast<size_t> (len);
00217
00218 return ACE_OS::madvise ((caddr_t) this->base_addr_,
00219 advise_len,
00220 behavior);
00221 }
|
|
|
Close down the if necessary and unmap the mapping.
Definition at line 41 of file Mem_Map.cpp. References ACE_TRACE, close_handle(), and unmap(). Referenced by ACE_MMAP_Memory_Pool::release(), remove(), and ~ACE_Mem_Map().
00042 {
00043 ACE_TRACE ("ACE_Mem_Map::close");
00044
00045 this->unmap ();
00046
00047 return this->close_handle ();
00048 }
|
|
|
Close down the internal if necessary. This is mostly necessary on Win32, which has a different handle for file-mapping kernel object. Definition at line 99 of file Mem_Map.inl. References ACE_OS::close(), and file_mapping_. Referenced by map_it(), and unmap().
00100 {
00101 int result = 0;
00102
00103 if (this->file_mapping_ != this->handle_
00104 && this->file_mapping_ != ACE_INVALID_HANDLE)
00105 {
00106 result = ACE_OS::close (this->file_mapping_);
00107 this->file_mapping_ = ACE_INVALID_HANDLE;
00108 }
00109
00110 return result;
00111 }
|
|
|
Close down the if necessary.
Definition at line 224 of file Mem_Map.inl. References ACE_OS::close(), and close_handle_. Referenced by close().
00225 {
00226 int result = 0;
00227
00228 if (this->close_handle_)
00229 {
00230 this->close_handle_ = false;
00231 result = ACE_OS::close (this->handle_);
00232 this->handle_ = ACE_INVALID_HANDLE;
00233 }
00234
00235 return result;
00236 }
|
|
|
Dump the state of an object.
Definition at line 24 of file Mem_Map.cpp. References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_TEXT, ACE_TRACE, and LM_DEBUG.
00025 {
00026 #if defined (ACE_HAS_DUMP)
00027 ACE_TRACE ("ACE_Mem_Map::dump");
00028
00029 ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00030 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("base_addr_ = %x"), this->base_addr_));
00031 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nfilename_ = %s"), this->filename_));
00032 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nlength_ = %d"), this->length_));
00033 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nhandle_ = %d"), this->handle_));
00034 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nfile_mapping_ = %d"), this->file_mapping_));
00035 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nclose_handle_ = %d"), this->close_handle_));
00036 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00037 #endif /* ACE_HAS_DUMP */
00038 }
|
|
|
Return the name of file that is mapped (if any).
Definition at line 21 of file Mem_Map.inl. Referenced by ACE_Shared_Memory_MM::filename().
00022 {
00023 return this->filename_;
00024 }
|
|
|
Return the underlying .
Definition at line 12 of file Mem_Map.inl. References ACE_TRACE. Referenced by ACE_MMAP_Memory_Pool::commit_backing_store_name(), and ACE_Shared_Memory_MM::get_id().
|
|
||||||||||||||||||||||||||||||||||||||||
|
Map a file specified by .
Definition at line 185 of file Mem_Map.cpp. References ACE_OFF_T, ACE_TCHAR, ACE_TRACE, map_it(), mode_t, and open().
00194 {
00195 ACE_TRACE ("ACE_Mem_Map::map");
00196 this->length_ = 0;
00197
00198 if (this->open (file_name,
00199 flags,
00200 mode,
00201 sa) == -1)
00202 return -1;
00203 else
00204 return this->map_it (this->handle (),
00205 len,
00206 prot,
00207 share,
00208 addr,
00209 offset,
00210 sa);
00211 }
|
|
||||||||||||||||||||||||||||
|
Remap the file associated with .
Definition at line 42 of file Mem_Map.inl. References ACE_OFF_T, ACE_TRACE, base_addr_, MAP_FAILED, MAP_FIXED, and map_it().
00048 {
00049 ACE_TRACE ("ACE_Mem_Map::map");
00050 // If we're already mapped at a particular location then try to
00051 // remap the file using the same base address.
00052 if (addr == 0 && this->base_addr_ != 0 && this->base_addr_ != MAP_FAILED)
00053 {
00054 share |= MAP_FIXED;
00055 addr = this->base_addr_;
00056 }
00057
00058 return this->map_it (this->handle (), length, prot,
00059 share, addr, offset, sa);
00060 }
|
|
||||||||||||||||||||||||||||||||
|
Map a file from an open file descriptor handle. This function will lookup the length of the file if it is not given. Definition at line 27 of file Mem_Map.inl. References ACE_OFF_T, ACE_TRACE, and map_it(). Referenced by ACE_Filecache_Object::ACE_Filecache_Object(), ACE_Mem_Map(), ACE_MMAP_Memory_Pool::init_acquire(), ACE_MMAP_Memory_Pool::map_file(), ACE_Shared_Memory_MM::open(), and ACE_Filecache_Object::release().
|
|
||||||||||||||||||||||||||||||||
|
This method does the dirty work of actually calling ::mmap to map the file into memory. Definition at line 61 of file Mem_Map.cpp. References ACE_OFF_T, ACE_TRACE, base_addr_, close_filemapping_handle(), ACE_OS::filesize(), MAP_FAILED, ACE_Numeric_Limits< T >::max(), ACE_OS::mmap(), ACE_OS::pwrite(), and unmap(). Referenced by map().
00068 {
00069 ACE_TRACE ("ACE_Mem_Map::map_it");
00070
00071 #if defined (ACE_LACKS_AUTO_MMAP_REPLACEMENT)
00072 // If the system does not replace any previous mappings, then
00073 // unmap() before (potentially) mapping to the same location.
00074 int const unmap_result = this->unmap ();
00075 if (unmap_result != 0)
00076 return unmap_result;
00077 #endif /* ACE_LACKS_AUTO_MMAP_REPLACEMENT */
00078
00079 this->base_addr_ = addr;
00080 this->handle_ = handle;
00081
00082 // Get the current filesize
00083 ACE_OFF_T const current_file_length = ACE_OS::filesize (this->handle_);
00084
00085 // Flag to indicate if we need to extend the back store
00086 bool extend_backing_store = false;
00087
00088 // File length requested by user
00089 ACE_OFF_T requested_file_length = 0;
00090
00091 // Check <length_request>
00092 if (length_request == static_cast<size_t> (-1))
00093 {
00094 // Set length to file_request or size_t max.
00095 this->length_ = ACE_Utils::truncate_cast<size_t> (current_file_length - offset);
00096 }
00097 else
00098 {
00099 // Make sure that we have not been asked to do the impossible.
00100 if (static_cast<ACE_UINT64> (length_request)
00101 + static_cast<ACE_UINT64> (offset)
00102 > static_cast<ACE_UINT64> (ACE_Numeric_Limits<ACE_OFF_T>::max ()))
00103 return -1;
00104
00105 // File length implicitly requested by user
00106 requested_file_length = static_cast<ACE_OFF_T> (length_request) + offset;
00107
00108 // Check to see if we need to extend the backing store
00109 if (requested_file_length > current_file_length)
00110 {
00111 // If the length of the mapped region is less than the
00112 // length of the file then we force a complete new remapping
00113 // by setting the descriptor to ACE_INVALID_HANDLE (closing
00114 // down the descriptor if necessary).
00115 this->close_filemapping_handle ();
00116
00117 // Remember to extend the backing store
00118 extend_backing_store = true;
00119 }
00120
00121 // Set length to length_request
00122 this->length_ = length_request;
00123 }
00124
00125 // Check if we need to extend the backing store.
00126 if (extend_backing_store)
00127 {
00128 // Remember than write increases the size by one.
00129 ACE_OFF_T null_byte_position = 0;
00130 if (requested_file_length > 0)
00131 {
00132 // This will make the file size <requested_file_length>
00133 null_byte_position = requested_file_length - 1;
00134 }
00135
00136 if (ACE_OS::pwrite (this->handle_,
00137 "",
00138 1,
00139 null_byte_position) == -1)
00140 return -1;
00141 }
00142
00143 this->base_addr_ = ACE_OS::mmap (this->base_addr_,
00144 this->length_,
00145 prot,
00146 share,
00147 this->handle_,
00148 offset,
00149 &this->file_mapping_,
00150 sa);
00151
00152 return this->base_addr_ == MAP_FAILED ? -1 : 0;
00153 }
|
|
||||||||||||||||||||
|
Open the file without mapping it.
Definition at line 156 of file Mem_Map.cpp. References ACE_TCHAR, ACE_TRACE, close_handle_, MAXPATHLEN, mode_t, ACE_OS::open(), ACE_OS::shm_open(), and ACE_OS::strsncpy(). Referenced by ACE_MMAP_Memory_Pool::init_acquire(), and map().
00160 {
00161 ACE_TRACE ("ACE_Mem_Map::open");
00162
00163 #if defined (INTEGRITY) || defined (__QNXNTO__) || defined (ACE_VXWORKS)
00164 this->handle_ = ACE_OS::shm_open (file_name, flags, perms, sa);
00165 #elif defined (ACE_OPENVMS)
00166 ACE_OSCALL (::open (file_name, flags, perms, "shr=get,put,upd"), ACE_HANDLE, -1, this->handle_);
00167 #else
00168 this->handle_ = ACE_OS::open (file_name, flags, perms, sa);
00169 #endif /* INTEGRITY */
00170
00171 if (this->handle_ == ACE_INVALID_HANDLE)
00172 return -1;
00173 else
00174 {
00175 ACE_OS::strsncpy (this->filename_,
00176 file_name,
00177 MAXPATHLEN);
00178
00179 this->close_handle_ = true;
00180 return 0;
00181 }
00182 }
|
|
|
This operator passes back the starting address of the mapped file. Definition at line 65 of file Mem_Map.inl. References ACE_TRACE, base_addr_, and MAP_FAILED.
00066 {
00067 ACE_TRACE ("ACE_Mem_Map::operator");
00068
00069 if (this->base_addr_ == MAP_FAILED)
00070 return -1;
00071 else
00072 {
00073 addr = this->base_addr_;
00074 return 0;
00075 }
00076 }
|
|
|
|
|
||||||||||||||||
|
Change the protection of the pages of the mapped region to prot starting at addr up to len bytes. Definition at line 203 of file Mem_Map.inl. References ACE_TRACE, and ACE_OS::mprotect().
00204 {
00205 ACE_TRACE ("ACE_Mem_Map::protect");
00206 return ACE_OS::mprotect (addr, len, prot);
00207 }
|
|
|
Change the protection of all the pages of the mapped region to prot starting at . Definition at line 193 of file Mem_Map.inl. References ACE_TRACE, and ACE_OS::mprotect().
00194 {
00195 ACE_TRACE ("ACE_Mem_Map::protect");
00196 return ACE_OS::mprotect (this->base_addr_, this->length_, prot);
00197 }
|
|
||||||||||||
|
Change the protection of the pages of the mapped region to prot starting at up to len bytes. Definition at line 182 of file Mem_Map.inl. References ACE_TRACE, and ACE_OS::mprotect(). Referenced by ACE_MMAP_Memory_Pool::protect().
00183 {
00184 ACE_TRACE ("ACE_Mem_Map::protect");
00185 return ACE_OS::mprotect (this->base_addr_, len, prot);
00186 }
|
|
|
Close and remove the file from the file system.
Definition at line 292 of file Mem_Map.cpp. References ACE_TRACE, close(), ACE_OS::ftruncate(), ACE_OS::shm_unlink(), and ACE_OS::unlink(). Referenced by ACE_MMAP_Memory_Pool::release(), and ACE_Shared_Memory_MM::remove().
00293 {
00294 ACE_TRACE ("ACE_Mem_Map::remove");
00295
00296 ACE_OS::ftruncate (this->handle_, 0);
00297 this->close ();
00298
00299 if (this->filename_[0] != '\0')
00300 #if defined (INTEGRITY) || defined (__QNXNTO__) || defined (ACE_VXWORKS)
00301 return ACE_OS::shm_unlink (this->filename_);
00302 #else
00303 return ACE_OS::unlink (this->filename_);
00304 #endif /* __QNXNTO__ */
00305
00306 else
00307 return 0;
00308 }
|
|
|
This function returns the number of bytes currently mapped in the file. Definition at line 92 of file Mem_Map.inl. References ACE_TRACE. Referenced by ACE_MMAP_Memory_Pool::acquire(), ACE_Shared_Memory_MM::get_segment_size(), ACE_MMAP_Memory_Pool::handle_signal(), and ACE_MMAP_Memory_Pool::init_acquire().
|
|
||||||||||||||||
|
Sync len bytes of the memory region to the backing store starting at . Definition at line 172 of file Mem_Map.inl. References ACE_TRACE, and ACE_OS::msync().
00173 {
00174 ACE_TRACE ("ACE_Mem_Map::sync");
00175 return ACE_OS::msync (addr, len, flags);
00176 }
|
|
|
Sync the whole memory region to the backing store starting at . Definition at line 160 of file Mem_Map.inl. References ACE_TRACE, and ACE_OS::msync().
00161 {
00162 ACE_TRACE ("ACE_Mem_Map::sync");
00163 return ACE_OS::msync (this->base_addr_,
00164 this->length_,
00165 flags);
00166 }
|
|
||||||||||||
|
Sync len bytes of the memory region to the backing store starting at . If len == -1 then sync the whole region. Definition at line 150 of file Mem_Map.inl. References ACE_TRACE, and ACE_OS::msync(). Referenced by ACE_MMAP_Memory_Pool::sync().
00151 {
00152 ACE_TRACE ("ACE_Mem_Map::sync");
00153 return ACE_OS::msync (this->base_addr_,
00154 len,
00155 flags);
00156 }
|
|
||||||||||||
|
Unmap the region starting at .
Definition at line 136 of file Mem_Map.inl. References ACE_TRACE, close_filemapping_handle(), ACE_OS::munmap(), and ssize_t.
00137 {
00138 ACE_TRACE ("ACE_Mem_Map::unmap");
00139
00140 this->close_filemapping_handle ();
00141
00142 return ACE_OS::munmap (addr,
00143 len < 0 ? this->length_ : len);
00144 }
|
|
|
Unmap the region starting at .
Definition at line 116 of file Mem_Map.inl. References ACE_TRACE, base_addr_, close_filemapping_handle(), MAP_FAILED, ACE_OS::munmap(), and ssize_t. Referenced by ACE_Shared_Memory_MM::close(), close(), ACE_MMAP_Memory_Pool::map_file(), map_it(), ACE_Filecache_Object::release(), and ACE_Filecache_Object::~ACE_Filecache_Object().
00117 {
00118 ACE_TRACE ("ACE_Mem_Map::unmap");
00119
00120 this->close_filemapping_handle ();
00121
00122 if (this->base_addr_ != MAP_FAILED)
00123 {
00124 int const result = ACE_OS::munmap (this->base_addr_,
00125 len < 0 ? this->length_ : len);
00126 this->base_addr_ = MAP_FAILED;
00127 return result;
00128 }
00129 else
00130 return 0;
00131 }
|
|
|
Declare the dynamic allocation hooks.
|
|
|
Base address of the memory-mapped file.
Definition at line 207 of file Mem_Map.h. Referenced by addr(), map(), map_it(), operator()(), and unmap(). |
|
|
Keeps track of whether we need to close the handle. This is set if we opened the file. Definition at line 223 of file Mem_Map.h. Referenced by close_handle(), and open(). |
|
|
HANDLE for the open mapping.
Definition at line 219 of file Mem_Map.h. Referenced by close_filemapping_handle(). |
|
|
Name of the file that is mapped.
|
|
|
HANDLE for the open file.
|
|
|
Length of the mapping.
|
1.3.6