Sharing memory between applications, server/creator side.
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;
{
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);
return 0;
}
Interface for memory-like objects.
static Env const * env() noexcept
Returns the initial environment for the current task.
L4::Cap< Mem_alloc > mem_alloc() const noexcept
Object-capability to the memory allocator.
L4::Cap< Rm > rm() const noexcept
Object-capability to the region map.
L4::Cap< L4::Irq > register_irq_obj(L4::Epiface *o) override
Register a handler for an interrupt.
L4::Cap< void > register_obj(L4::Epiface *o, char const *service) override
Register a new server object to a pre-allocated receive endpoint.
A server loop object which has a Object_registry included.
Object_registry const * registry() const
Return registry of this server loop.
void L4_NORETURN loop(l4_utcb_t *utcb=l4_utcb())
Start the server loop.
C++ interface for capabilities.
Input/Output stream for IPC [un]marshalling.
virtual int dispatch(unsigned long rights, Ipc::Iostream &ios)=0
The abstract handler for client requests to the object.
unsigned long l4_umword_t
Unsigned machine word.
@ L4_EBADPROTO
Unsupported protocol.
_Cap_alloc & cap_alloc
Capability allocator.
Cap< T > make_cap_rw(L4::Cap< T > cap) noexcept
Make an L4::Ipc::Cap<T> for the given capability with L4_CAP_FPAGE_RW rights.
@ RW
Readable and writable region.
@ Search_addr
Search for a suitable address range.
Server object base class for handling IRQ messages.
Base class (template) for server implementing server objects.
Message tag data structure.
long label() const L4_NOTHROW
Get the protocol value.
Type information server template.