base: remove env_deprecated from thread-start code

This patch replaces the internal use 'env_deprecated()' from the
implementation of the thread API in the base library. It also
replaces the global accessor 'main_thread_cap' by the explicit
propagation of the main-thread's capability to the single point of
use via a new 'init_thread_bootstap' function.

Issue #4784
This commit is contained in:
Norman Feske 2023-06-20 13:45:33 +02:00
parent adf0b893e8
commit 3489672bc0
19 changed files with 233 additions and 57 deletions

View File

@ -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);
}

View File

@ -20,7 +20,6 @@
#include <cpu_thread/client.h>
#include <foc/native_capability.h>
#include <foc_native_cpu/client.h>
#include <deprecated/env.h>
/* base-internal includes */
#include <base/internal/stack.h>
@ -33,6 +32,20 @@
using namespace Genode;
static Capability<Pd_session> pd_session_cap(Capability<Pd_session> pd_cap = { })
{
static Capability<Pd_session> 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_session> pd_cap)
{
pd_session_cap(pd_cap);
}
void Genode::init_thread_bootstrap(Thread_capability main_cap)
{
main_thread_cap(main_cap);
}

View File

@ -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;

View File

@ -18,7 +18,6 @@
#include <base/sleep.h>
#include <base/env.h>
#include <cpu_thread/client.h>
#include <deprecated/env.h>
/* base-internal includes */
#include <base/internal/stack_allocator.h>
@ -33,6 +32,20 @@ namespace Hw {
}
static Capability<Pd_session> pd_session_cap(Capability<Pd_session> pd_cap = { })
{
static Capability<Pd_session> 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_session> pd_cap)
{
pd_session_cap(pd_cap);
}
void Genode::init_thread_bootstrap(Thread_capability main_cap)
{
main_thread_cap(main_cap);
}

View File

@ -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;

View File

@ -19,7 +19,6 @@
#include <base/log.h>
#include <linux_native_cpu/client.h>
#include <cpu_thread/client.h>
#include <deprecated/env.h>
/* base-internal includes */
#include <base/internal/stack.h>
@ -30,11 +29,27 @@
using namespace Genode;
extern int main_thread_futex_counter;
static void empty_signal_handler(int) { }
static Capability<Pd_session> pd_session_cap(Capability<Pd_session> pd_cap = { })
{
static Capability<Pd_session> 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_session> pd_cap)
{
pd_session_cap(pd_cap);
}
void Genode::init_thread_bootstrap(Thread_capability main_cap)
{
main_thread_cap(main_cap);
}

View File

@ -402,6 +402,11 @@ static void *thread_start(void *arg)
}
void Genode::init_thread(Cpu_session &, Region_map &) { }
void Genode::init_thread_start(Capability<Pd_session>) { }
void Genode::init_thread_bootstrap(Thread_capability) { }
extern "C" void *malloc(::size_t size);
extern "C" void free(void *);

View File

@ -22,7 +22,6 @@
#include <session/session.h>
#include <cpu_thread/client.h>
#include <nova_native_cpu/client.h>
#include <deprecated/env.h>
/* base-internal includes */
#include <base/internal/stack.h>
@ -37,6 +36,20 @@
using namespace Genode;
static Capability<Pd_session> pd_session_cap(Capability<Pd_session> pd_cap = { })
{
static Capability<Pd_session> 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_session> pd_cap)
{
pd_session_cap(pd_cap);
}
void Genode::init_thread_bootstrap(Thread_capability main_cap)
{
main_thread_cap(main_cap);
}

View File

@ -22,9 +22,19 @@
#include <base/internal/globals.h>
#include <base/internal/okl4.h>
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);
}

View File

@ -20,9 +20,19 @@
#include <base/internal/globals.h>
#include <base/internal/pistachio.h>
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);
}

View File

@ -17,6 +17,7 @@
/* base-internal includes */
#include <base/internal/stack.h>
#include <base/internal/globals.h>
/*****************************
@ -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) { }

View File

@ -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

View File

@ -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
*/

View File

@ -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<Pd_session>);
void init_thread_bootstrap(Thread_capability);
void deinit_heartbeat_monitoring();
void exec_static_constructors();

View File

@ -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 <deprecated/env.h>
/* base-internal includes */
#include <base/internal/globals.h>
#include <base/internal/parent_cap.h>
Genode::Thread_capability Genode::main_thread_cap()
{
return Genode::env_deprecated()->parent()->main_thread_cap();
}

View File

@ -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;

View File

@ -18,7 +18,6 @@
#include <base/thread.h>
#include <base/env.h>
#include <base/sleep.h>
#include <deprecated/env.h>
/* base-internal includes */
#include <base/internal/stack_allocator.h>
@ -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;
}

View File

@ -17,14 +17,21 @@
#include <base/sleep.h>
#include <base/env.h>
#include <cpu_thread/client.h>
#include <deprecated/env.h>
/* base-internal includes */
#include <base/internal/stack.h>
#include <base/internal/globals.h>
using namespace Genode;
static Capability<Pd_session> pd_session_cap(Capability<Pd_session> pd_cap = { })
{
static Capability<Pd_session> 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_session> pd_cap)
{
pd_session_cap(pd_cap);
}

View File

@ -17,7 +17,6 @@
#include <util/construct_at.h>
#include <base/env.h>
#include <base/thread.h>
#include <deprecated/env.h>
/* base-internal includes */
#include <base/internal/globals.h>