[okl4-developer] Shared memory between two services
Nelson Tam
nelson at ok-labs.com
Tue Feb 26 17:51:32 EST 2008
Hi Damien,
On 24/02/2008, at 2:21 PM, Damien Schulz wrote:
> how can I share memory between two separate address spaces? I want
> to share some pages between a server and a client application but I
> can't figure out the L4_SpaceID_t of myself - so I'm wondering how
> to achieve this.
>
> Any help would be greatly appreciated.
Today I will mention how to do this dynamically during runtime.
Tomorrow I will talk about how to do this statically during
configuration time.
The standard way to set up shared memory in OKL4 is to using
capabilities. Here's one way to do it:
1. One party (let's say the server) creates the memsection. You can
use any of the OKL4 memsection API functions (see libs/iguana/include/
memsections.h) to do this, we shall use the standard
memsection_create() for now.
server.c:
#include <iguana/memsection.h>
#include <iguana/cap.h>
ms = memsection_create(0x1000, &ms_base);
2. The server creates a capability object for that memsection.
server.c:
cap_t cap;
cap.ref.obj = ms;
cap.passwd = 0;
3. Send the cap to the other party (client) using IPC.
4. When the client receives the cap, add it to its cap list.
client.c:
#include <iguana/memsection.h>
#include <iguana/cap.h>
clist_insert(default_clist, cap);
5. From then, the client can access the memsection, dereferencing up
to ms_size bytes starting from ms_base.
client.c:
memsection_ref_t ms = (memsection_ref_t)cap.ref.obj;
void *ms_base = memsection_base(ms);
uintptr_t ms_size = memsection_size(ms);
--
(nt)
Nelson Tam
nelson at ok-labs.com
More information about the Developer
mailing list