Boost logo

Boost Users :

From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2006-07-15 05:21:38


Hi,

> As you suggested mmap returns a different address than the one specified,
> behaving as a named_shared_object under the hood instead of a
> fixed_named_shared_object.
>
> I have used the MAP_FIXED flag for mmap with disastrous results (the man
> pages already discourage you to use this flag). The computer hanged, very
> strange behaviours, etc... It just forces a segment the size you want at the
> address you specify overwriting anything in it's way. Lots of fun as you can
> foresee...

Very interesting. I thought that fixed mapping should always fail if
there is no room for it. But I see that OpenGroup's mmap description
(http://www.opengroup.org/onlinepubs/000095399/functions/mmap.html) states:

"If a MAP_FIXED request is successful, the mapping established by mmap()
replaces any previous mappings for the process' pages in the range
[pa,pa+len)."

"If an application requests a mapping that would overlay existing
mappings in the process, it might be desirable that an implementation
detect this and inform the application. However, the default, portable
(not MAP_FIXED) operation does not overlay existing mappings. On the
other hand, if the program specifies a fixed address mapping (which
requires some implementation knowledge to determine a suitable address,
if the function is supported at all), then the program is presumed to be
successfully managing its own address space and should be trusted when
it asks to map over existing data structures."

"[ENOMEM]
     MAP_FIXED was specified, and the range [addr,addr+len) exceeds that
allowed for the address space of a process; or, if MAP_FIXED was not
specified and there is insufficient room in the address space to effect
the mapping."

So using MAP_FIXED is really dangerous unless you exactly know what you
are managing your own address space. I think that Shmem should not offer
that possibility, because it's very dangerous. If there is user request
for this, I will add it as an option.

To solve your issue, we could avoid using MAP_FIXED and pass the address
as a suggestion. If the returned address is not the suggested address, I
could unmap the segment and return an error. Since we avoid MAP_FIXED,
you will have no risk to overwrite the address space of your shared
libraries or heap. I will write a new version ASAP. Meanwhile, try to
live with a smaller memory size.

Adeu,

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