mirror of
https://github.com/genodelabs/genode.git
synced 2025-04-07 19:34:56 +00:00
Follow-up tweaks for issue #145
Because we use to pass a policy class to 'Native_capability_tpl' we can pass the dst type as part of the policy instead of as a separate template argument. This patch also adds documentation of the POLICY interface as expected by 'Native_capability_tpl'.
This commit is contained in:
parent
c9c21ad39c
commit
35384faa7a
@ -29,7 +29,9 @@ namespace Genode {
|
||||
|
||||
struct Native_thread_id
|
||||
{
|
||||
int tid;
|
||||
typedef int Dst;
|
||||
|
||||
Dst tid;
|
||||
|
||||
/**
|
||||
* Pointer to thread's running lock
|
||||
@ -46,12 +48,12 @@ namespace Genode {
|
||||
/**
|
||||
* Constructor (used as implicit constructor)
|
||||
*/
|
||||
Native_thread_id(int l4id) : tid(l4id), running_lock(0) { }
|
||||
Native_thread_id(Dst l4id) : tid(l4id), running_lock(0) { }
|
||||
|
||||
Native_thread_id(int l4id, Codezero::l4_mutex *rl) : tid(l4id), running_lock(rl) { }
|
||||
Native_thread_id(Dst 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; }
|
||||
static bool valid(Dst tid) { return tid != Codezero::NILTHREAD; }
|
||||
static Dst invalid() { return Codezero::NILTHREAD; }
|
||||
};
|
||||
|
||||
struct Native_thread
|
||||
@ -105,7 +107,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; }
|
||||
|
||||
typedef Native_capability_tpl<int,Native_thread_id> Native_capability;
|
||||
typedef Native_capability_tpl<Native_thread_id> Native_capability;
|
||||
typedef int Native_connection_state;
|
||||
}
|
||||
|
||||
|
@ -21,8 +21,9 @@ namespace Fiasco {
|
||||
|
||||
struct Thread_id_check
|
||||
{
|
||||
static bool valid(l4_threadid_t id) { return !l4_is_invalid_id(id); }
|
||||
static l4_threadid_t invalid() { return L4_INVALID_ID;}
|
||||
typedef l4_threadid_t Dst;
|
||||
static bool valid(Dst id) { return !l4_is_invalid_id(id); }
|
||||
static Dst invalid() { return L4_INVALID_ID;}
|
||||
};
|
||||
}
|
||||
|
||||
@ -65,7 +66,7 @@ namespace Genode {
|
||||
*/
|
||||
typedef struct { } Native_utcb;
|
||||
|
||||
typedef Native_capability_tpl<Native_thread_id,Fiasco::Thread_id_check> Native_capability;
|
||||
typedef Native_capability_tpl<Fiasco::Thread_id_check> Native_capability;
|
||||
typedef Fiasco::l4_threadid_t Native_connection_state;
|
||||
}
|
||||
|
||||
|
@ -10,10 +10,12 @@ namespace Fiasco {
|
||||
|
||||
struct Thread_id_check
|
||||
{
|
||||
static bool valid(l4_cap_idx_t idx) {
|
||||
typedef l4_cap_idx_t Dst;
|
||||
|
||||
static bool valid(Dst idx) {
|
||||
return !(idx & Fiasco::L4_INVALID_CAP_BIT) && idx != 0; }
|
||||
|
||||
static l4_cap_idx_t invalid() { return L4_INVALID_CAP;}
|
||||
static Dst invalid() { return L4_INVALID_CAP;}
|
||||
};
|
||||
|
||||
enum Cap_selectors {
|
||||
@ -42,8 +44,8 @@ namespace Genode {
|
||||
typedef Fiasco::l4_cap_idx_t Native_task;
|
||||
typedef Fiasco::l4_utcb_t* Native_utcb;
|
||||
typedef int Native_connection_state;
|
||||
typedef Native_capability_tpl<Fiasco::l4_cap_idx_t,
|
||||
Fiasco::Thread_id_check> Native_capability;
|
||||
|
||||
typedef Native_capability_tpl<Fiasco::Thread_id_check> Native_capability;
|
||||
}
|
||||
|
||||
#endif /* _INCLUDE__BASE__NATIVE_TYPES_H_ */
|
||||
|
@ -19,8 +19,9 @@
|
||||
namespace Genode {
|
||||
|
||||
struct Empty_thread_id {
|
||||
static bool valid(Empty_thread_id id) { return true; }
|
||||
static Empty_thread_id invalid() { return Empty_thread_id();}
|
||||
typedef int Dst;
|
||||
static bool valid(Dst) { return false; }
|
||||
static Dst invalid() { return false; }
|
||||
};
|
||||
|
||||
typedef volatile int Native_lock;
|
||||
|
@ -94,8 +94,9 @@ namespace Genode {
|
||||
return (t1.tid != t2.tid) || (t1.pid != t2.pid); }
|
||||
|
||||
struct Thread_id_check {
|
||||
static bool valid(long id) { return id != 0; }
|
||||
static long invalid() { return 0; }
|
||||
typedef long Dst;
|
||||
static bool valid(Dst id) { return id != 0; }
|
||||
static Dst invalid() { return 0; }
|
||||
};
|
||||
|
||||
/**
|
||||
@ -103,7 +104,7 @@ namespace Genode {
|
||||
*/
|
||||
typedef struct { } Native_utcb;
|
||||
|
||||
typedef Native_capability_tpl<long, Thread_id_check> Native_capability;
|
||||
typedef Native_capability_tpl<Thread_id_check> Native_capability;
|
||||
typedef int Native_connection_state; /* socket descriptor */
|
||||
}
|
||||
|
||||
|
@ -30,17 +30,16 @@ namespace Genode {
|
||||
|
||||
Native_thread_id my_thread_id();
|
||||
|
||||
|
||||
struct Thread_id_check
|
||||
{
|
||||
static bool valid(Kernel::Thread_id tid) {
|
||||
typedef Kernel::Thread_id Dst;
|
||||
static bool valid(Dst tid) {
|
||||
return tid != Kernel::INVALID_THREAD_ID; }
|
||||
static Kernel::Thread_id invalid()
|
||||
static Dst invalid()
|
||||
{ return Kernel::INVALID_THREAD_ID; }
|
||||
};
|
||||
|
||||
|
||||
typedef Native_capability_tpl<Kernel::Thread_id,Thread_id_check> Native_capability;
|
||||
typedef Native_capability_tpl<Thread_id_check> Native_capability;
|
||||
typedef int Native_connection_state;
|
||||
}
|
||||
|
||||
|
@ -55,11 +55,12 @@ namespace Genode {
|
||||
|
||||
struct Portal_checker
|
||||
{
|
||||
static bool valid(int pt) { return pt != 0; }
|
||||
static int invalid() { return 0; }
|
||||
typedef int Dst;
|
||||
static bool valid(Dst pt) { return pt != 0; }
|
||||
static Dst invalid() { return 0; }
|
||||
};
|
||||
|
||||
typedef Native_capability_tpl<int, Portal_checker> Native_capability;
|
||||
typedef Native_capability_tpl<Portal_checker> Native_capability;
|
||||
typedef int Native_connection_state;
|
||||
}
|
||||
|
||||
|
@ -80,13 +80,12 @@ namespace Genode {
|
||||
|
||||
struct Thread_id_checker
|
||||
{
|
||||
static bool valid(Okl4::L4_ThreadId_t tid) {
|
||||
return !Okl4::L4_IsNilThread(tid); }
|
||||
static Okl4::L4_ThreadId_t invalid() { return Okl4::L4_nilthread; }
|
||||
typedef Okl4::L4_ThreadId_t Dst;
|
||||
static bool valid(Dst tid) { return !Okl4::L4_IsNilThread(tid); }
|
||||
static Dst invalid() { return Okl4::L4_nilthread; }
|
||||
};
|
||||
|
||||
typedef Native_capability_tpl<Okl4::L4_ThreadId_t,
|
||||
Thread_id_checker> Native_capability;
|
||||
typedef Native_capability_tpl<Thread_id_checker> Native_capability;
|
||||
typedef Okl4::L4_ThreadId_t Native_connection_state;
|
||||
}
|
||||
|
||||
|
@ -19,10 +19,11 @@
|
||||
namespace Pistachio {
|
||||
#include <l4/types.h>
|
||||
|
||||
struct Thread_id_checker
|
||||
struct Cap_dst_policy
|
||||
{
|
||||
static bool valid(L4_ThreadId_t tid) { return !L4_IsNilThread(tid); }
|
||||
static L4_ThreadId_t invalid() { return L4_nilthread; }
|
||||
typedef L4_ThreadId_t Dst;
|
||||
static bool valid(Dst tid) { return !L4_IsNilThread(tid); }
|
||||
static Dst invalid() { return L4_nilthread; }
|
||||
};
|
||||
}
|
||||
|
||||
@ -65,8 +66,8 @@ namespace Genode {
|
||||
*/
|
||||
typedef struct { } Native_utcb;
|
||||
|
||||
typedef Native_capability_tpl<Pistachio::L4_ThreadId_t,
|
||||
Pistachio::Thread_id_checker> Native_capability;
|
||||
typedef Native_capability_tpl<Pistachio::Cap_dst_policy> Native_capability;
|
||||
|
||||
typedef Pistachio::L4_ThreadId_t Native_connection_state;
|
||||
}
|
||||
|
||||
|
@ -22,62 +22,85 @@
|
||||
|
||||
namespace Genode {
|
||||
|
||||
template <typename ID, typename T>
|
||||
/**
|
||||
* Generic parts of the platform-specific 'Native_capability'
|
||||
*
|
||||
* \param POLICY policy class that provides the type used as capability
|
||||
* destination and functions for checking the validity of
|
||||
* the platform-specific destination type and for
|
||||
* invalid destinations.
|
||||
*
|
||||
* The struct passed as 'POLICY' argument must have the following
|
||||
* interface:
|
||||
*
|
||||
* ! typedef Dst;
|
||||
* ! static bool valid(Dst dst);
|
||||
* ! static Dst invalid();
|
||||
*
|
||||
* The 'Dst' type is the platform-specific destination type (e.g., the ID
|
||||
* of the destination thread targeted by the capability). The 'valid'
|
||||
* function returns true if the specified destination is valid. The
|
||||
* 'invalid' function produces an invalid destination.
|
||||
*/
|
||||
template <typename POLICY>
|
||||
class Native_capability_tpl
|
||||
{
|
||||
private:
|
||||
|
||||
ID _tid;
|
||||
typedef typename POLICY::Dst Dst;
|
||||
|
||||
Dst _tid;
|
||||
long _local_name;
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Constructor for a local capability.
|
||||
* Constructor for a local capability
|
||||
*
|
||||
* A local capability just encapsulates a pointer to some
|
||||
* local object. This constructor is only used by a factory
|
||||
* method for local-capabilities in the generic Capability
|
||||
* class.
|
||||
*
|
||||
* \param ptr address of the local object.
|
||||
* \param ptr address of the local object
|
||||
*/
|
||||
Native_capability_tpl(void* ptr)
|
||||
: _tid(T::invalid()), _local_name((long)ptr) { }
|
||||
: _tid(POLICY::invalid()), _local_name((long)ptr) { }
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor for an invalid capability.
|
||||
* Constructor for an invalid capability
|
||||
*/
|
||||
Native_capability_tpl() : _tid(T::invalid()), _local_name(0) { }
|
||||
Native_capability_tpl() : _tid(POLICY::invalid()), _local_name(0) { }
|
||||
|
||||
/**
|
||||
* Publicly available constructor.
|
||||
* Publicly available constructor
|
||||
*
|
||||
* \param tid kernel-specific thread id
|
||||
* \param local_name global, unique id of the cap.
|
||||
* \param tid kernel-specific thread id
|
||||
* \param local_name ID used as key to lookup the 'Rpc_object'
|
||||
* that corresponds to the capability.
|
||||
*/
|
||||
Native_capability_tpl(ID tid, long local_name)
|
||||
: _tid(tid), _local_name(local_name) {}
|
||||
Native_capability_tpl(Dst tid, long local_name)
|
||||
: _tid(tid), _local_name(local_name) { }
|
||||
|
||||
/**
|
||||
* \return true when the capability is a valid one, otherwise false.
|
||||
* Return true when the capability is valid
|
||||
*/
|
||||
bool valid() const { return T::valid(_tid); }
|
||||
bool valid() const { return POLICY::valid(_tid); }
|
||||
|
||||
/**
|
||||
* \return the globally unique id.
|
||||
* Return ID used to lookup the 'Rpc_object' by its capability
|
||||
*/
|
||||
long local_name() const { return _local_name; }
|
||||
|
||||
/**
|
||||
* \return true if this is a local-capability, otherwise false.
|
||||
* Return pointer to object referenced by a local-capability
|
||||
*/
|
||||
void* local() const { return (void*)_local_name; }
|
||||
|
||||
/**
|
||||
* Copy this capability to another pd.
|
||||
* Copy this capability to another PD
|
||||
*/
|
||||
void copy_to(void* dst) {
|
||||
memcpy(dst, this, sizeof(Native_capability_tpl)); }
|
||||
@ -88,9 +111,9 @@ namespace Genode {
|
||||
*****************************************/
|
||||
|
||||
/**
|
||||
* \return the kernel-specific thread specifier.
|
||||
* Return the kernel-specific capability destination
|
||||
*/
|
||||
ID tid() const { return _tid; }
|
||||
Dst tid() const { return _tid; }
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user