Boost logo

Boost Users :

Subject: Re: [Boost-users] [Interprocess] Communication between x86 and x64 issue
From: TUELLER, SHAYNE R CIV USAF AFMC 519 SMXS/MXDEC (shayne.tueller_at_[hidden])
Date: 2016-02-19 13:28:41


If memory serves, boost::interprocess::managed_shared_memory has issues with
shared memory between 32-bit and 64-bit applications, at least on Windows 7.

I've used boost::interprocess::shared_memory_object to map shared memory
between 32-bit and 64-bit applications without any trouble.

Here's some code snippets to set things up...

struct SMdata
{
....
}

32-bit application code (creates shared memory for read/write):

boost::interprocess::shared_memory_object* shm;
boost::interprocess::mapped_region* region;
SMdata* data;
shm = new boost::interprocess::shared_memory_object(create_only, "SHMEM",
read_write);
shm->truncate(sizeof(SMdata));
region = new mapped_region(*shm, read_write);
void* addr = region->get_address();
data = new (addr)SMdata;
// data can now be written to and read from

64-bit application code (opens shared memory for read/write):

SMdata* data;
boost::interprocess::shared_memory_object shm(open_only, "SHMEM",
read_write);
mapped_region region(shm, read_write);
void* addr = region.get_address();
data = static_cast<SMdata*>(addr);
// data can now be written to and read from

Obviously, you'll need to synchronize/protect the shared memory with the
objects provided for in boost::interprocess when you do the reads and writes
to the shared memory structure...

HTH

Shayne

-----Original Message-----
From: Boost-users [mailto:boost-users-bounces_at_[hidden]] On Behalf Of
Jan Boehme
Sent: Thursday, February 18, 2016 1:11 AM
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] [Interprocess] Communication between x86 and x64
issue

On 07/29/2015 10:02 PM, Toni Neubert wrote:
> I want to communicate between different platforms using boost
interprocess.
>
> I am using vc12 and boost 1.58 on windows 7.
>
> My code below is a very simple example, that should work. But it
> doesn't for communications between different platforms...
>
> If I create it in x64 and open in win32, the process stuck at a lock
> at function try_based_lock in
> boost/int/sync/detail/common_algorithms.hpp
>
> In the other way around: win32 create, x64 open: the process crashes
> at name_length in segment_manager_helper.hpp while trying to find the
> name in index (priv_generic_find in segment_manager).
>
> #include <iostream>
> #include <boost/interprocess/managed_shared_memory.hpp>
>
> int main() {
> namespace bip = boost::interprocess;
>
> // open in WIN32, create in x64
> #ifdef _WIN32
> bip::managed_shared_memory msm(bip::open_only, "TestIPC"); #elsif
> X64
> bip::shared_memory_object::remove("TestIPC");
> bip::managed_shared_memory msm(bip::create_only, "TestIPC", 4096);
> msm.construct<uint32_t>("Data")[1](10);
> #endif
>
> // Get Data and print it
> auto data = msm.find<uint32_t>("Data"); if (data.second == 1) {
> std::cout << *data.first << std::endl; } std::cin.ignore();
>
> return 0;
> }
>
> Does anybody have experience in this? Thank you in advance!

Hello,

some things indicate that's not possible to do with boost::interprocess:

#1 The internal structure, look at the header struct for example, uses data
types that are different in length at 32 vs 64 bit arch.

#2 Using a hex editor and looking at the shm for the object shows that there
are major differences in the area before your actual data ( which might be
safe). The reason for this is #1.And this is the reason for undefined
behavior when trying to access it.

Regards, Jan

_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users




Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net