From 8b69bc96f95782f0765ca6d49132426f2c3b2fad Mon Sep 17 00:00:00 2001 From: Martin Stein Date: Fri, 9 Jul 2021 12:09:31 +0200 Subject: [PATCH] base-hw: separate variants of Kernel_object(...) For the constructor of Kernel_object there are two variants. One for the case that it is called from Core where the kernel object (type T) must be created via a syscall and one when it is called from within the kernel and the kernel object can be created directly. Selecting one of these variants was done using a bool argument to the constructor. However, this implies that the constructor of Kernel_object and that of T have the same signature in the variadic arguments, even in the syscall case, although technically it would then not be necessary. This becomes a problem as soon as kernel objects created by Core shall receive additional arguments from the kernel, for instance a reference to the global CPU pool, and therefore stands in the way when wanting to get rid of global statics in the kernel. Therefore, this commit introduces two constructors that are selected through enum arguments: ! Kernel_object(Called_from_kernel, ...); ! Kernel_object(Called_from_core, ...); Ref #4217 --- repos/base-hw/src/core/object.h | 22 ++++++++++++++----- repos/base-hw/src/core/pager.cc | 3 ++- repos/base-hw/src/core/platform_pd.cc | 8 +++++-- repos/base-hw/src/core/platform_thread.cc | 4 ++-- .../src/core/signal_source_component.h | 7 ++++-- 5 files changed, 31 insertions(+), 13 deletions(-) diff --git a/repos/base-hw/src/core/object.h b/repos/base-hw/src/core/object.h index 6b8c04d751..4267b4b7a0 100644 --- a/repos/base-hw/src/core/object.h +++ b/repos/base-hw/src/core/object.h @@ -44,19 +44,29 @@ class Genode::Kernel_object : public Genode::Constructible - Kernel_object(bool syscall, ARGS &&... args) + Kernel_object(Called_from_core, ARGS &&... args) : - _cap(Capability_space::import(syscall ? T::syscall_create(*this, args...) - : Kernel::cap_id_invalid())) + _cap(Capability_space::import(T::syscall_create(*this, args...))) + { } + + /** + * Creates a kernel object directly + */ + template + Kernel_object(Called_from_kernel, ARGS &&... args) + : + _cap(Capability_space::import(Kernel::cap_id_invalid())) { - if (!syscall) - Genode::Constructible>::construct(args...); + Genode::Constructible>::construct(args...); } ~Kernel_object() diff --git a/repos/base-hw/src/core/pager.cc b/repos/base-hw/src/core/pager.cc index 5c012f9398..e5cc671c91 100644 --- a/repos/base-hw/src/core/pager.cc +++ b/repos/base-hw/src/core/pager.cc @@ -110,7 +110,8 @@ Pager_entrypoint::Pager_entrypoint(Rpc_cap_factory &) : Thread(Weight::DEFAULT_WEIGHT, "pager_ep", PAGER_EP_STACK_SIZE, Type::NORMAL), - _kobj(true) + + _kobj(_kobj.CALLED_FROM_CORE) { start(); } diff --git a/repos/base-hw/src/core/platform_pd.cc b/repos/base-hw/src/core/platform_pd.cc index 10f796b79d..24c382bcd4 100644 --- a/repos/base-hw/src/core/platform_pd.cc +++ b/repos/base-hw/src/core/platform_pd.cc @@ -96,7 +96,9 @@ Hw::Address_space::Address_space(Page_table & tt, _tt(tt), _tt_phys(Platform::core_page_table()), _tt_alloc(tt_alloc), - _kobj(false, *(Page_table*)translation_table_phys(), pd) + _kobj(_kobj.CALLED_FROM_KERNEL, + *(Page_table*)translation_table_phys(), + pd) { } @@ -107,7 +109,9 @@ Hw::Address_space::Address_space(Platform_pd & pd) _tt_array(new (_cma()) Array([] (void * virt) { return (addr_t)_cma().phys_addr(virt);})), _tt_alloc(_tt_array->alloc()), - _kobj(true, *(Page_table*)translation_table_phys(), pd) + _kobj(_kobj.CALLED_FROM_CORE, + *(Page_table*)translation_table_phys(), + pd) { } diff --git a/repos/base-hw/src/core/platform_thread.cc b/repos/base-hw/src/core/platform_thread.cc index 82df2e1fd2..4c844fa48b 100644 --- a/repos/base-hw/src/core/platform_thread.cc +++ b/repos/base-hw/src/core/platform_thread.cc @@ -68,7 +68,7 @@ Platform_thread::Platform_thread(Label const &label, Native_utcb &utcb) _utcb_pd_addr(&utcb), _main_thread(false), _location(Affinity::Location()), - _kobj(true, _label.string()) + _kobj(_kobj.CALLED_FROM_CORE, _label.string()) { /* create UTCB for a core thread */ void *utcb_phys; @@ -95,7 +95,7 @@ Platform_thread::Platform_thread(size_t const quota, _quota(quota), _main_thread(false), _location(location), - _kobj(true, _priority, _quota, _label.string()) + _kobj(_kobj.CALLED_FROM_CORE, _priority, _quota, _label.string()) { try { _utcb = core_env().pd_session()->alloc(sizeof(Native_utcb), CACHED); diff --git a/repos/base-hw/src/core/signal_source_component.h b/repos/base-hw/src/core/signal_source_component.h index f9cc6c6972..c5d49a9e2a 100644 --- a/repos/base-hw/src/core/signal_source_component.h +++ b/repos/base-hw/src/core/signal_source_component.h @@ -56,7 +56,7 @@ struct Genode::Signal_source_component : private Kernel_object(true), + Kernel_object(CALLED_FROM_CORE), Signal_source_pool::Entry(Kernel_object::cap()) { } @@ -70,7 +70,10 @@ struct Genode::Signal_source_component : private Kernel_object(true, s.signal_receiver(), imprint), + Kernel_object(CALLED_FROM_CORE, + s.signal_receiver(), + imprint), + Signal_context_pool::Entry(Kernel_object::_cap) { }