diff --git a/base-codezero/include/base/native_types.h b/base-codezero/include/base/native_types.h index bb43b6c6ce..77fa1e5a90 100644 --- a/base-codezero/include/base/native_types.h +++ b/base-codezero/include/base/native_types.h @@ -14,7 +14,7 @@ #ifndef _INCLUDE__BASE__NATIVE_TYPES_H_ #define _INCLUDE__BASE__NATIVE_TYPES_H_ -#include +#include 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 Native_capability; typedef int Native_connection_state; } diff --git a/base-codezero/src/base/ipc/ipc.cc b/base-codezero/src/base/ipc/ipc.cc index 266dacf389..7a7e43c080 100644 --- a/base-codezero/src/base/ipc/ipc.cc +++ b/base-codezero/src/base/ipc/ipc.cc @@ -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; diff --git a/base-fiasco/include/base/native_types.h b/base-fiasco/include/base/native_types.h index 719d585374..af18d17d2c 100644 --- a/base-fiasco/include/base/native_types.h +++ b/base-fiasco/include/base/native_types.h @@ -14,15 +14,16 @@ #ifndef _INCLUDE__BASE__NATIVE_TYPES_H_ #define _INCLUDE__BASE__NATIVE_TYPES_H_ -#include +#include namespace Fiasco { #include - /** - * Return invalid L4 thread ID - */ - inline l4_threadid_t invalid_l4_threadid_t() { return L4_INVALID_ID; } + 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;} + }; } namespace Genode { @@ -64,66 +65,7 @@ namespace Genode { */ typedef struct { } Native_utcb; - /* - * On Fiasco, the local_name member of a capability is global - * to the whole system. Therefore, capabilities are to be - * created at a central place that prevents id clashes. - */ - class Native_capability - { - protected: - - Fiasco::l4_threadid_t _tid; - long _local_name; - - protected: - - Native_capability(void *ptr) - : _tid(Fiasco::invalid_l4_threadid_t()), _local_name((long)ptr) { } - - public: - - /** - * Default constructor - */ - Native_capability() - : _tid(Fiasco::invalid_l4_threadid_t()), _local_name(0) { } - - long local_name() const { return _local_name; } - Fiasco::l4_threadid_t dst() const { return _tid; } - - void* local() const { return (void*)_local_name; } - - bool valid() const { return l4_is_invalid_id(_tid) == 0; } - - - /***************************************************** - ** Functions to be used by the Fiasco backend only ** - *****************************************************/ - - /** - * Constructor - * - * This constructor can be called to create a Fiasco - * capability by hand. It must never be used from - * generic code! - */ - Native_capability(Fiasco::l4_threadid_t tid, - Fiasco::l4_umword_t local_name) - : _tid(tid), _local_name(local_name) { } - - /** - * Access raw capability data - */ - Fiasco::l4_threadid_t 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 Native_capability; typedef Fiasco::l4_threadid_t Native_connection_state; } diff --git a/base-foc/include/base/cap_sel_alloc.h b/base-foc/include/base/cap_sel_alloc.h index 12a9b6b4e2..9d0b1adb16 100644 --- a/base-foc/include/base/cap_sel_alloc.h +++ b/base-foc/include/base/cap_sel_alloc.h @@ -163,8 +163,7 @@ namespace Genode /** * Constructor */ - Capability_allocator_tpl() - : _cap_idx(Fiasco::Fiasco_capability::USER_BASE_CAP) { } + Capability_allocator_tpl() : _cap_idx(Fiasco::USER_BASE_CAP) { } /************************************ diff --git a/base-foc/include/base/ipc.h b/base-foc/include/base/ipc.h index 414872fe94..b117441234 100644 --- a/base-foc/include/base/ipc.h +++ b/base-foc/include/base/ipc.h @@ -27,7 +27,7 @@ inline void Genode::Ipc_ostream::_marshal_capability(Genode::Native_capability c long unique_id = cap.local_name(); _write_to_buf(unique_id); if (unique_id) - _snd_msg->snd_append_cap_sel(cap.dst()); + _snd_msg->snd_append_cap_sel(cap.tid()); } diff --git a/base-foc/include/base/ipc_pager.h b/base-foc/include/base/ipc_pager.h index 75917cdf1b..f3591249c8 100644 --- a/base-foc/include/base/ipc_pager.h +++ b/base-foc/include/base/ipc_pager.h @@ -154,7 +154,7 @@ namespace Genode { * Set destination for next reply */ void set_reply_dst(Native_capability pager_object) { - _last = pager_object.dst(); } + _last = pager_object.tid(); } /** * Answer call without sending a flex-page mapping diff --git a/base-foc/include/base/native_types.h b/base-foc/include/base/native_types.h index 62cf03d504..71a38432a9 100644 --- a/base-foc/include/base/native_types.h +++ b/base-foc/include/base/native_types.h @@ -1,44 +1,31 @@ #ifndef _INCLUDE__BASE__NATIVE_TYPES_H_ #define _INCLUDE__BASE__NATIVE_TYPES_H_ -#include +#include namespace Fiasco { #include #include #include - class Fiasco_capability + struct Thread_id_check { - private: + static bool valid(l4_cap_idx_t idx) { + return !(idx & Fiasco::L4_INVALID_CAP_BIT) && idx != 0; } - l4_cap_idx_t _cap_idx; + static l4_cap_idx_t invalid() { return L4_INVALID_CAP;} + }; - public: - - enum Cap_selectors { - INVALID_CAP = L4_INVALID_CAP, - TASK_CAP = L4_BASE_TASK_CAP, - PARENT_CAP = 0x8UL << L4_CAP_SHIFT, - THREADS_BASE_CAP = 0x9UL << L4_CAP_SHIFT, - USER_BASE_CAP = 0x200UL << L4_CAP_SHIFT, - THREAD_GATE_CAP = 0, - THREAD_PAGER_CAP = 0x1UL << L4_CAP_SHIFT, - THREAD_IRQ_CAP = 0x2UL << L4_CAP_SHIFT, - THREAD_CAP_SLOT = THREAD_IRQ_CAP + L4_CAP_SIZE, - MAIN_THREAD_CAP = THREADS_BASE_CAP + THREAD_GATE_CAP - }; - - Fiasco_capability(l4_cap_idx_t cap = L4_INVALID_CAP) - : _cap_idx(cap) { } - - Fiasco_capability(void* cap) - : _cap_idx((l4_cap_idx_t)cap) { } - - bool valid() const { return !(_cap_idx & Fiasco::L4_INVALID_CAP_BIT) - && _cap_idx != 0; } - - operator l4_cap_idx_t () { return _cap_idx; } + enum Cap_selectors { + TASK_CAP = L4_BASE_TASK_CAP, + PARENT_CAP = 0x8UL << L4_CAP_SHIFT, + THREADS_BASE_CAP = 0x9UL << L4_CAP_SHIFT, + USER_BASE_CAP = 0x200UL << L4_CAP_SHIFT, + THREAD_GATE_CAP = 0, + THREAD_PAGER_CAP = 0x1UL << L4_CAP_SHIFT, + THREAD_IRQ_CAP = 0x2UL << L4_CAP_SHIFT, + THREAD_CAP_SLOT = THREAD_IRQ_CAP + L4_CAP_SIZE, + MAIN_THREAD_CAP = THREADS_BASE_CAP + THREAD_GATE_CAP }; enum Utcb_regs { @@ -49,51 +36,14 @@ namespace Fiasco { namespace Genode { - typedef volatile int Native_lock; - typedef Fiasco::Fiasco_capability Native_thread_id; - typedef Fiasco::Fiasco_capability Native_thread; - typedef Fiasco::Fiasco_capability Native_task; - typedef Fiasco::l4_utcb_t* Native_utcb; - - class Native_capability - { - private: - - Native_thread _cap_sel; - int _unique_id; - - protected: - - Native_capability(void* ptr) : _unique_id((int)ptr) { } - - public: - - /** - * Default constructor creates an invalid capability - */ - Native_capability() : _unique_id(0) { } - - /** - * Construct capability manually - */ - Native_capability(Native_thread cap_sel, int unique_id) - : _cap_sel(cap_sel), _unique_id(unique_id) { } - - int local_name() const { return _unique_id; } - void* local() const { return (void*)_unique_id; } - Native_thread dst() const { return _cap_sel; } - Native_thread_id tid() const { return _cap_sel; } - - bool valid() const { return _cap_sel.valid() && _unique_id != 0; } - - /** - * Copy this capability to another pd. - */ - void copy_to(void* dst) { - memcpy(dst, this, sizeof(Native_capability)); } - }; - - typedef int Native_connection_state; + typedef volatile int Native_lock; + typedef Fiasco::l4_cap_idx_t Native_thread_id; + typedef Fiasco::l4_cap_idx_t Native_thread; + 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; } #endif /* _INCLUDE__BASE__NATIVE_TYPES_H_ */ diff --git a/base-foc/include/signal_session/source_client.h b/base-foc/include/signal_session/source_client.h index a3cce24264..39f1a0e1fa 100644 --- a/base-foc/include/signal_session/source_client.h +++ b/base-foc/include/signal_session/source_client.h @@ -51,7 +51,7 @@ namespace Genode { /* request mapping of semaphore capability selector */ _sem = call(); - l4_msgtag_t tag = l4_irq_attach(_sem.dst(), 0, + l4_msgtag_t tag = l4_irq_attach(_sem.tid(), 0, Thread_base::myself()->tid()); if (l4_error(tag)) PERR("l4_irq_attach failed with %ld!", l4_error(tag)); @@ -76,7 +76,7 @@ namespace Genode { using namespace Fiasco; /* block on semaphore, will be unblocked if signal is available */ - l4_irq_receive(_sem.dst(), L4_IPC_NEVER); + l4_irq_receive(_sem.tid(), L4_IPC_NEVER); /* * Now that the server has unblocked the semaphore, we are sure diff --git a/base-foc/src/base/ipc/ipc.cc b/base-foc/src/base/ipc/ipc.cc index 8f8a1454ba..8956ebd01e 100644 --- a/base-foc/src/base/ipc/ipc.cc +++ b/base-foc/src/base/ipc/ipc.cc @@ -142,7 +142,7 @@ static l4_msgtag_t copy_msgbuf_to_utcb(Msgbuf_base *snd_msg, unsigned offset, void Ipc_ostream::_send() { l4_msgtag_t tag = copy_msgbuf_to_utcb(_snd_msg, _write_offset, _dst); - tag = l4_ipc_send(_dst.dst(), l4_utcb(), tag, L4_IPC_NEVER); + tag = l4_ipc_send(_dst.tid(), l4_utcb(), tag, L4_IPC_NEVER); if (ipc_error(tag, DEBUG_MSG)) throw Ipc_error(); @@ -215,7 +215,7 @@ void Ipc_client::_call() rcv_cap_sel += L4_CAP_SIZE; } - tag = l4_ipc_call(_dst.dst(), l4_utcb(), tag, L4_IPC_NEVER); + tag = l4_ipc_call(_dst.tid(), l4_utcb(), tag, L4_IPC_NEVER); if (l4_ipc_error(tag, l4_utcb()) == L4_IPC_RECANCELED) throw Genode::Blocking_canceled(); if (ipc_error(tag, DEBUG_MSG)) diff --git a/base-foc/src/base/ipc/pager.cc b/base-foc/src/base/ipc/pager.cc index b23cca6360..d61905a7c4 100644 --- a/base-foc/src/base/ipc/pager.cc +++ b/base-foc/src/base/ipc/pager.cc @@ -98,7 +98,7 @@ void Ipc_pager::reply_and_wait_for_fault() void Ipc_pager::acknowledge_wakeup() { - l4_cap_idx_t dst = _last.valid() ? _last : L4_SYSF_REPLY; + l4_cap_idx_t dst = Thread_id_check::valid(_last) ? _last : L4_SYSF_REPLY; /* answer wakeup call from one of core's region-manager sessions */ l4_ipc_send(dst, l4_utcb(), l4_msgtag(0, 0, 0, 0), L4_IPC_SEND_TIMEOUT_0); diff --git a/base-foc/src/base/lock/lock_helper.h b/base-foc/src/base/lock/lock_helper.h index a293315a46..906f0dd0a8 100644 --- a/base-foc/src/base/lock/lock_helper.h +++ b/base-foc/src/base/lock/lock_helper.h @@ -55,20 +55,16 @@ static inline void thread_yield() { Fiasco::l4_thread_yield(); } */ static inline bool thread_check_stopped_and_restart(Genode::Native_thread_id tid) { - using namespace Fiasco; - - Genode::Native_thread_id irq = tid + Fiasco_capability::THREAD_IRQ_CAP; - l4_irq_trigger(irq); + Genode::Native_thread_id irq = tid + Fiasco::THREAD_IRQ_CAP; + Fiasco::l4_irq_trigger(irq); return true; } static inline Genode::Native_thread_id thread_get_my_native_id() { - using namespace Fiasco; - Genode::Thread_base *myself = Genode::Thread_base::myself(); - return myself ? myself->tid() : Fiasco_capability::MAIN_THREAD_CAP; + return myself ? myself->tid() : Fiasco::MAIN_THREAD_CAP; } @@ -85,7 +81,7 @@ static inline Genode::Native_thread_id thread_invalid_id() */ static inline bool thread_id_valid(Genode::Native_thread_id tid) { - return tid.valid(); + return Fiasco::Thread_id_check::valid(tid); } @@ -105,8 +101,7 @@ static inline void thread_stop_myself() { using namespace Fiasco; - Genode::Native_thread_id irq = thread_get_my_native_id() - + Fiasco_capability::THREAD_IRQ_CAP; + Genode::Native_thread_id irq = thread_get_my_native_id() + THREAD_IRQ_CAP; l4_irq_receive(irq, L4_IPC_NEVER); } diff --git a/base-foc/src/base/thread/thread_start.cc b/base-foc/src/base/thread/thread_start.cc index ea4f19ca6c..9f486c1f75 100644 --- a/base-foc/src/base/thread/thread_start.cc +++ b/base-foc/src/base/thread/thread_start.cc @@ -49,7 +49,7 @@ void Thread_base::start() /* get gate-capability and badge of new thread */ Thread_state state; env()->cpu_session()->state(_thread_cap, &state); - _tid = state.cap.dst(); + _tid = state.cap.tid(); /* * send newly constructed thread, pointer to its Thread_base object, diff --git a/base-foc/src/core/cap_session_component.cc b/base-foc/src/core/cap_session_component.cc index b86ba2750a..ab5f122918 100644 --- a/base-foc/src/core/cap_session_component.cc +++ b/base-foc/src/core/cap_session_component.cc @@ -118,10 +118,10 @@ void Cap_session_component::free(Native_capability cap) Capability_tree::tree()->remove(n); l4_msgtag_t tag = l4_task_unmap(L4_BASE_TASK_CAP, - l4_obj_fpage(cap.dst(), 0, L4_FPAGE_RWX), + l4_obj_fpage(cap.tid(), 0, L4_FPAGE_RWX), L4_FP_ALL_SPACES | L4_FP_DELETE_OBJ); if (l4_msgtag_has_error(tag)) - PERR("destruction of ipc-gate %lx failed!", (unsigned long) cap.dst()); + PERR("destruction of ipc-gate %lx failed!", (unsigned long) cap.tid()); /* free badge _after_ invalidating all caps */ Badge_allocator::allocator()->free(n->badge()); diff --git a/base-foc/src/core/cpu_session_extension.cc b/base-foc/src/core/cpu_session_extension.cc index 5b7001f8b9..76053fbebb 100644 --- a/base-foc/src/core/cpu_session_extension.cc +++ b/base-foc/src/core/cpu_session_extension.cc @@ -61,7 +61,7 @@ Genode::Native_capability Genode::Cpu_session_component::alloc_irq() { using namespace Fiasco; - Fiasco_capability irq_cap(Genode::cap_alloc()->alloc()); + Native_thread_id irq_cap(Genode::cap_alloc()->alloc()); l4_msgtag_t res = l4_factory_create_irq(L4_BASE_FACTORY_CAP, irq_cap); if (l4_error(res)) PWRN("Allocation of irq object failed!"); diff --git a/base-foc/src/core/include/platform_pd.h b/base-foc/src/core/include/platform_pd.h index 590c65ca0b..f3c775d0b2 100644 --- a/base-foc/src/core/include/platform_pd.h +++ b/base-foc/src/core/include/platform_pd.h @@ -111,7 +111,7 @@ namespace Genode { Native_task native_task() { return _l4_task_cap; } unsigned badge() { return _badge; } - Native_thread parent_cap() { return _parent.dst(); } + Native_thread parent_cap() { return _parent.tid(); } }; } diff --git a/base-foc/src/core/include/platform_thread.h b/base-foc/src/core/include/platform_thread.h index bfe47fe106..a9c590c411 100644 --- a/base-foc/src/core/include/platform_thread.h +++ b/base-foc/src/core/include/platform_thread.h @@ -147,14 +147,14 @@ namespace Genode { * Return identification of thread when faulting */ unsigned long pager_object_badge() { - return (unsigned long) _thread_cap.dst(); } + return (unsigned long) _thread_cap.tid(); } /******************************* ** Fiasco-specific Accessors ** *******************************/ - Native_thread native_thread() const { return _thread_cap.dst(); } + Native_thread native_thread() const { return _thread_cap.tid(); } Native_capability thread_cap() const { return _thread_cap; } Native_capability gate() const { return _remote_gate_cap; } const char *name() const { return _name; } diff --git a/base-foc/src/core/irq_session_component.cc b/base-foc/src/core/irq_session_component.cc index 54fe8226af..1ee70cc2e7 100644 --- a/base-foc/src/core/irq_session_component.cc +++ b/base-foc/src/core/irq_session_component.cc @@ -56,7 +56,7 @@ Irq_session_component::Interrupt::Interrupt() Native_thread Irq_session_component::Interrupt_handler::handler_cap() { static Interrupt_handler handler; - return handler._thread_cap.dst(); + return handler._thread_cap.tid(); } diff --git a/base-foc/src/core/platform_pd.cc b/base-foc/src/core/platform_pd.cc index a226c4cdb2..0041bb1be7 100644 --- a/base-foc/src/core/platform_pd.cc +++ b/base-foc/src/core/platform_pd.cc @@ -43,7 +43,7 @@ static addr_t core_utcb_base() { void Platform_pd::_create_pd(bool syscall) { - if (!_l4_task_cap.valid()) + if (!Thread_id_check::valid(_l4_task_cap)) _l4_task_cap = cap_alloc()->alloc(); if (syscall) { @@ -75,8 +75,6 @@ void Platform_pd::_destroy_pd() int Platform_pd::bind_thread(Platform_thread *thread) { - using namespace Fiasco; - for (unsigned i = 0; i < THREAD_MAX; i++) { if (_threads[i]) continue; @@ -87,12 +85,11 @@ int Platform_pd::bind_thread(Platform_thread *thread) else thread->_utcb = reinterpret_cast(UTCB_AREA_START + i * L4_UTCB_OFFSET); - Native_thread cap_offset = Fiasco_capability::THREADS_BASE_CAP + - i * Fiasco_capability::THREAD_CAP_SLOT; - thread->_remote_gate_cap = Native_capability(cap_offset + Fiasco_capability::THREAD_GATE_CAP, + Native_thread cap_offset = THREADS_BASE_CAP + i * THREAD_CAP_SLOT; + thread->_remote_gate_cap = Native_capability(cap_offset + THREAD_GATE_CAP, thread->_gate_cap.local_name()); - thread->_remote_pager_cap = cap_offset + Fiasco_capability::THREAD_PAGER_CAP; - thread->_remote_irq_cap = cap_offset + Fiasco_capability::THREAD_IRQ_CAP; + thread->_remote_pager_cap = cap_offset + THREAD_PAGER_CAP; + thread->_remote_irq_cap = cap_offset + THREAD_IRQ_CAP; /* inform thread about binding */ thread->bind(this); @@ -129,8 +126,8 @@ void Platform_pd::map_parent_cap() { if (!_parent_cap_mapped) { l4_msgtag_t tag = l4_task_map(_l4_task_cap, L4_BASE_TASK_CAP, - l4_obj_fpage(_parent.dst(), 0, L4_FPAGE_RWX), - Fiasco_capability::PARENT_CAP | L4_ITEM_MAP); + l4_obj_fpage(_parent.tid(), 0, L4_FPAGE_RWX), + PARENT_CAP | L4_ITEM_MAP); if (l4_msgtag_has_error(tag)) PWRN("mapping parent cap failed"); @@ -144,7 +141,7 @@ void Platform_pd::map_task_cap() if (!_task_cap_mapped) { l4_msgtag_t tag = l4_task_map(_l4_task_cap, L4_BASE_TASK_CAP, l4_obj_fpage(_l4_task_cap, 0, L4_FPAGE_RWX), - Fiasco_capability::TASK_CAP | L4_ITEM_MAP); + TASK_CAP | L4_ITEM_MAP); if (l4_msgtag_has_error(tag)) PWRN("mapping task cap failed"); _task_cap_mapped = true; diff --git a/base-foc/src/core/platform_thread.cc b/base-foc/src/core/platform_thread.cc index 1ab623c795..c9b1225958 100644 --- a/base-foc/src/core/platform_thread.cc +++ b/base-foc/src/core/platform_thread.cc @@ -41,7 +41,7 @@ int Platform_thread::start(void *ip, void *sp) if (_pager && _platform_pd) { /* map pager cap */ l4_msgtag_t tag = l4_task_map(_platform_pd->native_task(), L4_BASE_TASK_CAP, - l4_obj_fpage(_pager->cap().dst(), 0, L4_FPAGE_RWX), + l4_obj_fpage(_pager->cap().tid(), 0, L4_FPAGE_RWX), _remote_pager_cap | L4_ITEM_MAP); if (l4_msgtag_has_error(tag)) PWRN("mapping pager cap failed"); @@ -53,15 +53,15 @@ int Platform_thread::start(void *ip, void *sp) l4_thread_control_exc_handler(_remote_pager_cap); l4_thread_control_bind(_utcb, _platform_pd->native_task()); - l4_msgtag_t tag = l4_thread_control_commit(_thread_cap.dst()); + l4_msgtag_t tag = l4_thread_control_commit(_thread_cap.tid()); if (l4_msgtag_has_error(tag)) { PWRN("l4_thread_control_commit for %lx failed!", - (unsigned long) _thread_cap.dst()); + (unsigned long) _thread_cap.tid()); return -1; } /* set ip and sp and run the thread */ - tag = l4_thread_ex_regs(_thread_cap.dst(), (l4_addr_t) ip, (l4_addr_t) sp, 0); + tag = l4_thread_ex_regs(_thread_cap.tid(), (l4_addr_t) ip, (l4_addr_t) sp, 0); if (l4_msgtag_has_error(tag)) { PWRN("l4_thread_ex_regs failed!"); return -1; @@ -96,7 +96,7 @@ void Platform_thread::pause() * The pager thread, which also acts as exception handler, will * leave the thread in exception state until, it gets woken again */ - l4_thread_ex_regs_ret(_thread_cap.dst(), &_pager->state.ip, + l4_thread_ex_regs_ret(_thread_cap.tid(), &_pager->state.ip, &_pager->state.sp, &flags); bool in_syscall = flags == 0; _pager->state.lock.unlock(); @@ -111,7 +111,7 @@ void Platform_thread::pause() * the requested thread, and stored its thread state */ while (exc == _pager->state.exceptions && !_pager->state.in_exception) - l4_thread_switch(_thread_cap.dst()); + l4_thread_switch(_thread_cap.tid()); } } @@ -150,8 +150,8 @@ void Platform_thread::bind(Platform_pd *pd) if (_gate_cap.valid()) { /* map thread's gate cap */ tag = l4_task_map(task, L4_BASE_TASK_CAP, - l4_obj_fpage(_gate_cap.dst(), 0, L4_FPAGE_RWX), - _remote_gate_cap.dst() | L4_ITEM_MAP); + l4_obj_fpage(_gate_cap.tid(), 0, L4_FPAGE_RWX), + _remote_gate_cap.tid() | L4_ITEM_MAP); if (l4_msgtag_has_error(tag)) PWRN("mapping thread's gate cap failed"); } @@ -167,12 +167,12 @@ void Platform_thread::bind(Platform_pd *pd) void Platform_thread::unbind() { - l4_thread_ex_regs(_thread_cap.dst(), 0, 0, 0); + l4_thread_ex_regs(_thread_cap.tid(), 0, 0, 0); l4_task_unmap(L4_BASE_TASK_CAP, - l4_obj_fpage(_gate_cap.dst(), 0, L4_FPAGE_RWX), + l4_obj_fpage(_gate_cap.tid(), 0, L4_FPAGE_RWX), L4_FP_ALL_SPACES | L4_FP_DELETE_OBJ); l4_task_unmap(L4_BASE_TASK_CAP, - l4_obj_fpage(_thread_cap.dst(), 0, L4_FPAGE_RWX), + l4_obj_fpage(_thread_cap.tid(), 0, L4_FPAGE_RWX), L4_FP_ALL_SPACES | L4_FP_DELETE_OBJ); _platform_pd = (Platform_pd*) 0; } @@ -203,7 +203,7 @@ void Platform_thread::cancel_blocking() void Platform_thread::_create_thread() { l4_msgtag_t tag = l4_factory_create_thread(L4_BASE_FACTORY_CAP, - _thread_cap.dst()); + _thread_cap.tid()); if (l4_msgtag_has_error(tag)) PERR("cannot create more thread kernel-objects!"); } @@ -218,18 +218,18 @@ void Platform_thread::_finalize_construction(const char *name, unsigned prio) PWRN("creating thread's irq failed"); /* attach thread to irq */ - tag = l4_irq_attach(_irq_cap, 0, _thread_cap.dst()); + tag = l4_irq_attach(_irq_cap, 0, _thread_cap.tid()); if (l4_msgtag_has_error(tag)) PWRN("attaching thread's irq failed"); /* set human readable name in kernel debugger */ strncpy(_name, name, sizeof(_name)); - Fiasco::l4_debugger_set_object_name(_thread_cap.dst(), name); + Fiasco::l4_debugger_set_object_name(_thread_cap.tid(), name); /* set priority of thread */ prio = Cpu_session::scale_priority(DEFAULT_PRIORITY, prio); l4_sched_param_t params = l4_sched_param(prio); - l4_scheduler_run_thread(L4_BASE_SCHEDULER_CAP, _thread_cap.dst(), ¶ms); + l4_scheduler_run_thread(L4_BASE_SCHEDULER_CAP, _thread_cap.tid(), ¶ms); } @@ -239,7 +239,7 @@ Platform_thread::Platform_thread(const char *name, _badge(Badge_allocator::allocator()->alloc()), _thread_cap(cap_alloc()->alloc_id(_badge), _badge), - _node(_thread_cap.local_name(), 0, this, _thread_cap.dst()), + _node(_thread_cap.local_name(), 0, this, _thread_cap.tid()), _utcb(0), _platform_pd(0), _pager(0) @@ -259,7 +259,7 @@ Platform_thread::Platform_thread(const char *name, Platform_thread::Platform_thread(Native_thread cap, const char *name) : _core_thread(true), _thread_cap(cap, -1), - _node(_thread_cap.local_name(), 0, this, _thread_cap.dst()), + _node(_thread_cap.local_name(), 0, this, _thread_cap.tid()), _utcb(0), _platform_pd(0), _pager(0) @@ -276,7 +276,7 @@ Platform_thread::Platform_thread(const char *name) _badge(Badge_allocator::allocator()->alloc()), _thread_cap(cap_alloc()->alloc_id(_badge), _badge), - _node(_thread_cap.local_name(), 0, this, _thread_cap.dst()), + _node(_thread_cap.local_name(), 0, this, _thread_cap.tid()), _utcb(0), _platform_pd(0), _pager(0) @@ -304,6 +304,6 @@ Platform_thread::~Platform_thread() /* remove the thread capability */ Capability_tree::tree()->remove(&_node); - cap_alloc()->free(_thread_cap.dst()); + cap_alloc()->free(_thread_cap.tid()); Badge_allocator::allocator()->free(_badge); } diff --git a/base-foc/src/core/signal_source_component.cc b/base-foc/src/core/signal_source_component.cc index 3394389254..d403b1e593 100644 --- a/base-foc/src/core/signal_source_component.cc +++ b/base-foc/src/core/signal_source_component.cc @@ -44,7 +44,7 @@ void Signal_source_component::submit(Signal_context_component *context, _signal_queue.enqueue(context); /* wake up client */ - Fiasco::l4_irq_trigger(_blocking_semaphore.dst()); + Fiasco::l4_irq_trigger(_blocking_semaphore.tid()); } } @@ -69,9 +69,9 @@ Signal_source_component::Signal_source_component(Rpc_entrypoint *ep) { using namespace Fiasco; - unsigned long badge = Badge_allocator::allocator()->alloc(); - Fiasco_capability irq = cap_alloc()->alloc_id(badge); - l4_msgtag_t res = l4_factory_create_irq(L4_BASE_FACTORY_CAP, irq); + unsigned long badge = Badge_allocator::allocator()->alloc(); + Native_thread_id irq = cap_alloc()->alloc_id(badge); + l4_msgtag_t res = l4_factory_create_irq(L4_BASE_FACTORY_CAP, irq); if (l4_error(res)) PERR("Allocation of irq object failed!"); diff --git a/base-foc/src/core/thread_start.cc b/base-foc/src/core/thread_start.cc index f16193570c..240abb3895 100644 --- a/base-foc/src/core/thread_start.cc +++ b/base-foc/src/core/thread_start.cc @@ -44,7 +44,7 @@ void Thread_base::start() new(platform()->core_mem_alloc()) Platform_thread(_context->name); platform_specific()->core_pd()->bind_thread(pt); - _tid = pt->gate().dst(); + _tid = pt->gate().tid(); _thread_cap = reinterpret_cap_cast(pt->thread_cap()); pt->pager(platform_specific()->core_pager()); diff --git a/base-foc/src/platform/_main_parent_cap.h b/base-foc/src/platform/_main_parent_cap.h index d04409f1a4..9dc9e7cda6 100644 --- a/base-foc/src/platform/_main_parent_cap.h +++ b/base-foc/src/platform/_main_parent_cap.h @@ -28,8 +28,7 @@ namespace Genode { /* assemble parent capability from object ID and Fiasco cap */ return reinterpret_cap_cast( - Native_capability(Fiasco::Fiasco_capability::PARENT_CAP, - cap.local_name())); + Native_capability(Fiasco::PARENT_CAP, cap.local_name())); } } diff --git a/base-host/include/base/native_types.h b/base-host/include/base/native_types.h index 6b992420b4..ca0fb16975 100644 --- a/base-host/include/base/native_types.h +++ b/base-host/include/base/native_types.h @@ -14,45 +14,21 @@ #ifndef _INCLUDE__BASE__NATIVE_TYPES_H_ #define _INCLUDE__BASE__NATIVE_TYPES_H_ -#include +#include 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 volatile int Native_lock; typedef int Native_thread; typedef Native_thread Native_thread_id; typedef struct { } Native_utcb; - - class Native_capability - { - private: - - long _local_name; - - protected: - - Native_capability(void* ptr) : _local_name((long)ptr) { } - - public: - - Native_capability() : _local_name(0) { } - Native_capability(Native_thread_id, long local_name) - : _local_name(local_name) { } - - bool valid() const { return _local_name != 0; } - int local_name() const { return _local_name; } - void* local() const { return (void*)_local_name; } - int dst() const { return 0; } - Native_thread_id tid() const { return 0; } - - /** - * Copy this capability to another pd. - */ - void copy_to(void* dst) { - memcpy(dst, this, sizeof(Native_capability)); } - }; - typedef int Native_connection_state; + typedef Native_capability_tpl Native_capability; } #endif /* _INCLUDE__BASE__NATIVE_TYPES_H_ */ diff --git a/base-linux/include/base/native_types.h b/base-linux/include/base/native_types.h index 6960bbd9d8..83d574b104 100644 --- a/base-linux/include/base/native_types.h +++ b/base-linux/include/base/native_types.h @@ -14,7 +14,7 @@ #ifndef _INCLUDE__BASE__NATIVE_TYPES_H_ #define _INCLUDE__BASE__NATIVE_TYPES_H_ -#include +#include /* * We cannot just include and here @@ -93,68 +93,17 @@ namespace Genode { inline bool operator != (Native_thread_id t1, Native_thread_id t2) { 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; } + }; + /** * Empty UTCB type expected by the thread library, unused on Linux */ typedef struct { } Native_utcb; - /* - * On Linux, the local_name member of a capability is global - * to the whole system. Therefore, capabilities are to be - * created at a central place that prevents id clashes. - */ - class Native_capability - { - protected: - - long _tid; /* target thread */ - long _local_name; - - protected: - - Native_capability(void* ptr) : _local_name((long)ptr) { } - - public: - - /** - * Default constructor - */ - Native_capability() : _tid(0), _local_name(0) { } - - long local_name() const { return _local_name; } - - void* local() const { return (void*)_local_name; } - - bool valid() const { return _tid != 0; } - - - /**************************************************** - ** Functions to be used by the Linux backend only ** - ****************************************************/ - - /** - * Constructor - * - * This constructor can be called to create a Linux - * capability by hand. It must never be used from - * generic code! - */ - Native_capability(long tid, long local_name) - : _tid(tid), _local_name(local_name) { } - - /** - * Access raw capability data - */ - long dst() const { return _tid; } - long 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 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 e6cdefcfb0..5c08fb0bce 100755 --- a/base-mb/include/base/native_types.h +++ b/base-mb/include/base/native_types.h @@ -14,8 +14,8 @@ #ifndef _INCLUDE__BASE__NATIVE_TYPES_H_ #define _INCLUDE__BASE__NATIVE_TYPES_H_ -#include #include +#include namespace Genode { @@ -30,41 +30,17 @@ namespace Genode { Native_thread_id my_thread_id(); - class Native_capability + + struct Thread_id_check { - private: - - Native_thread_id _tid; - long _local_name; - - protected: - - Native_capability(void* ptr) : _local_name((long)ptr) {} - - public: - - Native_capability() : _tid(0), _local_name(0) { } - - Native_capability(Native_thread_id tid, long local_name) - : _tid(tid), _local_name(local_name) { } - - bool valid() const { return _tid!=0; } - - int local_name() const { return _local_name; } - - void* local() const { return (void*)_local_name; } - - int dst() const { return (int)_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)); } + static bool valid(Kernel::Thread_id tid) { + return tid != Kernel::INVALID_THREAD_ID; } + static Kernel::Thread_id invalid() + { return Kernel::INVALID_THREAD_ID; } }; + + typedef Native_capability_tpl Native_capability; typedef int Native_connection_state; } diff --git a/base-nova/include/base/ipc.h b/base-nova/include/base/ipc.h index 5d5e3f06f2..05602848bf 100644 --- a/base-nova/include/base/ipc.h +++ b/base-nova/include/base/ipc.h @@ -19,9 +19,9 @@ inline void Genode::Ipc_ostream::_marshal_capability(Genode::Native_capability const &cap) { - long unique_id = cap.unique_id(); + long unique_id = cap.local_name(); _write_to_buf(unique_id); - _snd_msg->snd_append_pt_sel(cap.pt_sel()); + _snd_msg->snd_append_pt_sel(cap.tid()); } diff --git a/base-nova/include/base/native_types.h b/base-nova/include/base/native_types.h index 8584709818..7a675f8c9a 100644 --- a/base-nova/include/base/native_types.h +++ b/base-nova/include/base/native_types.h @@ -14,7 +14,7 @@ #ifndef _INCLUDE__BASE__NATIVE_TYPES_H_ #define _INCLUDE__BASE__NATIVE_TYPES_H_ -#include +#include namespace Genode { @@ -53,48 +53,13 @@ namespace Genode { long _utcb[UTCB_SIZE/sizeof(long)]; }; - class Native_capability + struct Portal_checker { - private: - - int _pt_sel; - int _unique_id; - - protected: - - Native_capability(void* ptr) : _unique_id((int)ptr) {} - - public: - - /** - * Default constructor creates an invalid capability - */ - Native_capability() : _pt_sel(0), _unique_id(0) { } - - /** - * Construct capability manually - * - * This constructor should be called only from the platform-specific - * part of the Genode framework. - */ - Native_capability(int pt_sel, int unique_id) - : _pt_sel(pt_sel), _unique_id(unique_id) { } - - bool valid() const { return _pt_sel != 0 && _unique_id != 0; } - int local_name() const { return _unique_id; } - void* local() const { return (void*)_unique_id; } - int dst() const { return _pt_sel; } - - int unique_id() const { return _unique_id; } - int pt_sel() const { return _pt_sel; } - - /** - * Copy this capability to another pd. - */ - void copy_to(void* dst) { - memcpy(dst, this, sizeof(Native_capability)); } + static bool valid(int pt) { return pt != 0; } + static int invalid() { return 0; } }; + typedef Native_capability_tpl Native_capability; typedef int Native_connection_state; } diff --git a/base-nova/include/signal_session/source_client.h b/base-nova/include/signal_session/source_client.h index f713fc199a..b8c4627665 100644 --- a/base-nova/include/signal_session/source_client.h +++ b/base-nova/include/signal_session/source_client.h @@ -67,7 +67,7 @@ namespace Genode { _init_sem(); /* block on semaphore, will be unblocked if signal is available */ - Nova::sm_ctrl(_sem.pt_sel(), Nova::SEMAPHORE_DOWN); + Nova::sm_ctrl(_sem.tid(), Nova::SEMAPHORE_DOWN); /* * Now that the server has unblocked the semaphore, we are sure diff --git a/base-nova/src/base/ipc/ipc.cc b/base-nova/src/base/ipc/ipc.cc index 5f47182dab..455f0c9ad6 100644 --- a/base-nova/src/base/ipc/ipc.cc +++ b/base-nova/src/base/ipc/ipc.cc @@ -138,9 +138,9 @@ void Ipc_client::_call() _rcv_msg->rcv_prepare_pt_sel_window(utcb); /* establish the mapping via a portal traversal */ - if (_dst.pt_sel() == 0) + if (_dst.tid() == 0) PWRN("destination portal is zero"); - int res = Nova::call(_dst.pt_sel()); + int res = Nova::call(_dst.tid()); if (res) PERR("call returned %d", res); diff --git a/base-nova/src/base/thread/thread_nova.cc b/base-nova/src/base/thread/thread_nova.cc index fed16ff725..8be0fa43c8 100644 --- a/base-nova/src/base/thread/thread_nova.cc +++ b/base-nova/src/base/thread/thread_nova.cc @@ -49,7 +49,7 @@ static void request_event_portal(Pager_capability pager_cap, utcb->set_msg_word(1); utcb->crd_rcv = Obj_crd(exc_base + event, 0); - int res = call(pager_cap.pt_sel()); + int res = call(pager_cap.tid()); if (res) PERR("request of event (%d) capability selector failed", event); diff --git a/base-nova/src/core/include/cap_session_component.h b/base-nova/src/core/include/cap_session_component.h index 2d30d8b867..410c2f8552 100644 --- a/base-nova/src/core/include/cap_session_component.h +++ b/base-nova/src/core/include/cap_session_component.h @@ -38,7 +38,7 @@ namespace Genode { { Lock::Guard lock_guard(_lock()); - return Native_capability(ep.pt_sel(), ++_unique_id_cnt); + return Native_capability(ep.tid(), ++_unique_id_cnt); } void free(Native_capability cap) { } diff --git a/base-nova/src/core/include/platform_pd.h b/base-nova/src/core/include/platform_pd.h index ac70e30c80..ac71b20ded 100644 --- a/base-nova/src/core/include/platform_pd.h +++ b/base-nova/src/core/include/platform_pd.h @@ -63,7 +63,7 @@ namespace Genode { /** * Return portal capability selector for parent interface */ - int parent_pt_sel() { return _parent.pt_sel(); } + int parent_pt_sel() { return _parent.tid(); } /** * Assign PD selector to PD diff --git a/base-nova/src/core/signal_source_component.cc b/base-nova/src/core/signal_source_component.cc index b200fc9143..8226c9ced3 100644 --- a/base-nova/src/core/signal_source_component.cc +++ b/base-nova/src/core/signal_source_component.cc @@ -40,7 +40,7 @@ void Signal_source_component::submit(Signal_context_component *context, _signal_queue.enqueue(context); /* wake up client */ - Nova::sm_ctrl(_blocking_semaphore.pt_sel(), Nova::SEMAPHORE_UP); + Nova::sm_ctrl(_blocking_semaphore.tid(), Nova::SEMAPHORE_UP); } } diff --git a/base-nova/src/platform/_main_parent_cap.h b/base-nova/src/platform/_main_parent_cap.h index 05a1dabba3..2bea15f325 100644 --- a/base-nova/src/platform/_main_parent_cap.h +++ b/base-nova/src/platform/_main_parent_cap.h @@ -39,7 +39,7 @@ namespace Genode { /* assemble parent capability from object ID and portal */ return reinterpret_cap_cast(Native_capability(Nova::PT_SEL_PARENT, - cap.unique_id())); + cap.local_name())); } } diff --git a/base-okl4/include/base/native_types.h b/base-okl4/include/base/native_types.h index d2c0f8b4f9..91f349251f 100644 --- a/base-okl4/include/base/native_types.h +++ b/base-okl4/include/base/native_types.h @@ -14,7 +14,7 @@ #ifndef _INCLUDE__BASE__NATIVE_TYPES_H_ #define _INCLUDE__BASE__NATIVE_TYPES_H_ -#include +#include namespace Okl4 { extern "C" { #include @@ -78,63 +78,15 @@ namespace Genode { */ typedef struct { } Native_utcb; - /* - * On OKL4, the local_name member of a capability is global to the whole - * system. Therefore, capabilities are to be created at a central place - * that prevents id clashes. - */ - class Native_capability + struct Thread_id_checker { - protected: - - Okl4::L4_ThreadId_t _tid; - long _local_name; - - protected: - - Native_capability(void* ptr) : _local_name((long)ptr) {} - - public: - - /** - * Default constructor - */ - Native_capability() : _local_name(0) { - _tid = Okl4::L4_nilthread; } - - long local_name() const { return _local_name; } - Okl4::L4_ThreadId_t dst() const { return _tid; } - - void* local() const { return (void*)_local_name; } - - bool valid() const { return !Okl4::L4_IsNilThread(_tid); } - - - /******************************************************** - ** Functions to be used by the Pistachio backend only ** - ********************************************************/ - - /** - * Constructor - * - * Creates a L4 capability manually. This must not be called from - * generic code. - */ - Native_capability(Okl4::L4_ThreadId_t tid, long local_name) - : _tid(tid), _local_name(local_name) { } - - /** - * Access raw capability data - */ - Okl4::L4_ThreadId_t tid() const { return _tid; }; - - /** - * Copy this capability to another pd. - */ - void copy_to(void* dst) { - memcpy(dst, this, sizeof(Native_capability)); } + static bool valid(Okl4::L4_ThreadId_t tid) { + return !Okl4::L4_IsNilThread(tid); } + static Okl4::L4_ThreadId_t invalid() { return Okl4::L4_nilthread; } }; + 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 6e785c7afe..abfdad757f 100644 --- a/base-pistachio/include/base/native_types.h +++ b/base-pistachio/include/base/native_types.h @@ -14,10 +14,16 @@ #ifndef _INCLUDE__BASE__NATIVE_TYPES_H_ #define _INCLUDE__BASE__NATIVE_TYPES_H_ -#include +#include namespace Pistachio { #include + + struct Thread_id_checker + { + static bool valid(L4_ThreadId_t tid) { return !L4_IsNilThread(tid); } + static L4_ThreadId_t invalid() { return L4_nilthread; } + }; } namespace Genode { @@ -59,66 +65,8 @@ namespace Genode { */ typedef struct { } Native_utcb; - /* - * On Pistachio, the local_name member of a capability is global to the - * whole system. Therefore, capabilities are to be created at a central - * place that prevents id clashes. - */ - class Native_capability - { - protected: - - Pistachio::L4_ThreadId_t _tid; - long _local_name; - - protected: - - Native_capability(void* ptr) : _local_name((long)ptr) {} - - public: - - /** - * Default constructor - */ - Native_capability() : _local_name (0) - { - using namespace Pistachio; - _tid = L4_nilthread; - } - - long local_name() const { return _local_name; } - Pistachio::L4_ThreadId_t dst() const { return _tid; } - - void* local() const { return (void*)_local_name; } - - bool valid() const { return !Pistachio::L4_IsNilThread(_tid); } - - - /******************************************************** - ** Functions to be used by the Pistachio backend only ** - ********************************************************/ - - /** - * Constructor - * - * Creates a L4 capability manually. This must not be called from - * generic code. - */ - Native_capability(Pistachio::L4_ThreadId_t tid, long local_name) - : _tid(tid), _local_name(local_name) { } - - /** - * Access raw capability data - */ - Pistachio::L4_ThreadId_t 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 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 new file mode 100644 index 0000000000..a9d3be9510 --- /dev/null +++ b/base/include/base/native_capability.h @@ -0,0 +1,98 @@ +/* + * \brief Native capability template. + * \author Stefan Kalkowski + * \date 2011-03-07 + * + * This file is a generic variant of the Native_capability, which is + * suitable many platforms such as Fiasco, Pistachio, OKL4, Linux, Codezero, + * and some more. + */ + +/* + * Copyright (C) 2012 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__NATIVE_CAPABILITY_H_ +#define _INCLUDE__BASE__NATIVE_CAPABILITY_H_ + +#include + +namespace Genode { + + template + class Native_capability_tpl + { + private: + + ID _tid; + long _local_name; + + protected: + + /** + * 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. + */ + Native_capability_tpl(void* ptr) + : _tid(T::invalid()), _local_name((long)ptr) { } + + public: + + /** + * Constructor for an invalid capability. + */ + Native_capability_tpl() : _tid(T::invalid()), _local_name(0) { } + + /** + * Publicly available constructor. + * + * \param tid kernel-specific thread id + * \param local_name global, unique id of the cap. + */ + Native_capability_tpl(ID tid, long local_name) + : _tid(tid), _local_name(local_name) {} + + /** + * \return true when the capability is a valid one, otherwise false. + */ + bool valid() const { return T::valid(_tid); } + + /** + * \return the globally unique id. + */ + long local_name() const { return _local_name; } + + /** + * \return true if this is a local-capability, otherwise false. + */ + void* local() const { return (void*)_local_name; } + + /** + * Copy this capability to another pd. + */ + void copy_to(void* dst) { + memcpy(dst, this, sizeof(Native_capability_tpl)); } + + + /***************************************** + ** Only used by platform-specific code ** + *****************************************/ + + /** + * \return the kernel-specific thread specifier. + */ + ID tid() const { return _tid; } + }; +} + +#endif /* _INCLUDE__BASE__NATIVE_CAPABILITY_H_ */ +