
I've been happily using Boost.Interprocess to create shared memory regions under FreeBSD 7.2, however, I am having issues on FreeBSD 8.0 pre-release. I can reproduce the problem with Boost 1.39.0 and the svn trunk. The source of the problem appears to be that Boost.Interprocess calls lseek on a file descriptor returned by shm_open, but the results of such an lseek are undefined. Below, I explain further how I came to this conclusion. If you run the program I've appended to the end of this email, the constructor for managed_shared_memory throws an interprocess_exception with error code 29 which is Illegal Seek on FreeBSD. A little bit of system call tracing and debugging reveals that the offending seek is in mapped_region.h:447 (in svn revision 55512). However, digging around, it appears that lseek's behavior on file descriptors for shared memory regions is undefined (See http://www.opengroup.org/onlinepubs/000095399/functions/lseek.html for what IEEE 1003.1 standard has to say about this.) I've confirmed that FreeBSD 7.2 allowed such seeks but 8.0 does not by looking at the kernel source code. For what it's worth AIX 6.1 does not allow such seeks either (see http://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.ai...). Could someone advise me on what the correct fix for this bug is? I'd be glad to implement it, but I'm not sure what the right fix ought to be. #include <iostream> #include <string> #include <exception> #include <boost/interprocess/managed_shared_memory.hpp> namespace bip = boost::interprocess; int main(const int argc, const char *argv[]) { bool error = true; std::string shmName("testShmRegion"); bip::shared_memory_object::remove(shmName.c_str()); try { std::auto_ptr<bip::managed_shared_memory> segment(new bip::managed_shared_memory(bip::create_only, shmName.c_str(), 12345)); error = false; } catch(const std::exception &e) { std::cerr << "Error: " << e.what() << std::endl; } if(!error) { std::cout << "Shm allocated successfully." << std::endl; } return 0; } Manish