diff options
author | Nay <dnpd.dd@gmail.com> | 2012-09-17 23:21:01 +0100 |
---|---|---|
committer | Nay <dnpd.dd@gmail.com> | 2012-09-17 23:21:01 +0100 |
commit | 2e21fa6b925c4572d620248f1b149a5d652836b2 (patch) | |
tree | d0ff026bc848d7ee466c9b793f42fb9ec4f07f62 /dep/acelite/ace/Mem_Map.cpp | |
parent | 6ebc6b9a76d0a4576306d777b35ec1a37d3ec5da (diff) |
Core/Dependencies: Update ACE to v6.1.4 (Windows only)
Tested in multiple configurations
.diff with TC changes added
Diffstat (limited to 'dep/acelite/ace/Mem_Map.cpp')
-rw-r--r-- | dep/acelite/ace/Mem_Map.cpp | 133 |
1 files changed, 79 insertions, 54 deletions
diff --git a/dep/acelite/ace/Mem_Map.cpp b/dep/acelite/ace/Mem_Map.cpp index baf9ce36189..c4e689ec842 100644 --- a/dep/acelite/ace/Mem_Map.cpp +++ b/dep/acelite/ace/Mem_Map.cpp @@ -1,8 +1,9 @@ -// $Id: Mem_Map.cpp 91286 2010-08-05 09:04:31Z johnnyw $ +// $Id: Mem_Map.cpp 95716 2012-05-01 07:49:04Z johnnyw $ // Defines the member functions for the memory mapping facility. #include "ace/Mem_Map.h" + #if !defined (__ACE_INLINE__) #include "ace/Mem_Map.inl" #endif /* __ACE_INLINE__ */ @@ -13,13 +14,10 @@ #include "ace/Log_Msg.h" #include "ace/Truncate.h" - - ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_ALLOC_HOOK_DEFINE(ACE_Mem_Map) - void ACE_Mem_Map::dump (void) const { @@ -79,68 +77,95 @@ ACE_Mem_Map::map_it (ACE_HANDLE handle, this->base_addr_ = addr; this->handle_ = handle; - // Get the current filesize - ACE_OFF_T const current_file_length = ACE_OS::filesize (this->handle_); - - // Flag to indicate if we need to extend the back store - bool extend_backing_store = false; - - // File length requested by user - ACE_OFF_T requested_file_length = 0; + // mmap through character device doens't care about it's size + // So map with /dev/* is done with a special case. + ACE_stat current_file_type; + int result = ACE_OS::fstat (this->handle_, ¤t_file_type); - // Check <length_request> - if (length_request == static_cast<size_t> (-1)) + if (result == -1) { - // Set length to file_request or size_t max. - this->length_ = ACE_Utils::truncate_cast<size_t> (current_file_length - offset); + // Something wrong found, bail out. + return -1; } - else + else if ((current_file_type.st_mode & S_IFMT) == S_IFCHR) { - // Make sure that we have not been asked to do the impossible. - if (static_cast<ACE_UINT64> (length_request) - + static_cast<ACE_UINT64> (offset) - > static_cast<ACE_UINT64> (ACE_Numeric_Limits<ACE_OFF_T>::max ())) - return -1; - - // File length implicitly requested by user - requested_file_length = static_cast<ACE_OFF_T> (length_request) + offset; - - // Check to see if we need to extend the backing store - if (requested_file_length > current_file_length) - { - // If the length of the mapped region is less than the - // length of the file then we force a complete new remapping - // by setting the descriptor to ACE_INVALID_HANDLE (closing - // down the descriptor if necessary). - this->close_filemapping_handle (); - - // Remember to extend the backing store - extend_backing_store = true; - } - // Set length to length_request this->length_ = length_request; } - - // Check if we need to extend the backing store. - if (extend_backing_store) + else if ((current_file_type.st_mode & S_IFMT) == S_IFREG) { - // Remember than write increases the size by one. - ACE_OFF_T null_byte_position = 0; - if (requested_file_length > 0) + // Get the current filesize + ACE_OFF_T const current_file_length = ACE_OS::filesize (this->handle_); + + // Flag to indicate if we need to extend the back store + bool extend_backing_store = false; + + // File length requested by user + ACE_OFF_T requested_file_length = 0; + + // Check <length_request> + if (length_request == static_cast<size_t> (-1)) { - // This will make the file size <requested_file_length> - null_byte_position = requested_file_length - 1; + // Set length to file_request or size_t max. + this->length_ = ACE_Utils::truncate_cast<size_t> (current_file_length - offset); +#if defined (ACE_MMAP_NO_ZERO) + if (this->length_ == 0) + { + this->length_ = ACE_OS::getpagesize (); + } +#endif /* ACE_MMAP_NO_ZERO */ + } + else + { + // Make sure that we have not been asked to do the impossible. + if (static_cast<ACE_UINT64> (length_request) + + static_cast<ACE_UINT64> (offset) + > static_cast<ACE_UINT64> (ACE_Numeric_Limits<ACE_OFF_T>::max ())) + return -1; + + // File length implicitly requested by user + requested_file_length = static_cast<ACE_OFF_T> (length_request) + offset; + + // Check to see if we need to extend the backing store + if (requested_file_length > current_file_length) + { + // If the length of the mapped region is less than the + // length of the file then we force a complete new remapping + // by setting the descriptor to ACE_INVALID_HANDLE (closing + // down the descriptor if necessary). + this->close_filemapping_handle (); + + // Remember to extend the backing store + extend_backing_store = true; + } + + // Set length to length_request + this->length_ = length_request; } - if (ACE_OS::pwrite (this->handle_, - "", - 1, - null_byte_position) == -1) - return -1; - } + // Check if we need to extend the backing store. + if (extend_backing_store) + { + // Remember than write increases the size by one. + ACE_OFF_T null_byte_position = 0; + if (requested_file_length > 0) + { + // This will make the file size <requested_file_length> + null_byte_position = requested_file_length - 1; + } + + if (ACE_OS::pwrite (this->handle_, + "", + 1, + null_byte_position) == -1) + return -1; + } + } + else + // Unmappable file type. + return -1; - this->base_addr_ = ACE_OS::mmap (this->base_addr_, + this->base_addr_ = ACE_OS::mmap (this->base_addr_, this->length_, prot, share, |