ACE_MMAP_Memory_Pool Class Reference

Make a memory pool that is based on mmap(2). This implementation allows memory to be shared between processes. More...

#include <MMAP_Memory_Pool.h>

Inheritance diagram for ACE_MMAP_Memory_Pool:

Inheritance graph
[legend]
Collaboration diagram for ACE_MMAP_Memory_Pool:

Collaboration graph
[legend]
List of all members.

Public Types

typedef ACE_MMAP_Memory_Pool_Options OPTIONS

Public Member Functions

 ACE_MMAP_Memory_Pool (const ACE_TCHAR *backing_store_name=0, const OPTIONS *options=0)
 Initialize the pool.
virtual ~ACE_MMAP_Memory_Pool (void)
 Destructor.
virtual void * init_acquire (size_t nbytes, size_t &rounded_bytes, int &first_time)
 Ask system for initial chunk of shared memory.
virtual void * acquire (size_t nbytes, size_t &rounded_bytes)
virtual int release (int destroy=1)
 Instruct the memory pool to release all of its resources.
virtual int sync (size_t len, int flags=MS_SYNC)
virtual int sync (int flags=MS_SYNC)
virtual int sync (void *addr, size_t len, int flags=MS_SYNC)
 Sync the memory region to the backing store starting at addr.
virtual int protect (size_t len, int prot=PROT_RDWR)
virtual int protect (int prot=PROT_RDWR)
virtual int protect (void *addr, size_t len, int prot=PROT_RDWR)
virtual int remap (void *addr)
virtual void * base_addr (void) const
 Return the base address of this memory pool.
virtual void dump (void) const
 Dump the state of an object.
ACE_Mem_Map const & mmap (void) const
 Get reference to underlying ACE_Mem_Map object.
ACE_Mem_Mapmmap (void)
 Get reference to underlying ACE_Mem_Map object.

Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks.

Protected Member Functions

virtual size_t round_up (size_t nbytes)
virtual int commit_backing_store_name (size_t rounded_bytes, size_t &map_size)
virtual int map_file (size_t map_size)
 Memory map the file up to map_size bytes.
virtual int handle_signal (int signum, siginfo_t *, ucontext_t *)

Protected Attributes

ACE_Sig_Handler signal_handler_
 Handles SIGSEGV.
ACE_Mem_Map mmap_
 Memory-mapping object.
void * base_addr_
int use_fixed_addr_
 Must we use the base_addr_ or can we let mmap(2) select it?
int flags_
 Flags passed into ACE_OS::mmap().
bool write_each_page_
size_t minimum_bytes_
 What the minimum bytes of the initial segment should be.
ACE_TCHAR backing_store_name_ [MAXPATHLEN+1]
 Name of the backing store where the shared memory pool is kept.
bool guess_on_fault_
LPSECURITY_ATTRIBUTES sa_
 Security attributes object, only used on NT.
mode_t file_mode_
 Protection mode for mmaped file.
bool install_signal_handler_
 Should we install a signal handler.

Detailed Description

Make a memory pool that is based on mmap(2). This implementation allows memory to be shared between processes.

Definition at line 136 of file MMAP_Memory_Pool.h.


Member Typedef Documentation

typedef ACE_MMAP_Memory_Pool_Options ACE_MMAP_Memory_Pool::OPTIONS

Definition at line 139 of file MMAP_Memory_Pool.h.


Constructor & Destructor Documentation

ACE_MMAP_Memory_Pool::ACE_MMAP_Memory_Pool ( const ACE_TCHAR backing_store_name = 0,
const OPTIONS options = 0 
)

Initialize the pool.

Definition at line 116 of file MMAP_Memory_Pool.cpp.

References ACE_ERROR, ACE_SET_BITS, ACE_TEXT, ACE_TRACE, ACE_MMAP_Memory_Pool_Options::ALWAYS_FIXED, backing_store_name_, ACE_MMAP_Memory_Pool_Options::base_addr_, base_addr_, ACE_MMAP_Memory_Pool_Options::file_mode_, file_mode_, flags_, ACE_MMAP_Memory_Pool_Options::flags_, ACE::get_temp_dir(), ACE_MMAP_Memory_Pool_Options::guess_on_fault_, guess_on_fault_, ACE_MMAP_Memory_Pool_Options::install_signal_handler_, install_signal_handler_, LM_ERROR, MAXPATHLEN, ACE_MMAP_Memory_Pool_Options::minimum_bytes_, minimum_bytes_, ACE_OS::mktemp(), sa_, ACE_MMAP_Memory_Pool_Options::sa_, SIGSEGV, ACE_OS::strcat(), ACE_OS::strcpy(), ACE_OS::strsncpy(), ACE_MMAP_Memory_Pool_Options::unique_, ACE_MMAP_Memory_Pool_Options::use_fixed_addr_, use_fixed_addr_, ACE_MMAP_Memory_Pool_Options::write_each_page_, and write_each_page_.

00119   : base_addr_ (0),
00120     use_fixed_addr_(0),
00121     flags_ (MAP_SHARED),
00122     write_each_page_ (false),
00123     minimum_bytes_ (0),
00124     sa_ (0),
00125     file_mode_ (ACE_DEFAULT_FILE_PERMS),
00126     install_signal_handler_ (true)
00127 {
00128   ACE_TRACE ("ACE_MMAP_Memory_Pool::ACE_MMAP_Memory_Pool");
00129 
00130 #if (defined (ACE_HAS_SIGINFO_T) && !defined (ACE_LACKS_SI_ADDR)) || defined (ACE_WIN32)
00131       // For plaforms that give the faulting address.
00132       guess_on_fault_ = false;
00133 #else
00134       // For plaforms that do NOT give the faulting address, let the
00135       // options decide whether to guess or not.
00136       if (options)
00137         guess_on_fault_ = options->guess_on_fault_;
00138       else
00139         // If no options are specified, default to true.
00140         guess_on_fault_ = true;
00141 #endif /* (defined (ACE_HAS_SIGINFO_T) && !defined (ACE_LACKS_SI_ADDR)) || defined (ACE_WIN32) */
00142 
00143   // Only change the defaults if <options> != 0.
00144   if (options)
00145     {
00146       if (options->flags_ != 0)
00147         this->flags_ = options->flags_;
00148       use_fixed_addr_ = options->use_fixed_addr_;
00149 
00150       if (use_fixed_addr_ == ACE_MMAP_Memory_Pool_Options::ALWAYS_FIXED)
00151         {
00152           this->base_addr_ = const_cast<void *> (options->base_addr_);
00153           ACE_SET_BITS (flags_, MAP_FIXED);
00154         }
00155       this->write_each_page_ = options->write_each_page_;
00156       this->minimum_bytes_ = options->minimum_bytes_;
00157       if (options->sa_ != 0)
00158         this->sa_ = options->sa_;
00159       this->file_mode_ = options->file_mode_;
00160       this->install_signal_handler_ = options->install_signal_handler_;
00161     }
00162 
00163   if (backing_store_name == 0)
00164     {
00165       // Only create a new unique filename for the backing store file
00166       // if the user didn't supply one...
00167 #if defined (ACE_DEFAULT_BACKING_STORE)
00168       // Create a temporary file.
00169       ACE_OS::strcpy (this->backing_store_name_,
00170                       ACE_DEFAULT_BACKING_STORE);
00171 #else /* ACE_DEFAULT_BACKING_STORE */
00172       if (ACE::get_temp_dir (this->backing_store_name_,
00173                              MAXPATHLEN - 17) == -1)
00174         // -17 for ace-malloc-XXXXXX
00175         {
00176           ACE_ERROR ((LM_ERROR,
00177                       ACE_TEXT ("Temporary path too long, ")
00178                       ACE_TEXT ("defaulting to current directory\n")));
00179           this->backing_store_name_[0] = 0;
00180         }
00181 
00182       // Add the filename to the end
00183       ACE_OS::strcat (this->backing_store_name_,
00184                       ACE_TEXT ("ace-malloc-XXXXXX"));
00185 
00186       // If requested an unique filename, use mktemp to get a random file.
00187       if (options && options->unique_)
00188         ACE_OS::mktemp(this->backing_store_name_);
00189 #endif /* ACE_DEFAULT_BACKING_STORE */
00190     }
00191   else
00192     ACE_OS::strsncpy (this->backing_store_name_,
00193                       backing_store_name,
00194                       (sizeof this->backing_store_name_ / sizeof (ACE_TCHAR)));
00195 
00196 #if !defined (ACE_WIN32)
00197   if (this->install_signal_handler_)
00198     {
00199       if (this->signal_handler_.register_handler (SIGSEGV, this) == -1)
00200         ACE_ERROR ((LM_ERROR,
00201                     "%p\n", this->backing_store_name_));
00202     }
00203 #endif /* ACE_WIN32 */
00204 }

ACE_MMAP_Memory_Pool::~ACE_MMAP_Memory_Pool ( void   )  [virtual]

Destructor.

Definition at line 206 of file MMAP_Memory_Pool.cpp.

00207 {
00208 }


Member Function Documentation

void * ACE_MMAP_Memory_Pool::acquire ( size_t  nbytes,
size_t &  rounded_bytes 
) [virtual]

Acquire at least nbytes from the memory pool. rounded_bytes is the actual number of bytes allocated. Also acquires an internal semaphore that ensures proper serialization of ACE_MMAP_Memory_Pool initialization across processes.

Definition at line 328 of file MMAP_Memory_Pool.cpp.

References ACE_TRACE, mmap_, round_up(), and ACE_Mem_Map::size().

Referenced by init_acquire().

00330 {
00331   ACE_TRACE ("ACE_MMAP_Memory_Pool::acquire");
00332   rounded_bytes = this->round_up (nbytes);
00333 
00334   // ACE_DEBUG ((LM_DEBUG, "(%P|%t) acquiring more chunks, nbytes =
00335   // %B, rounded_bytes = %B\n", nbytes, rounded_bytes));
00336 
00337   size_t map_size;
00338 
00339   if (this->commit_backing_store_name (rounded_bytes,
00340                                        map_size) == -1)
00341     return 0;
00342   else if (this->map_file (map_size) == -1)
00343     return 0;
00344 
00345   // ACE_DEBUG ((LM_DEBUG, "(%P|%t) acquired more chunks, nbytes = %B,
00346   // rounded_bytes = %B, map_size = %B\n", nbytes, rounded_bytes,
00347   // map_size));
00348 
00349   return (void *) ((char *) this->mmap_.addr () + (this->mmap_.size () - rounded_bytes));
00350 }

void * ACE_MMAP_Memory_Pool::base_addr ( void   )  const [virtual]

Return the base address of this memory pool.

Definition at line 543 of file MMAP_Memory_Pool.cpp.

References ACE_TRACE, and base_addr_.

00544 {
00545   ACE_TRACE ("ACE_MMAP_Memory_Pool::base_addr");
00546   return this->base_addr_;
00547 }

int ACE_MMAP_Memory_Pool::commit_backing_store_name ( size_t  rounded_bytes,
size_t &  map_size 
) [protected, virtual]

Compute the new map_size of the backing store and commit the memory.

Definition at line 213 of file MMAP_Memory_Pool.cpp.

References ACE_ERROR_RETURN, ACE_TEXT, ACE_TRACE, ACE_OS::fsync(), ACE_Mem_Map::handle(), LM_ERROR, ACE_OS::lseek(), mmap_, round_up(), and ACE_OS::write().

00215 {
00216   ACE_TRACE ("ACE_MMAP_Memory_Pool::commit_backing_store_name");
00217 
00218 #if defined (__Lynx__)
00219   map_size = rounded_bytes;
00220 #else
00221   size_t seek_len;
00222 
00223   if (this->write_each_page_)
00224     // Write to the end of every block to ensure that we have enough
00225     // space in the backing store.
00226     seek_len = this->round_up (1); // round_up(1) is one page.
00227   else
00228     // We're willing to risk it all in the name of efficiency...
00229     seek_len = rounded_bytes;
00230 
00231   // The following loop will execute multiple times (if
00232   // this->write_each_page == 1) or just once (if
00233   // this->write_each_page == 0).
00234 
00235   for (size_t cur_block = 0;
00236        cur_block < rounded_bytes;
00237        cur_block += seek_len)
00238     {
00239       map_size =
00240         ACE_Utils::truncate_cast<size_t> (
00241           ACE_OS::lseek (this->mmap_.handle (),
00242                          static_cast<ACE_OFF_T> (seek_len - 1),
00243                          SEEK_END));
00244 
00245       if (map_size == static_cast<size_t> (-1)
00246           || ACE_OS::write (this->mmap_.handle (),
00247                             "",
00248                             1) == -1)
00249         ACE_ERROR_RETURN ((LM_ERROR,
00250                            ACE_TEXT ("(%P|%t) %p\n"),
00251                            this->backing_store_name_),
00252                           -1);
00253     }
00254 
00255 #if defined (ACE_OPENVMS)
00256   ::fsync(this->mmap_.handle());
00257 #endif
00258 
00259   // Increment by one to put us at the beginning of the next chunk...
00260   ++map_size;
00261 #endif /* __Lynx__ */
00262   return 0;
00263 }

ACE_BEGIN_VERSIONED_NAMESPACE_DECL void ACE_MMAP_Memory_Pool::dump ( void   )  const [virtual]

Dump the state of an object.

Definition at line 30 of file MMAP_Memory_Pool.cpp.

References ACE_TRACE.

00031 {
00032 #if defined (ACE_HAS_DUMP)
00033   ACE_TRACE ("ACE_MMAP_Memory_Pool::dump");
00034 #endif /* ACE_HAS_DUMP */
00035 }

int ACE_MMAP_Memory_Pool::handle_signal ( int  signum,
siginfo_t ,
ucontext_t  
) [protected, virtual]

Handle SIGSEGV and SIGBUS signals to remap memory properly. When a process reads or writes to non-mapped memory a signal (SIGBUS or SIGSEGV) will be triggered. At that point, the ACE_Sig_Handler (which is part of the ACE_Reactor) will catch the signal and dispatch the handle_signal() method defined here. If the SIGSEGV signal occurred due to the fact that the mapping wasn't uptodate with respect to the backing store, the handler method below will update the mapping accordingly. When the signal handler returns, the instruction should be restarted and the operation should work.

Reimplemented from ACE_Event_Handler.

Definition at line 486 of file MMAP_Memory_Pool.cpp.

References ACE_DEBUG, ACE_TEXT, ACE_OS::filesize(), guess_on_fault_, LM_DEBUG, map_file(), and SIGSEGV.

00487 {
00488   if (signum != SIGSEGV)
00489     return -1;
00490 #if 0
00491   else
00492     ACE_DEBUG ((LM_DEBUG,  ACE_TEXT ("(%P|%t) received %S\n"), signum));
00493 #endif
00494   // ACE_DEBUG ((LM_DEBUG,  ACE_TEXT ("(%P|%t) new mapping address = %@\n"), (char *) this->base_addr_ + current_map_size));
00495 
00496 #if defined (ACE_HAS_SIGINFO_T) && !defined (ACE_LACKS_SI_ADDR)
00497   // Make sure that the pointer causing the problem is within the
00498   // range of the backing store.
00499 
00500   if (siginfo != 0)
00501     {
00502       // ACE_DEBUG ((LM_DEBUG,  ACE_TEXT ("(%P|%t) si_signo = %d, si_code = %d, addr = %@\n"), siginfo->si_signo, siginfo->si_code, siginfo->si_addr));
00503       if (this->remap ((void *) siginfo->si_addr) == -1)
00504         return -1;
00505       // ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) address %@ out of range\n",
00506       // siginfo->si_addr), -1);
00507       return 0;
00508     }
00509 #else
00510   ACE_UNUSED_ARG(siginfo);
00511 #endif /* ACE_HAS_SIGINFO_T && !defined ACE_LACKS_SI_ADDR */
00512   // If guess_on_fault_ is true, then we want to try to remap without
00513   // knowing the faulting address.  guess_on_fault_ can only be true
00514   // on platforms that do not provide the faulting address through
00515   // signals or exceptions.  We check to see if the mapping is up to
00516   // date. If it is, then this fault isn't due to this mapping and we
00517   // pass it on.
00518   if (guess_on_fault_)
00519     {
00520       // Check if the current mapping is up to date.
00521       size_t const current_map_size =
00522         ACE_Utils::truncate_cast<size_t> (ACE_OS::filesize (this->mmap_.handle ()));
00523 
00524       if (static_cast<size_t> (current_map_size) == this->mmap_.size ())
00525         {
00526           // The mapping is up to date so this really is a bad
00527           // address.  Thus, remove current signal handler so process
00528           // will fail with default action and core file will be
00529           // written.
00530           this->signal_handler_.remove_handler (SIGSEGV);
00531           return 0;
00532         }
00533 
00534       // Extend the mapping to cover the size of the backing store.
00535       return this->map_file (current_map_size);
00536     }
00537   else
00538     return -1;
00539 }

void * ACE_MMAP_Memory_Pool::init_acquire ( size_t  nbytes,
size_t &  rounded_bytes,
int &  first_time 
) [virtual]

Ask system for initial chunk of shared memory.

Definition at line 355 of file MMAP_Memory_Pool.cpp.

References ACE_ERROR_RETURN, ACE_SET_BITS, ACE_TEXT, ACE_TRACE, acquire(), ACE_Mem_Map::addr(), ACE_MMAP_Memory_Pool_Options::FIRSTCALL_FIXED, flags_, LM_ERROR, minimum_bytes_, mmap_, PROT_RDWR, ACE_Mem_Map::size(), and use_fixed_addr_.

00358 {
00359   ACE_TRACE ("ACE_MMAP_Memory_Pool::init_acquire");
00360 
00361   first_time = 0;
00362 
00363   if (nbytes < static_cast <size_t> (this->minimum_bytes_))
00364     nbytes = static_cast <size_t> (this->minimum_bytes_);
00365 
00366   if (this->mmap_.open (this->backing_store_name_,
00367                         O_RDWR | O_CREAT | O_TRUNC | O_EXCL,
00368                         this->file_mode_, this->sa_) != -1)
00369     {
00370       // First time in, so need to acquire memory.
00371       first_time = 1;
00372 
00373       void *result = this->acquire (nbytes, rounded_bytes);
00374       // After the first time, reset the flag so that subsequent calls
00375       // will use MAP_FIXED
00376       if (use_fixed_addr_ == ACE_MMAP_Memory_Pool_Options::FIRSTCALL_FIXED)
00377         {
00378           ACE_SET_BITS (flags_, MAP_FIXED);
00379         }
00380       return result;
00381     }
00382   else if (errno == EEXIST)
00383     {
00384       errno = 0;
00385       // Reopen file *without* using O_EXCL...
00386       if (this->mmap_.map (this->backing_store_name_,
00387                            static_cast<size_t> (-1),
00388                            O_RDWR,
00389                            this->file_mode_,
00390                            PROT_RDWR,
00391                            this->flags_,
00392                            this->base_addr_,
00393                            0,
00394                            this->sa_) == -1)
00395         ACE_ERROR_RETURN ((LM_ERROR,
00396                            ACE_TEXT ("%p\n"),
00397                            ACE_TEXT ("MMAP_Memory_Pool::init_acquire, EEXIST")),
00398                           0);
00399       // After the first time, reset the flag so that subsequent calls
00400       // will use MAP_FIXED
00401       if (use_fixed_addr_ == ACE_MMAP_Memory_Pool_Options::FIRSTCALL_FIXED)
00402         {
00403           ACE_SET_BITS (flags_, MAP_FIXED);
00404         }
00405 #if (ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1)
00406       // Update the mapped segment information
00407       ACE_BASED_POINTER_REPOSITORY::instance ()->bind (this->mmap_.addr(),
00408                                                        this->mmap_.size());
00409 #endif /* ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1 */
00410 
00411       return this->mmap_.addr ();
00412     }
00413   else
00414     ACE_ERROR_RETURN ((LM_ERROR,
00415                        ACE_TEXT ("%p\n"),
00416                        ACE_TEXT ("MMAP_Memory_Pool::init_acquire")),
00417                       0);
00418 }

int ACE_MMAP_Memory_Pool::map_file ( size_t  map_size  )  [protected, virtual]

Memory map the file up to map_size bytes.

Definition at line 268 of file MMAP_Memory_Pool.cpp.

References ACE_ERROR, ACE_TEXT, ACE_TRACE, ACE_Mem_Map::addr(), backing_store_name_, base_addr_, LM_ERROR, mmap_, ACE_MMAP_Memory_Pool_Options::NEVER_FIXED, PROT_RDWR, ACE_Mem_Map::unmap(), and use_fixed_addr_.

Referenced by handle_signal(), and remap().

00269 {
00270   ACE_TRACE ("ACE_MMAP_Memory_Pool::map_file");
00271 #if (ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1)
00272     void* obase_addr = this->base_addr_;
00273 #endif /* ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1 */
00274 
00275   // Unmap the existing mapping.
00276   this->mmap_.unmap ();
00277 
00278 #if (ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1)
00279   if (use_fixed_addr_ == ACE_MMAP_Memory_Pool_Options::NEVER_FIXED)
00280     this->base_addr_ = 0;
00281 #endif /* ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1 */
00282 
00283   // Remap the file; try to stay at the same location as a previous mapping
00284   // but do not force it with MAP_FIXED. Doing so will give the OS permission
00285   // to map locations currently holding other things (such as the heap, or
00286   // the C library) into the map file, producing very unexpected results.
00287   if (this->mmap_.map (map_size,
00288                        PROT_RDWR,
00289                        this->flags_,
00290                        this->base_addr_,
00291                        0,
00292                        this->sa_) == -1
00293       || this->base_addr_ != 0
00294 #ifdef ACE_HAS_WINCE
00295       && this->mmap_.addr () == 0)  // WinCE does not allow users to specify alloc addr.
00296 #else
00297       && this->mmap_.addr () != this->base_addr_)
00298 #endif  // ACE_HAS_WINCE
00299     {
00300 #if 0
00301       ACE_ERROR ((LM_ERROR,
00302                   ACE_TEXT ("(%P|%t) addr = %@, base_addr = %@, map_size = %B, %p\n"),
00303                   this->mmap_.addr (),
00304                   this->base_addr_,
00305                   map_size,
00306                   this->backing_store_name_));
00307 #endif /* 0 */
00308       return -1;
00309     }
00310   else
00311     {
00312 #if (ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1)
00313       this->base_addr_ = this->mmap_.addr ();
00314       if(obase_addr && this->base_addr_ != obase_addr)
00315          ACE_BASED_POINTER_REPOSITORY::instance ()->unbind (obase_addr);
00316       ACE_BASED_POINTER_REPOSITORY::instance ()->bind (this->base_addr_,
00317                                                        map_size);
00318 #endif /* ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1 */
00319       return 0;
00320     }
00321 }

ACE_INLINE ACE_Mem_Map & ACE_MMAP_Memory_Pool::mmap ( void   ) 

Get reference to underlying ACE_Mem_Map object.

Definition at line 16 of file MMAP_Memory_Pool.inl.

References mmap_.

00017 {
00018   return mmap_;
00019 }

ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_INLINE ACE_Mem_Map const & ACE_MMAP_Memory_Pool::mmap ( void   )  const

Get reference to underlying ACE_Mem_Map object.

Definition at line 9 of file MMAP_Memory_Pool.inl.

References mmap_.

00010 {
00011   return mmap_;
00012 }

int ACE_MMAP_Memory_Pool::protect ( void *  addr,
size_t  len,
int  prot = PROT_RDWR 
) [virtual]

Change the protection of the pages of the mapped region to prot starting at addr up to len bytes.

Definition at line 110 of file MMAP_Memory_Pool.cpp.

References ACE_TRACE, and ACE_OS::mprotect().

00111 {
00112   ACE_TRACE ("ACE_MMAP_Memory_Pool::protect");
00113   return ACE_OS::mprotect (addr, len, prot);
00114 }

int ACE_MMAP_Memory_Pool::protect ( int  prot = PROT_RDWR  )  [virtual]

Change the protection of all the pages of the mapped region to prot starting at this->base_addr_.

Definition at line 95 of file MMAP_Memory_Pool.cpp.

References ACE_TRACE, ACE_OS::lseek(), mmap_, and ACE_Mem_Map::protect().

00096 {
00097   ACE_TRACE ("ACE_MMAP_Memory_Pool::protect");
00098 
00099   size_t const len = ACE_Utils::truncate_cast<size_t> (
00100     ACE_OS::lseek (this->mmap_.handle (), 0, SEEK_END));
00101 
00102   return this->mmap_.protect (len, prot);
00103 }

int ACE_MMAP_Memory_Pool::protect ( size_t  len,
int  prot = PROT_RDWR 
) [virtual]

Change the protection of the pages of the mapped region to prot starting at this->base_addr_ up to len bytes. If len == -1 then change protection of all pages in the mapped region.

Definition at line 87 of file MMAP_Memory_Pool.cpp.

References ACE_TRACE, mmap_, and ACE_Mem_Map::protect().

00088 {
00089   ACE_TRACE ("ACE_MMAP_Memory_Pool::protect");
00090 
00091   return this->mmap_.protect (len, prot);
00092 }

int ACE_MMAP_Memory_Pool::release ( int  destroy = 1  )  [virtual]

Instruct the memory pool to release all of its resources.

Definition at line 38 of file MMAP_Memory_Pool.cpp.

References ACE_TRACE, ACE_Mem_Map::close(), mmap_, and ACE_Mem_Map::remove().

00039 {
00040   ACE_TRACE ("ACE_MMAP_Memory_Pool::release");
00041 
00042 #if (ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1)
00043   ACE_BASED_POINTER_REPOSITORY::instance ()->unbind (this->mmap_.addr ());
00044 #endif /* ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1 */
00045 
00046   if (destroy)
00047   this->mmap_.remove ();
00048   else
00049     this->mmap_.close ();
00050   return 0;
00051 }

int ACE_MMAP_Memory_Pool::remap ( void *  addr  )  [virtual]

Try to extend the virtual address space so that addr is now covered by the address mapping. The method succeeds and returns 0 if the backing store has adequate memory to cover this address. Otherwise, it returns -1. This method is typically called by a UNIX signal handler for SIGSEGV or a Win32 structured exception when another process has grown the backing store (and its mapping) and our process now incurs a fault because our mapping isn't in range (yet).

Definition at line 440 of file MMAP_Memory_Pool.cpp.

References ACE_TRACE, ACE_OS::filesize(), and map_file().

00441 {
00442   ACE_TRACE ("ACE_MMAP_Memory_Pool::remap");
00443   //  ACE_DEBUG ((LM_DEBUG,  ACE_TEXT ("Remapping with fault address at: %@\n"), addr));
00444   size_t const current_map_size =
00445     ACE_Utils::truncate_cast<size_t> (ACE_OS::filesize (this->mmap_.handle ()));
00446   // ACE_OS::lseek (this->mmap_.handle (), 0, SEEK_END);
00447 
00448   if (!(addr < (void *) ((char *) this->mmap_.addr () + current_map_size)
00449         && addr >= this->mmap_.addr ()))
00450     return -1;
00451 
00452   // Extend the mapping to cover the size of the backing store.
00453   return this->map_file (current_map_size);
00454 }

size_t ACE_MMAP_Memory_Pool::round_up ( size_t  nbytes  )  [protected, virtual]

Implement the algorithm for rounding up the request to an appropriate chunksize.

Definition at line 550 of file MMAP_Memory_Pool.cpp.

References ACE_TRACE, and ACE::round_to_pagesize().

Referenced by acquire(), and commit_backing_store_name().

00551 {
00552   ACE_TRACE ("ACE_MMAP_Memory_Pool::round_up");
00553   return ACE::round_to_pagesize (nbytes);
00554 }

int ACE_MMAP_Memory_Pool::sync ( void *  addr,
size_t  len,
int  flags = MS_SYNC 
) [virtual]

Sync the memory region to the backing store starting at addr.

Reimplemented in ACE_Lite_MMAP_Memory_Pool.

Definition at line 76 of file MMAP_Memory_Pool.cpp.

References ACE_TRACE, and ACE_OS::msync().

00077 {
00078   ACE_TRACE ("ACE_MMAP_Memory_Pool::sync");
00079   return ACE_OS::msync (addr, len, flags);
00080 }

int ACE_MMAP_Memory_Pool::sync ( int  flags = MS_SYNC  )  [virtual]

Sync the memory region to the backing store starting at this->base_addr_. Will sync as much as the backing file allows.

Reimplemented in ACE_Lite_MMAP_Memory_Pool.

Definition at line 62 of file MMAP_Memory_Pool.cpp.

References ACE_TRACE, ACE_OS::lseek(), mmap_, and ACE_Mem_Map::sync().

00063 {
00064   ACE_TRACE ("ACE_MMAP_Memory_Pool::sync");
00065 
00066   size_t const len = ACE_Utils::truncate_cast<size_t> (
00067     ACE_OS::lseek (this->mmap_.handle (), 0, SEEK_END));
00068 
00069   return this->mmap_.sync (len, flags);
00070 }

int ACE_MMAP_Memory_Pool::sync ( size_t  len,
int  flags = MS_SYNC 
) [virtual]

Sync the memory region to the backing store starting at this->base_addr_.

Reimplemented in ACE_Lite_MMAP_Memory_Pool.

Definition at line 54 of file MMAP_Memory_Pool.cpp.

References ACE_TRACE, mmap_, and ACE_Mem_Map::sync().

00055 {
00056   ACE_TRACE ("ACE_MMAP_Memory_Pool::sync");
00057 
00058   return this->mmap_.sync (len, flags);
00059 }


Member Data Documentation

ACE_MMAP_Memory_Pool::ACE_ALLOC_HOOK_DECLARE

Declare the dynamic allocation hooks.

Definition at line 230 of file MMAP_Memory_Pool.h.

ACE_TCHAR ACE_MMAP_Memory_Pool::backing_store_name_[MAXPATHLEN+1] [protected]

Name of the backing store where the shared memory pool is kept.

Definition at line 289 of file MMAP_Memory_Pool.h.

Referenced by ACE_MMAP_Memory_Pool(), and map_file().

void* ACE_MMAP_Memory_Pool::base_addr_ [protected]

Base of mapped region. If this has the value of 0 then the OS is free to select any address to map the file, otherwise this value is what the OS must try to use to mmap the file.

Definition at line 273 of file MMAP_Memory_Pool.h.

Referenced by ACE_MMAP_Memory_Pool(), base_addr(), and map_file().

mode_t ACE_MMAP_Memory_Pool::file_mode_ [protected]

Protection mode for mmaped file.

Definition at line 302 of file MMAP_Memory_Pool.h.

Referenced by ACE_MMAP_Memory_Pool().

int ACE_MMAP_Memory_Pool::flags_ [protected]

Flags passed into ACE_OS::mmap().

Definition at line 279 of file MMAP_Memory_Pool.h.

Referenced by ACE_MMAP_Memory_Pool(), and init_acquire().

bool ACE_MMAP_Memory_Pool::guess_on_fault_ [protected]

Try to remap without knowing the faulting address. This parameter is ignored on platforms that know the faulting address (UNIX with SI_ADDR and Win32).

Definition at line 296 of file MMAP_Memory_Pool.h.

Referenced by ACE_MMAP_Memory_Pool(), and handle_signal().

bool ACE_MMAP_Memory_Pool::install_signal_handler_ [protected]

Should we install a signal handler.

Definition at line 305 of file MMAP_Memory_Pool.h.

Referenced by ACE_MMAP_Memory_Pool().

size_t ACE_MMAP_Memory_Pool::minimum_bytes_ [protected]

What the minimum bytes of the initial segment should be.

Definition at line 286 of file MMAP_Memory_Pool.h.

Referenced by ACE_MMAP_Memory_Pool(), and init_acquire().

ACE_Mem_Map ACE_MMAP_Memory_Pool::mmap_ [protected]

Memory-mapping object.

Definition at line 266 of file MMAP_Memory_Pool.h.

Referenced by acquire(), commit_backing_store_name(), init_acquire(), map_file(), mmap(), protect(), release(), and sync().

LPSECURITY_ATTRIBUTES ACE_MMAP_Memory_Pool::sa_ [protected]

Security attributes object, only used on NT.

Definition at line 299 of file MMAP_Memory_Pool.h.

Referenced by ACE_MMAP_Memory_Pool().

ACE_Sig_Handler ACE_MMAP_Memory_Pool::signal_handler_ [protected]

Handles SIGSEGV.

Definition at line 262 of file MMAP_Memory_Pool.h.

int ACE_MMAP_Memory_Pool::use_fixed_addr_ [protected]

Must we use the base_addr_ or can we let mmap(2) select it?

Definition at line 276 of file MMAP_Memory_Pool.h.

Referenced by ACE_MMAP_Memory_Pool(), init_acquire(), and map_file().

bool ACE_MMAP_Memory_Pool::write_each_page_ [protected]

Should we write a byte to each page to forceably allocate memory for this backing store?

Definition at line 283 of file MMAP_Memory_Pool.h.

Referenced by ACE_MMAP_Memory_Pool().


The documentation for this class was generated from the following files:
Generated on Tue Feb 2 17:35:21 2010 for ACE by  doxygen 1.4.7