Click to See Complete Forum and Search --> : Obtaing a Virtual address for shared memory...
m_ajmera
November 21st, 2005, 02:14 PM
Hi Guys,
I have a user space DLL that can be called by multiple processes. This DLL deals with a buffer that is shared across the processes. The buffer is allocated by a driver and the DLL does an IOCTL call at the start to get the User Virtual address for that buffer in that process's context.
Now when the DLL is called by another process, is there a way to convert that virtual address to this process's context?
I want to avoid having to do an IOCTL call every time a process calls the DLL.
NigelQ
November 21st, 2005, 07:08 PM
You didn't mention which compiler or environment you're using, so I'll assume Microsoft (most other compilers and platforms have very similar features)...
It sounds like this page (http://support.microsoft.com/default.aspx?scid=kb;en-us;125677) describes what you are looking for. It describes a method of sharing a section of data between different instances of the same DLL (or executable).
Be aware that you will need to protect access to this data using something like a Mutex, to provide some sort of synchronization. This is clearly because multiple threads will be accessing this data segment, which can lead to very unpredictable results.
Hope this helps,
- Nigel
m_ajmera
November 21st, 2005, 08:32 PM
Thanks Nigel, but I don't think that'll work for my case.
That method would work if my DLL were the one allocating the buffer (in which case I would put the buffer in the data_seg).
In my case the DLL does not allocate the buffer, the buffer is allocated by a driver and I am only provided with a User Virtual Address to the pointer.
Boris K K
November 22nd, 2005, 07:03 AM
Isn't it an option your DLL to maintain one address for each client process? During the first call from the process the driver will be queried for the buffer address and this address can be used for all subsequent calls from the same process.
m_ajmera
November 22nd, 2005, 08:51 AM
That is how it is doing it right now.
I have a table of processes and their corresponding pointer. I was wondering if there is a easier graceful way to do this.
Boris K K
November 28th, 2005, 07:11 AM
Even if there were a documented way to convert a virtual address from the space of one process to another (and I don't think there is) I doubt it would be easier or more graceful. What would happen, for example, if the "primary" process (the only one for which you have requested the buffer address from the driver) terminates but there are other processes still using the DLL?
m_ajmera
November 28th, 2005, 11:38 AM
Hmm,
Good point.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.