L4Re - L4 Runtime Environment
examples/libs/l4re/streammap/server.cc

Client/Server example showing how to map a page to another task – Server implementation. Note that there's also a shared memory library that supplies this functionality in more convenient way.

/*
* (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
* Alexander Warg <warg@os.inf.tu-dresden.de>
* economic rights: Technische Universit├Ąt Dresden (Germany)
*
* This file is part of TUD:OS and distributed under the terms of the
* GNU General Public License 2.
* Please see the COPYING-GPL-2 file for details.
*/
#include <stdio.h>
#include <l4/re/env>
#include <l4/re/util/object_registry>
#include "shared.h"
static char page_to_map[L4_PAGESIZE] __attribute__((aligned(L4_PAGESIZE)));
class Smap_server : public L4::Server_object_t<Mapper>
{
public:
int dispatch(l4_umword_t obj, L4::Ipc::Iostream &ios);
};
int
Smap_server::dispatch(l4_umword_t, L4::Ipc::Iostream &ios)
{
ios >> t;
// We're only talking the Map_example protocol
if (t.label() != Mapper::Protocol)
return -L4_EBADPROTO;
L4::Opcode opcode;
ios >> opcode;
switch (opcode)
{
case Mapper::Do_map:
l4_addr_t snd_base;
ios >> snd_base;
// put something into the page to read it out at the other side
snprintf(page_to_map, sizeof(page_to_map), "Hello from the server!");
printf("Sending to client\n");
// send page
ios << L4::Ipc::Snd_fpage::mem((l4_addr_t)page_to_map, L4_PAGESHIFT,
L4_FPAGE_RO, snd_base);
return L4_EOK;
default:
return -L4_ENOSYS;
}
}
int
main()
{
static Smap_server smap;
// Register server
if (!server.registry()->register_obj(&smap, "smap").is_valid())
{
printf("Could not register my service, read-only namespace?\n");
return 1;
}
printf("Welcome to the memory map example server!\n");
// Wait for client requests
server.loop();
return 0;
}