|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r65861 - in trunk/boost/interprocess: . detail
From: igaztanaga_at_[hidden]
Date: 2010-10-09 12:31:38
Author: igaztanaga
Date: 2010-10-09 12:31:36 EDT (Sat, 09 Oct 2010)
New Revision: 65861
URL: http://svn.boost.org/trac/boost/changeset/65861
Log:
Workaround for shared memory and FreeBsd jails
Text files modified:
trunk/boost/interprocess/detail/intermodule_singleton.hpp | 31 ++++++++++++++--------
trunk/boost/interprocess/detail/workaround.hpp | 2 +
trunk/boost/interprocess/shared_memory_object.hpp | 55 +++++++++++++++++++++++++++++++++++----
3 files changed, 71 insertions(+), 17 deletions(-)
Modified: trunk/boost/interprocess/detail/intermodule_singleton.hpp
==============================================================================
--- trunk/boost/interprocess/detail/intermodule_singleton.hpp (original)
+++ trunk/boost/interprocess/detail/intermodule_singleton.hpp 2010-10-09 12:31:36 EDT (Sat, 09 Oct 2010)
@@ -37,7 +37,7 @@
#include <sys/stat.h>
#include <errno.h>
-#if (defined BOOST_INTERPROCESS_WINDOWS)
+#if defined (BOOST_INTERPROCESS_WINDOWS)
#include <fcntl.h>
#include <io.h>
@@ -433,7 +433,7 @@
void operator()()
{
- locking_file_serial_id *pserial_id = shm_.find<locking_file_serial_id>("lock_file_fd").first;
+ locking_file_serial_id *pserial_id = shm_.template find<locking_file_serial_id>("lock_file_fd").first;
if(pserial_id){
pserial_id->fd = GMemMarkToBeRemoved;
}
@@ -507,7 +507,7 @@
//First find the file locking descriptor id
locking_file_serial_id *pserial_id =
- mshm.find<locking_file_serial_id>("lock_file_fd").first;
+ mshm.template find<locking_file_serial_id>("lock_file_fd").first;
int fd;
//If not found schedule a creation
@@ -570,7 +570,7 @@
private:
locking_file_serial_id * register_lock_file(int fd)
{
- locking_file_serial_id *pinfo = mshm.construct<locking_file_serial_id>("lock_file_fd")();
+ locking_file_serial_id *pinfo = mshm.template construct<locking_file_serial_id>("lock_file_fd")();
fill_file_serial_id(fd, *pinfo);
return pinfo;
}
@@ -580,7 +580,9 @@
bool retry_with_new_shm;
};
-template <>
+#if defined (BOOST_INTERPROCESS_WINDOWS)
+
+template<>
struct lock_file_logic<managed_windows_shared_memory>
{
lock_file_logic(managed_windows_shared_memory &)
@@ -591,6 +593,8 @@
const bool retry_with_new_shm;
};
+#endif
+
} //namespace intermodule_singleton_helpers {
//This class contains common code for all singleton types, so that we instantiate this
@@ -632,7 +636,8 @@
return *static_cast<ManagedShMem *>(static_cast<void *>(&shm_mem));
}
- static const std::size_t MemSize = ((sizeof(ManagedShMem)-1)/sizeof(max_align))+1u;
+ enum { MemSize = ((sizeof(ManagedShMem)-1)/sizeof(max_align))+1u };
+
static void initialize_shm();
static void destroy_shm();
//Static data, zero-initalized without any dependencies
@@ -709,7 +714,7 @@
void operator()()
{
intermodule_singleton_helpers::locking_file_serial_id *pserial_id =
- mshm_.find<intermodule_singleton_helpers::locking_file_serial_id>
+ mshm_.template find<intermodule_singleton_helpers::locking_file_serial_id>
("lock_file_fd").first;
BOOST_ASSERT(0 != pserial_id);
if(1 == atomic_dec32(&pserial_id->modules_attached_to_gmem_count)){
@@ -728,6 +733,8 @@
ManagedShMem &mshm_;
};
+#if defined (BOOST_INTERPROCESS_WINDOWS)
+
template<>
struct unlink_shmlogic<managed_windows_shared_memory>
{
@@ -736,6 +743,8 @@
void operator()(){}
};
+#endif
+
template<class ManagedShMem>
void intermodule_singleton_common<ManagedShMem>::destroy_shm()
@@ -913,11 +922,11 @@
void operator()()
{
- ref_count_ptr *rcount = mshm.find<ref_count_ptr>(unique_instance).first;
+ ref_count_ptr *rcount = mshm.template find<ref_count_ptr>(unique_instance).first;
if(!rcount){
C *p = new C();
try{
- rcount = mshm.construct<ref_count_ptr>(unique_instance)(p, 0u);
+ rcount = mshm.template construct<ref_count_ptr>(unique_instance)(p, 0u);
}
catch(...){
delete p;
@@ -941,7 +950,7 @@
void operator()()
{
- ref_count_ptr *rcount = mshm.find<ref_count_ptr>(unique_instance).first;
+ ref_count_ptr *rcount = mshm.template find<ref_count_ptr>(unique_instance).first;
//The object must exist
BOOST_ASSERT(rcount);
//Check if last reference
@@ -950,7 +959,7 @@
BOOST_ASSERT(rcount->ptr != 0);
delete rcount->ptr;
//Now destroy shm entry
- bool destroyed = mshm.destroy<ref_count_ptr>(unique_instance);
+ bool destroyed = mshm.template destroy<ref_count_ptr>(unique_instance);
(void)destroyed; BOOST_ASSERT(destroyed == true);
}
}
Modified: trunk/boost/interprocess/detail/workaround.hpp
==============================================================================
--- trunk/boost/interprocess/detail/workaround.hpp (original)
+++ trunk/boost/interprocess/detail/workaround.hpp 2010-10-09 12:31:36 EDT (Sat, 09 Oct 2010)
@@ -101,6 +101,8 @@
// hp-ux tru64 vms freebsd
#if defined(__hpux) || defined(__osf__) || defined(__vms) || (defined(__FreeBSD__) && (__FreeBSD__ < 7))
#define BOOST_INTERPROCESS_FILESYSTEM_BASED_POSIX_SHARED_MEMORY
+ #elif defined(__FreeBSD__)
+ #define BOOST_INTERPROCESS_RUNTIME_FILESYSTEM_BASED_POSIX_SHARED_MEMORY
#endif
#endif
Modified: trunk/boost/interprocess/shared_memory_object.hpp
==============================================================================
--- trunk/boost/interprocess/shared_memory_object.hpp (original)
+++ trunk/boost/interprocess/shared_memory_object.hpp 2010-10-09 12:31:36 EDT (Sat, 09 Oct 2010)
@@ -32,6 +32,11 @@
# include <sys/mman.h> //shm_xxx
# include <unistd.h> //ftruncate, close
# include <sys/stat.h> //mode_t, S_IRWXG, S_IRWXO, S_IRWXU,
+# if defined(BOOST_INTERPROCESS_RUNTIME_FILESYSTEM_BASED_POSIX_SHARED_MEMORY)
+# if defined(__FreeBSD__)
+# include <sys/sysctl.h>
+# endif
+# endif
#else
//
#endif
@@ -240,16 +245,46 @@
#else //!defined(BOOST_INTERPROCESS_POSIX_SHARED_MEMORY_OBJECTS)
+namespace shared_memory_object_detail {
+
+#ifdef BOOST_INTERPROCESS_RUNTIME_FILESYSTEM_BASED_POSIX_SHARED_MEMORY
+
+#if defined(__FreeBSD__)
+
+inline bool use_filesistem_based_posix()
+{
+ int jailed = 0;
+ std::size_t len = sizeof(jailed);
+ ::sysctlbyname("security.jail.jailed", &jailed, &len, NULL, 0);
+ return jailed != 0;
+}
+
+#else
+#error "Not supported platform for BOOST_INTERPROCESS_RUNTIME_FILESYSTEM_BASED_POSIX_SHARED_MEMORY"
+#endif
+
+#endif
+
+} //shared_memory_object_detail
+
inline bool shared_memory_object::priv_open_or_create
(detail::create_enum_t type,
const char *filename,
mode_t mode, const permissions &perm)
{
- #ifndef BOOST_INTERPROCESS_FILESYSTEM_BASED_POSIX_SHARED_MEMORY
- detail::add_leading_slash(filename, m_filename);
+ #if defined(BOOST_INTERPROCESS_FILESYSTEM_BASED_POSIX_SHARED_MEMORY)
+ const bool add_leading_slash = false;
+ #elif defined(BOOST_INTERPROCESS_RUNTIME_FILESYSTEM_BASED_POSIX_SHARED_MEMORY)
+ const bool add_leading_slash = !shared_memory_object_detail::use_filesistem_based_posix();
#else
- detail::create_tmp_and_clean_old_and_get_filename(filename, m_filename);
+ const bool add_leading_slash = true;
#endif
+ if(add_leading_slash){
+ detail::add_leading_slash(filename, m_filename);
+ }
+ else{
+ detail::create_tmp_and_clean_old_and_get_filename(filename, m_filename);
+ }
//Create new mapping
int oflag = 0;
@@ -304,11 +339,19 @@
{
try{
std::string file_str;
- #ifndef BOOST_INTERPROCESS_FILESYSTEM_BASED_POSIX_SHARED_MEMORY
- detail::add_leading_slash(filename, file_str);
+ #if defined(BOOST_INTERPROCESS_FILESYSTEM_BASED_POSIX_SHARED_MEMORY)
+ const bool add_leading_slash = false;
+ #elif defined(BOOST_INTERPROCESS_RUNTIME_FILESYSTEM_BASED_POSIX_SHARED_MEMORY)
+ const bool add_leading_slash = !shared_memory_object_detail::use_filesistem_based_posix();
#else
- detail::tmp_filename(filename, file_str);
+ const bool add_leading_slash = true;
#endif
+ if(add_leading_slash){
+ detail::add_leading_slash(filename, file_str);
+ }
+ else{
+ detail::tmp_filename(filename, file_str);
+ }
return 0 == shm_unlink(file_str.c_str());
}
catch(...){
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk