2012-05-30 20:13:09 +02:00
|
|
|
/*
|
|
|
|
* \brief Implementation of the Genode IPC-framework
|
|
|
|
* \author Martin Stein
|
2016-03-13 22:55:48 +01:00
|
|
|
* \author Norman Feske
|
2012-05-30 20:13:09 +02:00
|
|
|
* \date 2012-02-12
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2013-01-10 21:44:47 +01:00
|
|
|
* Copyright (C) 2012-2013 Genode Labs GmbH
|
2012-05-30 20:13:09 +02:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
|
|
|
* under the terms of the GNU General Public License version 2.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Genode includes */
|
2015-05-19 14:18:40 +02:00
|
|
|
#include <base/env.h>
|
2012-05-30 20:13:09 +02:00
|
|
|
#include <base/ipc.h>
|
2015-05-19 14:18:40 +02:00
|
|
|
#include <base/allocator.h>
|
2012-05-30 20:13:09 +02:00
|
|
|
#include <base/thread.h>
|
2015-05-19 14:18:40 +02:00
|
|
|
#include <base/native_env.h>
|
|
|
|
#include <util/construct_at.h>
|
|
|
|
#include <util/retry.h>
|
2013-11-14 17:29:34 +01:00
|
|
|
|
2016-03-08 16:59:43 +01:00
|
|
|
/* base-internal includes */
|
|
|
|
#include <base/internal/native_utcb.h>
|
2016-03-11 17:32:43 +01:00
|
|
|
#include <base/internal/native_thread.h>
|
2016-03-15 20:01:59 +01:00
|
|
|
#include <base/internal/ipc_server.h>
|
2016-03-08 16:59:43 +01:00
|
|
|
|
2013-11-14 17:29:34 +01:00
|
|
|
/* base-hw includes */
|
|
|
|
#include <kernel/interface.h>
|
2012-05-30 20:13:09 +02:00
|
|
|
#include <kernel/log.h>
|
|
|
|
|
2015-05-19 14:18:40 +02:00
|
|
|
namespace Hw { extern Genode::Untyped_capability _main_thread_cap; }
|
|
|
|
|
2012-05-30 20:13:09 +02:00
|
|
|
using namespace Genode;
|
|
|
|
|
|
|
|
|
2015-05-19 14:18:40 +02:00
|
|
|
/*****************************
|
|
|
|
** IPC marshalling support **
|
|
|
|
*****************************/
|
|
|
|
|
2016-03-13 22:55:48 +01:00
|
|
|
void Ipc_marshaller::insert(Native_capability const &cap) {
|
|
|
|
_snd_msg.cap_add(cap); }
|
2015-05-19 14:18:40 +02:00
|
|
|
|
|
|
|
|
2016-03-13 22:55:48 +01:00
|
|
|
void Ipc_unmarshaller::extract(Native_capability &cap) {
|
|
|
|
cap = _rcv_msg.cap_get(); }
|
2012-05-30 20:13:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
/****************
|
2016-03-15 20:01:59 +01:00
|
|
|
** IPC client **
|
2012-05-30 20:13:09 +02:00
|
|
|
****************/
|
|
|
|
|
2016-03-15 20:01:59 +01:00
|
|
|
Rpc_exception_code Genode::ipc_call(Native_capability dst,
|
|
|
|
Msgbuf_base &snd_msg, Msgbuf_base &rcv_msg,
|
|
|
|
size_t rcv_caps)
|
2012-05-30 20:13:09 +02:00
|
|
|
{
|
2016-03-15 20:01:59 +01:00
|
|
|
rcv_msg.cap_rcv_window(rcv_caps);
|
|
|
|
|
|
|
|
Native_utcb &utcb = *Thread_base::myself()->utcb();
|
|
|
|
|
2015-05-19 14:18:40 +02:00
|
|
|
retry<Genode::Allocator::Out_of_memory>(
|
|
|
|
[&] () {
|
|
|
|
|
|
|
|
/* send request and receive corresponding reply */
|
2016-03-15 20:01:59 +01:00
|
|
|
Thread_base::myself()->utcb()->copy_from(snd_msg);
|
2015-05-19 14:18:40 +02:00
|
|
|
|
2016-03-15 20:01:59 +01:00
|
|
|
switch (Kernel::send_request_msg(dst.dst(),
|
|
|
|
rcv_msg.cap_rcv_window())) {
|
2015-05-19 14:18:40 +02:00
|
|
|
case -1: throw Blocking_canceled();
|
|
|
|
case -2: throw Allocator::Out_of_memory();
|
|
|
|
default:
|
2016-03-15 20:01:59 +01:00
|
|
|
rcv_msg.reset();
|
|
|
|
utcb.copy_to(rcv_msg);
|
2015-05-19 14:18:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
[&] () { upgrade_pd_session_quota(3*4096); });
|
2016-03-13 22:55:48 +01:00
|
|
|
|
2016-03-15 20:01:59 +01:00
|
|
|
return Rpc_exception_code(utcb.exception_code());
|
2016-03-13 22:55:48 +01:00
|
|
|
}
|
2012-05-30 20:13:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
/****************
|
|
|
|
** Ipc_server **
|
|
|
|
****************/
|
|
|
|
|
2016-03-13 22:55:48 +01:00
|
|
|
void Ipc_server::reply()
|
2013-10-17 13:51:17 +02:00
|
|
|
{
|
2016-03-15 20:01:59 +01:00
|
|
|
Thread_base::myself()->utcb()->copy_from(_snd_msg);
|
2016-03-13 22:55:48 +01:00
|
|
|
_snd_msg.reset();
|
2015-05-19 14:18:40 +02:00
|
|
|
Kernel::send_reply_msg(0, false);
|
2013-10-17 13:51:17 +02:00
|
|
|
}
|
2012-05-30 20:13:09 +02:00
|
|
|
|
|
|
|
|
2016-03-13 22:55:48 +01:00
|
|
|
void Ipc_server::reply_wait()
|
2012-05-30 20:13:09 +02:00
|
|
|
{
|
2016-03-15 20:01:59 +01:00
|
|
|
Native_utcb &utcb = *Thread_base::myself()->utcb();
|
2013-10-17 16:07:47 +02:00
|
|
|
|
2015-05-19 14:18:40 +02:00
|
|
|
retry<Genode::Allocator::Out_of_memory>(
|
|
|
|
[&] () {
|
2016-03-15 20:01:59 +01:00
|
|
|
int ret = 0;
|
|
|
|
if (_reply_needed) {
|
|
|
|
utcb.copy_from(_snd_msg);
|
|
|
|
utcb.exception_code(_exception_code.value);
|
|
|
|
ret = Kernel::send_reply_msg(Msgbuf_base::MAX_CAP_ARGS, true);
|
|
|
|
} else {
|
|
|
|
ret = Kernel::await_request_msg(Msgbuf_base::MAX_CAP_ARGS);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (ret) {
|
2015-05-19 14:18:40 +02:00
|
|
|
case -1: throw Blocking_canceled();
|
|
|
|
case -2: throw Allocator::Out_of_memory();
|
2016-03-15 20:01:59 +01:00
|
|
|
default: break;
|
2015-05-19 14:18:40 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
[&] () { upgrade_pd_session_quota(3*4096); });
|
2016-03-15 20:01:59 +01:00
|
|
|
|
|
|
|
_rcv_msg.reset();
|
|
|
|
_snd_msg.reset();
|
|
|
|
|
|
|
|
utcb.copy_to(_rcv_msg);
|
|
|
|
_badge = utcb.destination();
|
|
|
|
|
|
|
|
_reply_needed = true;
|
|
|
|
_read_offset = _write_offset = 0;
|
2012-05-30 20:13:09 +02:00
|
|
|
}
|
2016-03-11 21:47:12 +01:00
|
|
|
|
|
|
|
|
2016-03-13 22:55:48 +01:00
|
|
|
Ipc_server::Ipc_server(Native_connection_state &cs,
|
|
|
|
Msgbuf_base &snd_msg, Msgbuf_base &rcv_msg)
|
|
|
|
:
|
|
|
|
Ipc_marshaller(snd_msg), Ipc_unmarshaller(rcv_msg),
|
|
|
|
Native_capability(Thread_base::myself() ? Thread_base::myself()->native_thread().cap
|
|
|
|
: Hw::_main_thread_cap),
|
2016-03-15 20:01:59 +01:00
|
|
|
_rcv_cs(cs)
|
2016-03-13 22:55:48 +01:00
|
|
|
{
|
|
|
|
_snd_msg.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-11 21:47:12 +01:00
|
|
|
Ipc_server::~Ipc_server() { }
|