mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-23 07:22:25 +00:00
cda07b7da0
This commit replaces the stateful 'Ipc_client' type with the plain function 'ipc_call' that takes all the needed state as arguments. The stateful 'Ipc_server' class is retained but it moved from the public API to the internal ipc_server.h header. The kernel-specific implementations were cleaned up and simplified. E.g., the 'wait' function does no longer exist. The badge and exception code are no longer carried in the message buffers but are handled in kernel-specific ways. Issue #610 Issue #1832
141 lines
3.0 KiB
C++
141 lines
3.0 KiB
C++
/*
|
|
* \brief IPC message buffers
|
|
* \author Martin Stein
|
|
* \author Stefan Kalkowski
|
|
* \date 2012-01-03
|
|
*/
|
|
|
|
/*
|
|
* Copyright (C) 2012-2015 Genode Labs GmbH
|
|
*
|
|
* This file is part of the Genode OS framework, which is distributed
|
|
* under the terms of the GNU General Public License version 2.
|
|
*/
|
|
|
|
#ifndef _INCLUDE__BASE__IPC_MSGBUF_H_
|
|
#define _INCLUDE__BASE__IPC_MSGBUF_H_
|
|
|
|
#include <base/native_capability.h>
|
|
#include <base/stdint.h>
|
|
#include <util/string.h>
|
|
|
|
namespace Genode {
|
|
|
|
class Native_utcb;
|
|
|
|
class Ipc_marshaller;
|
|
|
|
/**
|
|
* IPC message buffer layout
|
|
*/
|
|
class Msgbuf_base;
|
|
|
|
/**
|
|
* Instance of IPC message buffer with specified buffer size
|
|
*
|
|
* 'Msgbuf_base' must be the last class this class inherits from.
|
|
*/
|
|
template <unsigned BUF_SIZE> class Msgbuf;
|
|
}
|
|
|
|
|
|
class Genode::Msgbuf_base
|
|
{
|
|
public:
|
|
|
|
enum { MAX_CAP_ARGS = 4 };
|
|
|
|
private:
|
|
|
|
friend class Native_utcb;
|
|
friend class Ipc_marshaller;
|
|
|
|
size_t const _capacity; /* buffer size in bytes */
|
|
size_t _data_size = 0; /* marshalled data in bytes */
|
|
Native_capability _caps[MAX_CAP_ARGS]; /* capability buffer */
|
|
size_t _snd_cap_cnt = 0; /* capability counter */
|
|
size_t _rcv_cap_cnt = 0; /* capability counter */
|
|
|
|
public:
|
|
|
|
/*************************************************
|
|
** 'buf' must be the last member of this class **
|
|
*************************************************/
|
|
|
|
char buf[]; /* begin of actual message buffer */
|
|
|
|
Msgbuf_base(size_t capacity) : _capacity(capacity) { }
|
|
|
|
void const * base() const { return &buf; }
|
|
|
|
/**
|
|
* Return size of message buffer
|
|
*/
|
|
size_t capacity() const { return _capacity; }
|
|
|
|
/**
|
|
* Return pointer of message data payload
|
|
*/
|
|
void *data() { return &buf[0]; }
|
|
void const *data() const { return &buf[0]; }
|
|
|
|
size_t data_size() const { return _data_size; }
|
|
|
|
/**
|
|
* Reset capability buffer.
|
|
*/
|
|
void reset()
|
|
{
|
|
_snd_cap_cnt = 0;
|
|
_rcv_cap_cnt = 0;
|
|
}
|
|
|
|
/**
|
|
* Return how many capabilities are accepted by this message buffer
|
|
*/
|
|
size_t cap_rcv_window() { return _rcv_cap_cnt; }
|
|
|
|
/**
|
|
* Set how many capabilities are accepted by this message buffer
|
|
*/
|
|
void cap_rcv_window(size_t cnt) { _rcv_cap_cnt = cnt; }
|
|
|
|
/**
|
|
* Add capability to buffer
|
|
*/
|
|
void cap_add(Native_capability const &cap)
|
|
{
|
|
if (_snd_cap_cnt < MAX_CAP_ARGS)
|
|
_caps[_snd_cap_cnt++] = cap;
|
|
}
|
|
|
|
/**
|
|
* Return last capability from buffer.
|
|
*/
|
|
Native_capability cap_get()
|
|
{
|
|
return (_rcv_cap_cnt < _snd_cap_cnt)
|
|
? _caps[_rcv_cap_cnt++] : Native_capability();
|
|
}
|
|
};
|
|
|
|
|
|
template <unsigned BUF_SIZE>
|
|
class Genode::Msgbuf : public Genode::Msgbuf_base
|
|
{
|
|
public:
|
|
|
|
/**************************************************
|
|
** 'buf' must be the first member of this class **
|
|
**************************************************/
|
|
|
|
char buf[BUF_SIZE];
|
|
|
|
/**
|
|
* Constructor
|
|
*/
|
|
Msgbuf() : Msgbuf_base(BUF_SIZE) { }
|
|
};
|
|
|
|
#endif /* _INCLUDE__BASE__IPC_MSGBUF_H_ */
|