Opened 12 years ago

Closed 12 years ago

#5108 closed Bugs (fixed)

shared memory object temporary name bug, Mac OSX 10.6.6

Reported by: david.ibbitson@… Owned by: Ion Gaztañaga
Milestone: To Be Determined Component: interprocess
Version: Boost 1.45.0 Severity: Showstopper
Keywords: shared memory object Cc:

Description

There is a problem with creating a shared memory object in a 64 bit application and trying to open it in a 32 bit application. The problem seems to stem from the following snippet of code, found in the function get_bootstamp defined on line 50 of the file tmp_dir_helpers.hpp.

   std::size_t char_counter = 0;
   long fields[2] = { result.tv_sec, result.tv_usec };
   for(std::size_t field = 0; field != 2; ++field){
      for(std::size_t i = 0; i != sizeof(long); ++i){
         const char *ptr = (const char *)&fields[field];
         bootstamp_str[char_counter++] = Characters[(ptr[i]&0xF0)>>4];
         bootstamp_str[char_counter++] = Characters[(ptr[i]&0x0F)];
      }
   }

On my system sizeof(long) = 4 under a 32 bit application, and sizeof(long) = 8 on a 64 bit application. Hence the generated temporary filename stored in bootstamp_str is of differing lengths under a 32 bit app and a 64 bit app respectively. Hence, I was seeing the error "file or directory does not exist" when trying to open a named shared memory object.

The fix (cross platform?) seems to be to use the type "long long" because sizeof(long long) = 8 under 32 and 64 bit application.

   std::size_t char_counter = 0;
   long long fields[2] = { result.tv_sec, result.tv_usec };
   for(std::size_t field = 0; field != 2; ++field){
      for(std::size_t i = 0; i != sizeof(long long); ++i){
         const char *ptr = (const char *)&fields[field];
         bootstamp_str[char_counter++] = Characters[(ptr[i]&0xF0)>>4];
         bootstamp_str[char_counter++] = Characters[(ptr[i]&0x0F)];
      }
   }

Making this change fixed this problem for me. Hope this helps!

David

Attachments (1)

main.cpp (1.5 KB ) - added by david.ibbitson@… 12 years ago.
Program demonstrating Leopard sysctl bug.

Download all attachments as: .zip

Change History (5)

comment:1 by David Ibbitson <david.ibbitson@…>, 12 years ago

It looks like ticket #4251 is related if not the same issue.

comment:2 by david.ibbitson@…, 12 years ago

Severity: ProblemShowstopper

by david.ibbitson@…, 12 years ago

Attachment: main.cpp added

Program demonstrating Leopard sysctl bug.

comment:3 by david.ibbitson@…, 12 years ago

Another update. It appears that on Leopard the sysctl function periodically returns an invalid timeval struct under a 64 bit build. In particular the microsecond field is occasionally incorrect. See the attached file for a sample program that shows the issue.

comment:4 by Ion Gaztañaga, 12 years ago

Resolution: fixed
Status: newclosed

Disabled bootstamp in Boost 1.47. This means that shared memory/queues will go to /tmp if it exists. If /tmp is not cleared on reboot shared memory will survive to reboots, but this behaviour is allowed by POSIX. Using bootstamps to detect reboots is doing more harm than good.

Note: See TracTickets for help on using tickets.