From 35384faa7a7989d82e2c8f1704b4ef0ca6d0be13 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Thu, 8 Mar 2012 19:28:32 +0100 Subject: [PATCH] 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'. --- base-codezero/include/base/native_types.h | 14 ++--- base-fiasco/include/base/native_types.h | 7 +-- base-foc/include/base/native_types.h | 10 ++-- base-host/include/base/native_types.h | 5 +- base-linux/include/base/native_types.h | 7 +-- base-mb/include/base/native_types.h | 9 ++-- base-nova/include/base/native_types.h | 7 +-- base-okl4/include/base/native_types.h | 9 ++-- base-pistachio/include/base/native_types.h | 11 ++-- base/include/base/native_capability.h | 61 +++++++++++++++------- 10 files changed, 85 insertions(+), 55 deletions(-) diff --git a/base-codezero/include/base/native_types.h b/base-codezero/include/base/native_types.h index 77fa1e5a90..9c78253093 100644 --- a/base-codezero/include/base/native_types.h +++ b/base-codezero/include/base/native_types.h @@ -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 Native_capability; + typedef Native_capability_tpl Native_capability; typedef int Native_connection_state; } diff --git a/base-fiasco/include/base/native_types.h b/base-fiasco/include/base/native_types.h index af18d17d2c..48e1e70e23 100644 --- a/base-fiasco/include/base/native_types.h +++ b/base-fiasco/include/base/native_types.h @@ -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_capability; + typedef Native_capability_tpl Native_capability; typedef Fiasco::l4_threadid_t Native_connection_state; } diff --git a/base-foc/include/base/native_types.h b/base-foc/include/base/native_types.h index 71a38432a9..ca63588232 100644 --- a/base-foc/include/base/native_types.h +++ b/base-foc/include/base/native_types.h @@ -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 Native_capability; + + typedef Native_capability_tpl Native_capability; } #endif /* _INCLUDE__BASE__NATIVE_TYPES_H_ */ diff --git a/base-host/include/base/native_types.h b/base-host/include/base/native_types.h index ca0fb16975..3e52b2d590 100644 --- a/base-host/include/base/native_types.h +++ b/base-host/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; diff --git a/base-linux/include/base/native_types.h b/base-linux/include/base/native_types.h index 83d574b104..ee5e35364f 100644 --- a/base-linux/include/base/native_types.h +++ b/base-linux/include/base/native_types.h @@ -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 Native_capability; + typedef Native_capability_tpl Native_capability; typedef int Native_connection_state; /* socket descriptor */ } diff --git a/base-mb/include/base/native_types.h b/base-mb/include/base/native_types.h index 5c08fb0bce..b818e690f0 100755 --- a/base-mb/include/base/native_types.h +++ b/base-mb/include/base/native_types.h @@ -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 Native_capability; + typedef Native_capability_tpl Native_capability; typedef int Native_connection_state; } diff --git a/base-nova/include/base/native_types.h b/base-nova/include/base/native_types.h index 7a675f8c9a..fe5ec00727 100644 --- a/base-nova/include/base/native_types.h +++ b/base-nova/include/base/native_types.h @@ -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 Native_capability; + typedef Native_capability_tpl Native_capability; typedef int Native_connection_state; } diff --git a/base-okl4/include/base/native_types.h b/base-okl4/include/base/native_types.h index 91f349251f..b183f58cce 100644 --- a/base-okl4/include/base/native_types.h +++ b/base-okl4/include/base/native_types.h @@ -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 Native_capability; + typedef Native_capability_tpl Native_capability; typedef Okl4::L4_ThreadId_t Native_connection_state; } diff --git a/base-pistachio/include/base/native_types.h b/base-pistachio/include/base/native_types.h index abfdad757f..d20e89c4c7 100644 --- a/base-pistachio/include/base/native_types.h +++ b/base-pistachio/include/base/native_types.h @@ -19,10 +19,11 @@ namespace Pistachio { #include - 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 Native_capability; + typedef Native_capability_tpl Native_capability; + typedef Pistachio::L4_ThreadId_t Native_connection_state; } diff --git a/base/include/base/native_capability.h b/base/include/base/native_capability.h index a9d3be9510..3a4c4cf1c5 100644 --- a/base/include/base/native_capability.h +++ b/base/include/base/native_capability.h @@ -22,62 +22,85 @@ namespace Genode { - template + /** + * 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 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; } }; }