summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschmidt <douglascraigschmidt@users.noreply.github.com>2011-12-29 15:18:08 +0000
committerschmidt <douglascraigschmidt@users.noreply.github.com>2011-12-29 15:18:08 +0000
commitba0edb144b5119b911045a34376e6680e0f76a49 (patch)
treed3fb1d343044d22f256ec2addd492c950afc2c59
parent1a6dafc9b053d96b2c0bd71814b1c234068b980f (diff)
downloadATCD-ba0edb144b5119b911045a34376e6680e0f76a49.tar.gz
ChangeLogTag:Thu
-rw-r--r--ACE/ChangeLog13
-rw-r--r--ACE/THANKS1
-rw-r--r--ACE/ace/Mem_Map.cpp133
3 files changed, 88 insertions, 59 deletions
diff --git a/ACE/ChangeLog b/ACE/ChangeLog
index dfb21889547..4539fdaa579 100644
--- a/ACE/ChangeLog
+++ b/ACE/ChangeLog
@@ -1,3 +1,16 @@
+Thu Dec 29 15:14:45 UTC 2011 Douglas C. Schmidt <schmidt@dre.vanderbilt.edu>
+
+ * ace/Mem_Map.cpp (ACE_Mem_Map::map_it): Further improved the
+ error checking. Thanks to JaeSung Lee <berise at gmail dot
+ com> for suggesting this.
+
+Tue Dec 27 15:19:56 UTC 2011 Douglas C. Schmidt <schmidt@dre.vanderbilt.edu>
+
+ * ace/Mem_Map.cpp (ACE_Mem_Map::map_it): mmap through character
+ device doesn't care about it's size, so map with /dev/* is done
+ with a special case. Thanks to JaeSung Lee <berise at gmail dot
+ com> for reporting this and providing a fix.
+
Tue Dec 27 11:39:53 UTC 2011 Johnny Willemsen <jwillemsen@remedy.nl>
* NEWS:
diff --git a/ACE/THANKS b/ACE/THANKS
index 2a92a7261e3..1729d3689c0 100644
--- a/ACE/THANKS
+++ b/ACE/THANKS
@@ -2355,6 +2355,7 @@ Chad Beaulac <chad dot beaulac at objectivesolutions dot com>
Jochen Meier <gesammeltimusenet2009 at arcor dot de>
Thomas Pauli <thomas dot pauli at tu-dortmund dot de>
Qiao Zhiqiang <qiaozhiqiang at leadcoretech dot com>
+JaeSung Lee <berise at gmail dot com>
I would particularly like to thank Paul Stephenson, who worked with me
at Ericsson in the early 1990's. Paul devised the recursive Makefile
diff --git a/ACE/ace/Mem_Map.cpp b/ACE/ace/Mem_Map.cpp
index 1f75fa9bced..cc5fba9c519 100644
--- a/ACE/ace/Mem_Map.cpp
+++ b/ACE/ace/Mem_Map.cpp
@@ -13,8 +13,6 @@
#include "ace/Log_Msg.h"
#include "ace/Truncate.h"
-
-
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
ACE_ALLOC_HOOK_DEFINE(ACE_Mem_Map)
@@ -79,74 +77,91 @@ 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_);
+ // 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_, &current_file_type);
- // Flag to indicate if we need to extend the back store
- bool extend_backing_store = false;
+ if (result == -1)
+ // Something wrong found, bail out.
+ return -1;
+ else if ((current_file_type.st_mode & S_IFMT) == S_IFCHR)
+ // Set length to length_request
+ this->length_ = length_request;
+ else if (current_file_type.st_mode & S_IFMT) == S_IFREG)
+ {
+ // Get the current filesize
+ ACE_OFF_T const current_file_length = ACE_OS::filesize (this->handle_);
- // File length requested by user
- ACE_OFF_T requested_file_length = 0;
+ // Flag to indicate if we need to extend the back store
+ bool extend_backing_store = false;
- // Check <length_request>
- if (length_request == static_cast<size_t> (-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)
+ // File length requested by user
+ ACE_OFF_T requested_file_length = 0;
+
+ // Check <length_request>
+ if (length_request == static_cast<size_t> (-1))
{
- this->length_ = ACE_OS::getpagesize ();
+ // 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 */
}
-#endif
- }
- 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)
+ else
{
- // 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;
+ // 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;
}
- // Set length to length_request
- this->length_ = length_request;
- }
-
- // 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)
+ // Check if we need to extend the backing store.
+ if (extend_backing_store)
{
- // This will make the file size <requested_file_length>
- null_byte_position = requested_file_length - 1;
+ // 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;
- if (ACE_OS::pwrite (this->handle_,
- "",
- 1,
- null_byte_position) == -1)
- return -1;
- }
-
- this->base_addr_ = ACE_OS::mmap (this->base_addr_,
+ this->base_addr_ = ACE_OS::mmap (this->base_addr_,
this->length_,
prot,
share,