Sharing memory between applications, server/creator side.
#include <l4/re/util/object_registry>
#include <cstring>
#include <cstdio>
#include <unistd.h>
#include "interface.h"
{
private:
public:
: _shm(shm), _irq(irq)
{}
};
{
(void) obj;
ios >> t;
switch (t.label())
{
case L4::Meta::Protocol:
return L4::Util::handle_meta_request<My_interface>(ios);
case 0:
ios << _shm << _irq;
return 0;
default:
}
}
{
private:
char *_shm;
public:
explicit Shm_observer(char *shm)
: _shm(shm)
{}
};
{
(void)obj;
(void)ios;
printf("Client sent us: %s\n", _shm);
return 0;
}
enum
{
DS_SIZE = 4 << 12,
};
{
if (!(*_ds).is_valid())
{
printf("Dataspace allocation failed.\n");
return 0;
}
if (err < 0)
{
printf("mem_alloc->alloc() failed.\n");
return 0;
}
char *_addr = 0;
if (err < 0)
{
printf("Error attaching data space: %s\n", l4sys_errtostr(err));
return 0;
}
printf("Attached DS\n");
static char const * const msg = "[DS] Hello from server!";
snprintf(_addr, strlen(msg) + 1, msg);
return _addr;
}
int main()
{
char *addr;
if (!(addr = get_ds(&ds)))
return 2;
Shm_observer observer(addr);
My_server_obj server_obj(ds, irq);
server.
registry()->register_obj(&server_obj,
"shm");
return 0;
}