Boost logo

Boost Users :

Subject: [Boost-users] [Interprocess] How to prevent collision of mapping addresses with DLL Loading on Windows?
From: pheres (ph3res_at_[hidden])
Date: 2009-12-14 03:28:30


Hi,

I do something like

fixed_managed_shared_memory segment
  (open_only,
  "MyFixedAddressSharedMemory" //Shared memory object name
  ,(void*)0x30000000 //Mapping address

to establish an shared memory segment which gets faded into the virtual
address space
of every process taking part on the IPC at the same offset (this is
important for me).
This works quite well for most processes.
But problems arise with IPC-clients using a lot of delay loaded DLL's.
This seems to be especially to be true for MFC windows programs.
While normal loaded DLL's goes to 0x10000000, or their fixed address or
are relocated to some there like 0x0...,
some windows delay loaded DLL's seem to can be placed nearly anywhere
inside the virtual address space,
This makes the success of establishing the IPC into a lottery game.

For example I used 0x40000000 for a shared memory range in the IPC
clients. One client used windows MFC.
Taking part on the IPC inside this client should happen after some
pushbutton was pressed but it failed sometimes.
I found out that in the moment of the button press windows delay loaded
two additional DLL's which
unfortunately faded in at the memory range I configured for the IPC
(around 0x40000000).

I was not able to find a 100% satisfying solution. The best thing I came
up with was:
-link everything you can static
-Link the self produced DLL's with fixed base address
-Allocate the memory range as the first call in main() using OS-specific
functions like VirtualAlloc()
-Free the allocated memory just before initializing the IPC (so it's
sure that no delay loaded DLL can be faded in in the mean time)
-for the rest (mainly windows or other 3rd party DLLs) hope the best

This seem to work at least for now but I guess there must be a more
elegant solution.
I did google a lot about the MS loader/run time linker, but there seems
to be no option to
prevent it from selecting a certain address range.
Could anybody help me out?

Thank you in advance!

Best Regards
Joerg


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