diff --git a/repos/base-fiasco/src/lib/base/thread_bootstrap.cc b/repos/base-fiasco/src/lib/base/thread_bootstrap.cc index 6d967c4a5f..2044a3f627 100644 --- a/repos/base-fiasco/src/lib/base/thread_bootstrap.cc +++ b/repos/base-fiasco/src/lib/base/thread_bootstrap.cc @@ -21,6 +21,13 @@ using namespace Genode; +static Thread_capability main_thread_cap(Thread_capability main_cap = { }) +{ + static Thread_capability cap = main_cap; + return cap; +} + + /***************************** ** Startup library support ** *****************************/ @@ -41,3 +48,9 @@ void Thread::_init_platform_thread(size_t, Type type) _thread_cap = main_thread_cap(); } + + +void Genode::init_thread_bootstrap(Thread_capability main_cap) +{ + main_thread_cap(main_cap); +} diff --git a/repos/base-foc/src/lib/base/thread_start.cc b/repos/base-foc/src/lib/base/thread_start.cc index 1ccf31bba8..f580106168 100644 --- a/repos/base-foc/src/lib/base/thread_start.cc +++ b/repos/base-foc/src/lib/base/thread_start.cc @@ -20,7 +20,6 @@ #include #include #include -#include /* base-internal includes */ #include @@ -33,6 +32,20 @@ using namespace Genode; +static Capability pd_session_cap(Capability pd_cap = { }) +{ + static Capability cap = pd_cap; /* defined once by 'init_thread_start' */ + return cap; +} + + +static Thread_capability main_thread_cap(Thread_capability main_cap = { }) +{ + static Thread_capability cap = main_cap; /* defined once by 'init_thread_bootstrap' */ + return cap; +} + + void Thread::_deinit_platform_thread() { using namespace Foc; @@ -52,7 +65,7 @@ void Thread::_init_platform_thread(size_t weight, Type type) if (type == NORMAL) { /* create thread at core */ - _thread_cap = _cpu_session->create_thread(env_deprecated()->pd_session_cap(), + _thread_cap = _cpu_session->create_thread(pd_session_cap(), name(), _affinity, Weight(weight)); @@ -101,3 +114,15 @@ void Thread::start() Cpu_thread_client cpu_thread(_thread_cap); cpu_thread.start((addr_t)_thread_start, _stack->top()); } + + +void Genode::init_thread_start(Capability pd_cap) +{ + pd_session_cap(pd_cap); +} + + +void Genode::init_thread_bootstrap(Thread_capability main_cap) +{ + main_thread_cap(main_cap); +} diff --git a/repos/base-hw/src/lib/base/platform.cc b/repos/base-hw/src/lib/base/platform.cc index 51cc656ab2..06c36f622f 100644 --- a/repos/base-hw/src/lib/base/platform.cc +++ b/repos/base-hw/src/lib/base/platform.cc @@ -75,6 +75,9 @@ void Genode::init_platform() init_log(platform.parent); init_rpc_cap_alloc(platform.parent); + init_thread(platform.cpu, platform.rm); + init_thread_start(platform.pd.rpc_cap()); + init_thread_bootstrap(platform.parent.main_thread_cap()); env_stack_area_ram_allocator = &platform.pd; env_stack_area_region_map = &platform.stack_area; diff --git a/repos/base-hw/src/lib/base/thread_start.cc b/repos/base-hw/src/lib/base/thread_start.cc index 83dc1033dc..d04359c82a 100644 --- a/repos/base-hw/src/lib/base/thread_start.cc +++ b/repos/base-hw/src/lib/base/thread_start.cc @@ -18,7 +18,6 @@ #include #include #include -#include /* base-internal includes */ #include @@ -33,6 +32,20 @@ namespace Hw { } +static Capability pd_session_cap(Capability pd_cap = { }) +{ + static Capability cap = pd_cap; /* defined once by 'init_thread_start' */ + return cap; +} + + +static Thread_capability main_thread_cap(Thread_capability main_cap = { }) +{ + static Thread_capability cap = main_cap; + return cap; +} + + /************ ** Thread ** ************/ @@ -45,7 +58,7 @@ void Thread::_init_platform_thread(size_t weight, Type type) /* create server object */ addr_t const utcb = (addr_t)&_stack->utcb(); - _thread_cap = _cpu_session->create_thread(env_deprecated()->pd_session_cap(), + _thread_cap = _cpu_session->create_thread(pd_session_cap(), name(), _affinity, Weight(weight), utcb); return; @@ -70,8 +83,10 @@ void Thread::_init_platform_thread(size_t weight, Type type) void Thread::_deinit_platform_thread() { - if (!_cpu_session) - _cpu_session = env_deprecated()->cpu_session(); + if (!_cpu_session) { + error("Thread::_cpu_session unexpectedly not defined"); + return; + } _cpu_session->kill_thread(_thread_cap); @@ -99,3 +114,15 @@ void Thread::start() /* start thread with its initial IP and aligned SP */ Cpu_thread_client(_thread_cap).start((addr_t)_thread_start, _stack->top()); } + + +void Genode::init_thread_start(Capability pd_cap) +{ + pd_session_cap(pd_cap); +} + + +void Genode::init_thread_bootstrap(Thread_capability main_cap) +{ + main_thread_cap(main_cap); +} diff --git a/repos/base-linux/src/lib/base/platform.cc b/repos/base-linux/src/lib/base/platform.cc index 9019a28eac..949131b282 100644 --- a/repos/base-linux/src/lib/base/platform.cc +++ b/repos/base-linux/src/lib/base/platform.cc @@ -197,6 +197,9 @@ void Genode::init_platform() init_log(platform.parent); init_rpc_cap_alloc(platform.parent); + init_thread(platform.cpu, platform.rm); + init_thread_start(platform.pd_cap); + init_thread_bootstrap(platform.parent.main_thread_cap()); env_stack_area_region_map = &platform.pd._stack_area; env_stack_area_ram_allocator = &platform.pd; diff --git a/repos/base-linux/src/lib/base/thread_linux.cc b/repos/base-linux/src/lib/base/thread_linux.cc index 6a8d5e8f16..3f0d50bca7 100644 --- a/repos/base-linux/src/lib/base/thread_linux.cc +++ b/repos/base-linux/src/lib/base/thread_linux.cc @@ -19,7 +19,6 @@ #include #include #include -#include /* base-internal includes */ #include @@ -30,11 +29,27 @@ using namespace Genode; + extern int main_thread_futex_counter; + static void empty_signal_handler(int) { } +static Capability pd_session_cap(Capability pd_cap = { }) +{ + static Capability cap = pd_cap; /* defined once by 'init_thread_start' */ + return cap; +} + + +static Thread_capability main_thread_cap(Thread_capability main_cap = { }) +{ + static Thread_capability cap = main_cap; /* defined once by 'init_thread_bootstrap' */ + return cap; +} + + static Blockade &startup_lock() { static Blockade blockade; @@ -88,12 +103,14 @@ void Thread::_thread_start() void Thread::_init_platform_thread(size_t /* weight */, Type type) { /* if no cpu session is given, use it from the environment */ - if (!_cpu_session) - _cpu_session = env_deprecated()->cpu_session(); + if (!_cpu_session) { + error("Thread::_init_platform_thread: _cpu_session not initialized"); + return; + } /* for normal threads create an object at the CPU session */ if (type == NORMAL) { - _thread_cap = _cpu_session->create_thread(env_deprecated()->pd_session_cap(), + _thread_cap = _cpu_session->create_thread(pd_session_cap(), _stack->name().string(), Affinity::Location(), Weight()); @@ -165,3 +182,15 @@ void Thread::start() /* wait until the 'thread_start' function got entered */ startup_lock().block(); } + + +void Genode::init_thread_start(Capability pd_cap) +{ + pd_session_cap(pd_cap); +} + + +void Genode::init_thread_bootstrap(Thread_capability main_cap) +{ + main_thread_cap(main_cap); +} diff --git a/repos/base-linux/src/lib/lx_hybrid/lx_hybrid.cc b/repos/base-linux/src/lib/lx_hybrid/lx_hybrid.cc index e201eb9b5f..dcb865d51e 100644 --- a/repos/base-linux/src/lib/lx_hybrid/lx_hybrid.cc +++ b/repos/base-linux/src/lib/lx_hybrid/lx_hybrid.cc @@ -402,6 +402,11 @@ static void *thread_start(void *arg) } +void Genode::init_thread(Cpu_session &, Region_map &) { } +void Genode::init_thread_start(Capability) { } +void Genode::init_thread_bootstrap(Thread_capability) { } + + extern "C" void *malloc(::size_t size); extern "C" void free(void *); diff --git a/repos/base-nova/src/lib/base/thread_start.cc b/repos/base-nova/src/lib/base/thread_start.cc index c7cfd29d83..2dc04d0cf7 100644 --- a/repos/base-nova/src/lib/base/thread_start.cc +++ b/repos/base-nova/src/lib/base/thread_start.cc @@ -22,7 +22,6 @@ #include #include #include -#include /* base-internal includes */ #include @@ -37,6 +36,20 @@ using namespace Genode; +static Capability pd_session_cap(Capability pd_cap = { }) +{ + static Capability cap = pd_cap; /* defined once by 'init_thread_start' */ + return cap; +} + + +static Thread_capability main_thread_cap(Thread_capability main_cap = { }) +{ + static Thread_capability cap = main_cap; + return cap; +} + + /** * Entry point entered by new threads */ @@ -112,7 +125,7 @@ void Thread::_init_platform_thread(size_t weight, Type type) _init_cpu_session_and_trace_control(); /* create thread at core */ - _thread_cap = _cpu_session->create_thread(env_deprecated()->pd_session_cap(), name(), + _thread_cap = _cpu_session->create_thread(pd_session_cap(), name(), _affinity, Weight(weight)); if (!_thread_cap.valid()) throw Cpu_session::Thread_creation_failed(); @@ -191,3 +204,15 @@ void Thread::start() /* request creation of SC to let thread run*/ cpu_thread.resume(); } + + +void Genode::init_thread_start(Capability pd_cap) +{ + pd_session_cap(pd_cap); +} + + +void Genode::init_thread_bootstrap(Thread_capability main_cap) +{ + main_thread_cap(main_cap); +} diff --git a/repos/base-okl4/src/lib/base/thread_bootstrap.cc b/repos/base-okl4/src/lib/base/thread_bootstrap.cc index 7ecbc7f57d..b996771f89 100644 --- a/repos/base-okl4/src/lib/base/thread_bootstrap.cc +++ b/repos/base-okl4/src/lib/base/thread_bootstrap.cc @@ -22,9 +22,19 @@ #include #include +using namespace Genode; + + Okl4::L4_ThreadId_t main_thread_tid; +static Thread_capability main_thread_cap(Thread_capability main_cap = { }) +{ + static Thread_capability cap = main_cap; + return cap; +} + + /******************* ** local helpers ** *******************/ @@ -83,3 +93,9 @@ void Thread::_init_platform_thread(size_t, Type type) native_thread().l4id.raw = main_thread_tid.raw; _thread_cap = main_thread_cap(); } + + +void Genode::init_thread_bootstrap(Thread_capability main_cap) +{ + main_thread_cap(main_cap); +} diff --git a/repos/base-pistachio/src/lib/base/thread_bootstrap.cc b/repos/base-pistachio/src/lib/base/thread_bootstrap.cc index de515d4b37..f6502f2de1 100644 --- a/repos/base-pistachio/src/lib/base/thread_bootstrap.cc +++ b/repos/base-pistachio/src/lib/base/thread_bootstrap.cc @@ -20,9 +20,19 @@ #include #include +using namespace Genode; + + Pistachio::L4_ThreadId_t main_thread_tid; +static Thread_capability main_thread_cap(Thread_capability main_cap = { }) +{ + static Thread_capability cap = main_cap; + return cap; +} + + /***************************** ** Startup library support ** *****************************/ @@ -52,3 +62,9 @@ void Genode::Thread::_init_platform_thread(size_t, Type type) _thread_cap = main_thread_cap(); } + + +void Genode::init_thread_bootstrap(Thread_capability main_cap) +{ + main_thread_cap(main_cap); +} diff --git a/repos/base-sel4/src/lib/base/thread_bootstrap.cc b/repos/base-sel4/src/lib/base/thread_bootstrap.cc index 0aa24ebaa1..27e1bd99a3 100644 --- a/repos/base-sel4/src/lib/base/thread_bootstrap.cc +++ b/repos/base-sel4/src/lib/base/thread_bootstrap.cc @@ -17,6 +17,7 @@ /* base-internal includes */ #include +#include /***************************** @@ -37,3 +38,6 @@ void Genode::Thread::_thread_bootstrap() native_thread().lock_sel = (unsigned)_stack->utcb().lock_sel(); } } + + +void Genode::init_thread_bootstrap(Thread_capability) { } diff --git a/repos/base/lib/mk/base.inc b/repos/base/lib/mk/base.inc index 75370107db..9a42798af0 100644 --- a/repos/base/lib/mk/base.inc +++ b/repos/base/lib/mk/base.inc @@ -1,5 +1,5 @@ SRC_CC += default_log.cc -SRC_CC += platform.cc stack_area.cc main_thread_cap.cc +SRC_CC += platform.cc stack_area.cc SRC_CC += rpc_cap_alloc.cc heartbeat.cc SRC_CC += vm.cc diff --git a/repos/base/src/core/main.cc b/repos/base/src/core/main.cc index 65ff6ec488..8852f14386 100644 --- a/repos/base/src/core/main.cc +++ b/repos/base/src/core/main.cc @@ -90,9 +90,6 @@ Platform_generic &Core::platform() { return platform_specific(); } void Genode::init_platform() { core_env(); } -Thread_capability Genode::main_thread_cap() { return Thread_capability(); } - - /** * Dummy implementation for core that has no parent to ask for resources */ diff --git a/repos/base/src/include/base/internal/globals.h b/repos/base/src/include/base/internal/globals.h index e5133de691..daf36eaebc 100644 --- a/repos/base/src/include/base/internal/globals.h +++ b/repos/base/src/include/base/internal/globals.h @@ -26,8 +26,6 @@ namespace Genode { extern Region_map *env_stack_area_region_map; extern Ram_allocator *env_stack_area_ram_allocator; - Thread_capability main_thread_cap(); - void init_platform(); void init_stack_area(); void init_exception_handling(Env &); @@ -42,6 +40,9 @@ namespace Genode { void init_rpc_cap_alloc(Parent &); void init_parent_resource_requests(Env &); void init_heartbeat_monitoring(Env &); + void init_thread(Cpu_session &, Region_map &); + void init_thread_start(Capability); + void init_thread_bootstrap(Thread_capability); void deinit_heartbeat_monitoring(); void exec_static_constructors(); diff --git a/repos/base/src/lib/base/main_thread_cap.cc b/repos/base/src/lib/base/main_thread_cap.cc deleted file mode 100644 index 0019920008..0000000000 --- a/repos/base/src/lib/base/main_thread_cap.cc +++ /dev/null @@ -1,24 +0,0 @@ -/* - * \brief Access to the component's initial thread capability - * \author Norman Feske - * \date 2017-05-10 - */ - -/* - * Copyright (C) 2017 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU Affero General Public License version 3. - */ - -/* Genode includes */ -#include - -/* base-internal includes */ -#include -#include - -Genode::Thread_capability Genode::main_thread_cap() -{ - return Genode::env_deprecated()->parent()->main_thread_cap(); -} diff --git a/repos/base/src/lib/base/platform.cc b/repos/base/src/lib/base/platform.cc index 90203ef8b6..2ced35d45b 100644 --- a/repos/base/src/lib/base/platform.cc +++ b/repos/base/src/lib/base/platform.cc @@ -67,6 +67,9 @@ void Genode::init_platform() init_log(platform.parent); init_rpc_cap_alloc(platform.parent); + init_thread(platform.cpu, platform.rm); + init_thread_start(platform.pd.rpc_cap()); + init_thread_bootstrap(platform.parent.main_thread_cap()); env_stack_area_ram_allocator = &platform.pd; env_stack_area_region_map = &platform.stack_area; diff --git a/repos/base/src/lib/base/thread.cc b/repos/base/src/lib/base/thread.cc index b21ffb319d..f1f41402ed 100644 --- a/repos/base/src/lib/base/thread.cc +++ b/repos/base/src/lib/base/thread.cc @@ -18,7 +18,6 @@ #include #include #include -#include /* base-internal includes */ #include @@ -27,6 +26,10 @@ using namespace Genode; +static Region_map *local_rm_ptr; +static Cpu_session *cpu_session_ptr; + + void Stack::size(size_t const size) { /* check if the stack needs to be enhanced */ @@ -211,31 +214,40 @@ Thread::Thread(size_t weight, const char *name, size_t stack_size, void Thread::_init_cpu_session_and_trace_control() { + if (!cpu_session_ptr || !local_rm_ptr) { + error("missing call of init_thread"); + return; + } + /* if no CPU session is given, use it from the environment */ if (!_cpu_session) { - _cpu_session = env_deprecated()->cpu_session(); } + _cpu_session = cpu_session_ptr; } /* initialize trace control now that the CPU session must be valid */ Dataspace_capability ds = _cpu_session->trace_control(); if (ds.valid()) { - _trace_control = env_deprecated()->rm_session()->attach(ds); } + _trace_control = local_rm_ptr->attach(ds); } } Thread::Thread(size_t weight, const char *name, size_t stack_size, Type type, Affinity::Location affinity) -: Thread(weight, name, stack_size, type, nullptr, affinity) { } +: + Thread(weight, name, stack_size, type, cpu_session_ptr, affinity) +{ } -Thread::Thread(Env &env, Name const &name, size_t stack_size, Location location, +Thread::Thread(Env &, Name const &name, size_t stack_size, Location location, Weight weight, Cpu_session &cpu) -: Thread(weight.value, name.string(), stack_size, NORMAL, - &cpu == &env.cpu() ? nullptr : &cpu, location) +: + Thread(weight.value, name.string(), stack_size, NORMAL, &cpu, location) { } Thread::Thread(Env &env, Name const &name, size_t stack_size) -: Thread(env, name, stack_size, Location(), Weight(), env.cpu()) { } +: + Thread(env, name, stack_size, Location(), Weight(), env.cpu()) +{ } Thread::~Thread() @@ -257,6 +269,13 @@ Thread::~Thread() * from here and any following RPC call will stumple upon the * detached trace control dataspace. */ - if (_trace_control) - env_deprecated()->rm_session()->detach(_trace_control); + if (_trace_control && local_rm_ptr) + local_rm_ptr->detach(_trace_control); +} + + +void Genode::init_thread(Cpu_session &cpu_session, Region_map &local_rm) +{ + local_rm_ptr = &local_rm; + cpu_session_ptr = &cpu_session; } diff --git a/repos/base/src/lib/base/thread_start.cc b/repos/base/src/lib/base/thread_start.cc index cdc4f1fe6a..c7fb1325ac 100644 --- a/repos/base/src/lib/base/thread_start.cc +++ b/repos/base/src/lib/base/thread_start.cc @@ -17,14 +17,21 @@ #include #include #include -#include /* base-internal includes */ #include +#include using namespace Genode; +static Capability pd_session_cap(Capability pd_cap = { }) +{ + static Capability cap = pd_cap; /* defined once by 'init_thread_start' */ + return cap; +} + + /** * Entry point entered by new threads */ @@ -59,8 +66,10 @@ void Thread::_thread_start() void Thread::_deinit_platform_thread() { - if (!_cpu_session) - _cpu_session = env_deprecated()->cpu_session(); + if (!_cpu_session) { + error("Thread::_cpu_session unexpectedly not defined"); + return; + } _cpu_session->kill_thread(_thread_cap); } @@ -72,7 +81,7 @@ void Thread::start() /* create thread at core */ addr_t const utcb = (addr_t)&_stack->utcb(); - _thread_cap = _cpu_session->create_thread(env_deprecated()->pd_session_cap(), name(), + _thread_cap = _cpu_session->create_thread(pd_session_cap(), name(), _affinity, Weight(), utcb); if (!_thread_cap.valid()) throw Cpu_session::Thread_creation_failed(); @@ -80,3 +89,9 @@ void Thread::start() /* start execution at initial instruction pointer and stack pointer */ Cpu_thread_client(_thread_cap).start((addr_t)_thread_start, _stack->top()); } + + +void Genode::init_thread_start(Capability pd_cap) +{ + pd_session_cap(pd_cap); +} diff --git a/repos/base/src/lib/startup/init_main_thread.cc b/repos/base/src/lib/startup/init_main_thread.cc index 4de48cc3fa..1fe40a3af2 100644 --- a/repos/base/src/lib/startup/init_main_thread.cc +++ b/repos/base/src/lib/startup/init_main_thread.cc @@ -17,7 +17,6 @@ #include #include #include -#include /* base-internal includes */ #include