Boost logo

Boost Users :

Subject: Re: [Boost-users] [Interprocess] error_code_t = 9 (already_exists_error) while opening a fixed_managed_shared_memory
From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2011-05-19 13:38:59


El 19/05/2011 17:52, Gaetan Gaumer escribió:
> Hello Ion and other Interprocess users,
> we are currently working with fixed_managed_shared_memory segments and
> we have a strange behavior while opening existing segments.
> Sometimes (we did not found the exact scenario yet...), when we try to
> open a fixed_managed_shared_memory
> in open_only mode with the code below, we get an
> interprocess_exception with the an error_code_t = 9 (
> already_exists_error ).

That error does not seem the correct answer to the problem.

> Walking the code I found in the mapped_region constructor the
> following code which trigger the exception :
> 522: //Check for fixed mapping error
> if(address&& (old_base != address)){
> error_info err = system_error_code();
> this->priv_close();
> throw interprocess_exception(err);
> }

I think that system_error_code() call is wrong. Mmap was succesful, but
suggested address was not used (MAP_FIXED is not used, because it
removes previous mapping in that address and the portable semantics of
mapped_region need to return an error if that address could not be
used). So the OS should not be called for an error. You can replace that
line, maybe with something like:

error_info err(busy_error);

> So I have two questions :
> 1) Do you have an idea why the mmap function maps the segment at a
> different address from the provided one, knowing that this address
> is the one returned from code below on another process (so should be valid) ?

Every address can be different in each process. Shared memory, in some
systems, shares address space with DLLs and other goodies. Depending on
your memory map when you call mmap, the address chosen by each process
might be different.

> 2) In the mapped_region constructor, when a non null address value is
> given as a parameter, could we use the MAP_FIXED flag to force
> the mmap function to map the segment at the provided address ?

That would break portable semantics, we want mapped_region to fail if
the address was used, otherwise, you might be unmapping DLL code or any
other previous mapping (mapped file, etc.) and bad things will happen.
MAP_FIXED is IMHO usable only to map devices/video memory that you know
exactly where they are placed in your system.

Best,

Ion


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