diff --git a/base-foc/src/core/cpu_session_extension.cc b/base-foc/src/core/cpu_session_extension.cc index cc6f20db4..0ba9e8d6c 100644 --- a/base-foc/src/core/cpu_session_extension.cc +++ b/base-foc/src/core/cpu_session_extension.cc @@ -66,6 +66,12 @@ Genode::Native_capability Genode::Cpu_session_component::alloc_irq() l4_msgtag_t res = l4_factory_create_irq(L4_BASE_FACTORY_CAP, i->kcap()); if (l4_error(res)) PWRN("Allocation of irq object failed!"); + + /* + * Increment reference-counter, because we don't hold any + * reference to IRQ object by now + */ + i->inc(); return Genode::Native_capability(i); } diff --git a/ports-foc/src/lib/l4lx/genode_block.cc b/ports-foc/src/lib/l4lx/genode_block.cc index 83bafaa2b..80df88c4d 100644 --- a/ports-foc/src/lib/l4lx/genode_block.cc +++ b/ports-foc/src/lib/l4lx/genode_block.cc @@ -96,7 +96,7 @@ namespace { Genode::size_t _blk_size; Genode::size_t _blk_cnt; Block::Session::Operations _blk_ops; - Fiasco::l4_cap_idx_t _irq_cap; + Genode::Native_capability _irq_cap; Genode::Signal_context _tx; char _name[32]; @@ -105,21 +105,21 @@ namespace { Block_device(const char *label) : _alloc(Genode::env()->heap()), _session(&_alloc, TX_BUF_SIZE, label), - _irq_cap(L4lx::vcpu_connection()->alloc_irq().dst()) + _irq_cap(L4lx::vcpu_connection()->alloc_irq()) { _session.info(&_blk_cnt, &_blk_size, &_blk_ops); Genode::strncpy(_name, label, sizeof(_name)); } - Req_cache *cache() { return &_cache; } - Block::Connection *session() { return &_session; } - Fiasco::l4_cap_idx_t irq_cap() { return _irq_cap; } - Genode::Signal_context *context() { return &_tx; } - Genode::size_t block_size() { return _blk_size; } - Genode::size_t block_count() { return _blk_cnt; } + Req_cache *cache() { return &_cache; } + Block::Connection *session() { return &_session; } + Fiasco::l4_cap_idx_t irq_cap() { return _irq_cap.dst(); } + Genode::Signal_context *context() { return &_tx; } + Genode::size_t block_size() { return _blk_size; } + Genode::size_t block_count() { return _blk_cnt; } bool writeable() { return _blk_ops.supported(Block::Packet_descriptor::WRITE); } - const char *name() { return _name; } + const char *name() { return _name; } }; diff --git a/ports-foc/src/lib/l4lx/genode_net.cc b/ports-foc/src/lib/l4lx/genode_net.cc index 4cdfb6fb6..4c09ab576 100644 --- a/ports-foc/src/lib/l4lx/genode_net.cc +++ b/ports-foc/src/lib/l4lx/genode_net.cc @@ -153,9 +153,9 @@ extern "C" { l4_cap_idx_t genode_net_irq_cap() { - static l4_cap_idx_t cap = L4lx::vcpu_connection()->alloc_irq().dst(); - static Signal_thread th(cap); - return cap; + static Genode::Native_capability cap = L4lx::vcpu_connection()->alloc_irq(); + static Signal_thread th(cap.dst()); + return cap.dst(); } diff --git a/ports-foc/src/lib/l4lx/genode_terminal.cc b/ports-foc/src/lib/l4lx/genode_terminal.cc index 0597d4229..a7529e27c 100644 --- a/ports-foc/src/lib/l4lx/genode_terminal.cc +++ b/ports-foc/src/lib/l4lx/genode_terminal.cc @@ -95,10 +95,10 @@ extern "C" { l4_cap_idx_t genode_terminal_irq(unsigned idx) { - static l4_cap_idx_t cap = L4lx::vcpu_connection()->alloc_irq().dst(); + static Genode::Native_capability cap = L4lx::vcpu_connection()->alloc_irq(); if (!signal_thread) - signal_thread = new (Genode::env()->heap()) Signal_thread(cap); - return cap; + signal_thread = new (Genode::env()->heap()) Signal_thread(cap.dst()); + return cap.dst(); } diff --git a/ports-foc/src/lib/l4lx/include/vcpu.h b/ports-foc/src/lib/l4lx/include/vcpu.h index 7b887aca9..7416c80cd 100644 --- a/ports-foc/src/lib/l4lx/include/vcpu.h +++ b/ports-foc/src/lib/l4lx/include/vcpu.h @@ -88,10 +88,16 @@ namespace L4lx { _tid = state.kcap; _context->utcb = state.utcb; - l4_utcb_tcr_u(state.utcb)->user[UTCB_TCR_THREAD_OBJ] = (addr_t)this; - l4_utcb_tcr_u(state.utcb)->user[UTCB_TCR_BADGE] = state.id; - l4_utcb_tcr_u(state.utcb)->user[0] = state.kcap; /* L4X_UTCB_TCR_ID */ - cap_map()->insert(state.id, state.kcap); + try { + l4_utcb_tcr_u(state.utcb)->user[UTCB_TCR_BADGE] = state.id; + l4_utcb_tcr_u(state.utcb)->user[UTCB_TCR_THREAD_OBJ] = (addr_t)this; + l4_utcb_tcr_u(state.utcb)->user[0] = state.kcap; /* L4X_UTCB_TCR_ID */ + + /* we need to manually increase the reference counter here */ + cap_map()->insert(state.id, state.kcap)->inc(); + } catch(Cap_index_allocator::Region_conflict) { + PERR("could not insert id %x", state.id); + } /* register initial IP and SP at core */ addr_t stack = (addr_t)&_context->stack[-4]; diff --git a/ports-foc/src/lib/l4lx/l4lx_irq.cc b/ports-foc/src/lib/l4lx/l4lx_irq.cc index 79029a68b..b7f7d45d5 100644 --- a/ports-foc/src/lib/l4lx/l4lx_irq.cc +++ b/ports-foc/src/lib/l4lx/l4lx_irq.cc @@ -71,8 +71,8 @@ static unsigned int startup_timer(struct l4x_irq_desc_private *p) Genode::snprintf(name, sizeof(name), "timer.i%d", TIMER_IRQ); - Genode::Native_capability cap = L4lx::vcpu_connection()->alloc_irq(); - p->irq_cap = cap.dst(); + static Genode::Native_capability timer_cap = L4lx::vcpu_connection()->alloc_irq(); + p->irq_cap = timer_cap.dst(); p->cpu = 0; l4lx_thread_create(timer_irq_thread, cpu, 0, 0, 0, 0, 0, name); diff --git a/ports-foc/src/lib/l4lx/startup.cc b/ports-foc/src/lib/l4lx/startup.cc index bdff73c13..af67e6761 100644 --- a/ports-foc/src/lib/l4lx/startup.cc +++ b/ports-foc/src/lib/l4lx/startup.cc @@ -103,7 +103,8 @@ static void prepare_l4re_env() using namespace Fiasco; Genode::Foc_cpu_connection cpu; - + static Genode::Native_capability main_thread_cap + = cpu.native_cap(Genode::env()->cpu_session()->first()); l4re_env_t *env = l4re_env(); env->first_free_utcb = (l4_addr_t)l4_utcb() + L4_UTCB_OFFSET; env->utcb_area = l4_fpage((l4_addr_t)l4_utcb(), @@ -113,7 +114,7 @@ static void prepare_l4re_env() env->scheduler = L4_BASE_SCHEDULER_CAP; env->mem_alloc = L4_INVALID_CAP; env->log = L4_INVALID_CAP; - env->main_thread = cpu.native_cap(Genode::env()->cpu_session()->first()).dst(); + env->main_thread = main_thread_cap.dst(); env->rm = Fiasco::THREADS_BASE_CAP + Fiasco::THREAD_PAGER_CAP; }