mirror of
https://github.com/mmueller41/genode.git
synced 2026-01-21 12:32:56 +01:00
Merge Native_capability implementations (fix #145).
This patch unifies the Native_capability classes for the different kernel platforms by introducing an appropriate template, and eliminating naming differences. Please refer issue #145.
This commit is contained in:
committed by
Norman Feske
parent
9992efed03
commit
c9c21ad39c
@@ -14,7 +14,7 @@
|
||||
#ifndef _INCLUDE__BASE__NATIVE_TYPES_H_
|
||||
#define _INCLUDE__BASE__NATIVE_TYPES_H_
|
||||
|
||||
#include <util/string.h>
|
||||
#include <base/native_capability.h>
|
||||
|
||||
namespace Codezero {
|
||||
|
||||
@@ -49,6 +49,9 @@ namespace Genode {
|
||||
Native_thread_id(int l4id) : tid(l4id), running_lock(0) { }
|
||||
|
||||
Native_thread_id(int l4id, Codezero::l4_mutex *rl) : tid(l4id), running_lock(rl) { }
|
||||
|
||||
static bool valid(int tid) { return tid != Codezero::NILTHREAD; }
|
||||
static int invalid() { return Codezero::NILTHREAD; }
|
||||
};
|
||||
|
||||
struct Native_thread
|
||||
@@ -102,54 +105,7 @@ namespace Genode {
|
||||
inline bool operator == (Native_thread_id t1, Native_thread_id t2) { return t1.tid == t2.tid; }
|
||||
inline bool operator != (Native_thread_id t1, Native_thread_id t2) { return t1.tid != t2.tid; }
|
||||
|
||||
/*
|
||||
* Because Codezero does not support local names for capabilities, a Genode
|
||||
* capability consists of the global thread ID and a global object ID, not
|
||||
* protected by the kernel when transmitted as IPC payloads.
|
||||
*/
|
||||
class Native_capability
|
||||
{
|
||||
private:
|
||||
|
||||
Native_thread_id _tid; /* global thread ID */
|
||||
int _local_name; /* global unique object ID */
|
||||
|
||||
protected:
|
||||
|
||||
Native_capability(void* ptr) : _local_name((int)ptr) {
|
||||
_tid.tid = Codezero::NILTHREAD; }
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Default constructor creates invalid capability
|
||||
*/
|
||||
Native_capability()
|
||||
: _local_name(0) { _tid.tid = Codezero::NILTHREAD; }
|
||||
|
||||
/**
|
||||
* Constructor for hand-crafting capabilities
|
||||
*
|
||||
* This constructor is only used internally be the framework.
|
||||
*/
|
||||
Native_capability(Native_thread_id tid, int local_name)
|
||||
: _tid(tid), _local_name(local_name) { }
|
||||
|
||||
bool valid() const { return _tid.tid != Codezero::NILTHREAD; }
|
||||
|
||||
int local_name() const { return _local_name; }
|
||||
void* local() const { return (void*)_local_name; }
|
||||
int dst() const { return _tid.tid; }
|
||||
|
||||
Native_thread_id tid() const { return _tid; }
|
||||
|
||||
/**
|
||||
* Copy this capability to another pd.
|
||||
*/
|
||||
void copy_to(void* dst) {
|
||||
memcpy(dst, this, sizeof(Native_capability)); }
|
||||
};
|
||||
|
||||
typedef Native_capability_tpl<int,Native_thread_id> Native_capability;
|
||||
typedef int Native_connection_state;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,17 +34,17 @@ void Ipc_ostream::_send()
|
||||
{
|
||||
if (verbose_ipc)
|
||||
PDBG("thread %d sends IPC to %d, write_offset=%d",
|
||||
thread_myself(), _dst.tid().tid, _write_offset);
|
||||
thread_myself(), _dst.tid(), _write_offset);
|
||||
|
||||
umword_t snd_size = min(_write_offset, (unsigned)L4_IPC_EXTENDED_MAX_SIZE);
|
||||
|
||||
*(umword_t *)_snd_msg->addr() = _dst.local_name();
|
||||
|
||||
int ret = l4_send_extended(_dst.tid().tid, L4_IPC_TAG_SYNC_EXTENDED,
|
||||
int ret = l4_send_extended(_dst.tid(), L4_IPC_TAG_SYNC_EXTENDED,
|
||||
snd_size, _snd_msg->addr());
|
||||
if (ret < 0)
|
||||
PERR("l4_send_extended (to thread %d) returned ret=%d",
|
||||
_dst.tid().tid, ret);
|
||||
_dst.tid(), ret);
|
||||
|
||||
_write_offset = sizeof(umword_t);
|
||||
}
|
||||
@@ -71,7 +71,7 @@ void Ipc_istream::_wait()
|
||||
|
||||
if (verbose_ipc)
|
||||
PDBG("thread %d waits for IPC from %d, rcv_buf at %p, rcv_size=%d",
|
||||
tid().tid, _rcv_cs, rcv_buf, (int)rcv_size);
|
||||
tid(), _rcv_cs, rcv_buf, (int)rcv_size);
|
||||
|
||||
int ret = l4_receive_extended(_rcv_cs, rcv_size, rcv_buf);
|
||||
if (ret < 0)
|
||||
@@ -79,7 +79,7 @@ void Ipc_istream::_wait()
|
||||
|
||||
if (verbose_ipc)
|
||||
PDBG("thread %d received IPC from %d",
|
||||
tid().tid, l4_get_sender());
|
||||
tid(), l4_get_sender());
|
||||
|
||||
_read_offset = sizeof(umword_t);
|
||||
}
|
||||
@@ -107,7 +107,7 @@ void Ipc_client::_call()
|
||||
{
|
||||
#warning l4_sendrecv_extended is not yet implemented in l4lib/arch/syslib.h
|
||||
_send();
|
||||
_rcv_cs = _dst.tid().tid;
|
||||
_rcv_cs = _dst.tid();
|
||||
_wait();
|
||||
_rcv_cs = L4_ANYTHREAD;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user