base: de-duplicate src/lib/base/platform.cc

By splitting the 'init_capability_slab()' implementation to a separate
compilation unit 'capability_slab.cc', base-hw no longer needs a
customized version of 'lib/base/platform.cc'.

Related to issue #4784
This commit is contained in:
Norman Feske 2023-06-20 17:53:41 +02:00
parent 6e30d00eef
commit 0ab69a2bb8
13 changed files with 90 additions and 125 deletions

View File

@ -4,5 +4,6 @@ LIBS += syscall-fiasco base-fiasco-common cxx timeout
SRC_CC += thread_start.cc
SRC_CC += cache.cc
SRC_CC += capability_slab.cc
SRC_CC += capability_space.cc
SRC_CC += signal_transmitter.cc signal.cc

View File

@ -4,6 +4,7 @@ LIBS += base-foc-common syscall-foc cxx
SRC_CC += cap_map_remove.cc cap_alloc.cc
SRC_CC += cache.cc
SRC_CC += capability_slab.cc
SRC_CC += thread_start.cc
SRC_CC += signal_transmitter.cc signal.cc
SRC_CC += stack_area_addr.cc

View File

@ -3,6 +3,7 @@ include $(BASE_DIR)/lib/mk/base.inc
SRC_CC += log.cc
SRC_CC += thread_start.cc
SRC_CC += capability.cc
SRC_CC += capability_slab.cc
SRC_CC += cache.cc
SRC_CC += raw_write_string.cc
SRC_CC += signal_receiver.cc

View File

@ -0,0 +1,64 @@
/*
* \brief Capability slab management
* \author Norman Feske
* \date 2023-06-20
*/
/*
* Copyright (C) 2023 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.
*/
#include <util/retry.h>
#include <base/internal/globals.h>
#include <base/internal/native_env.h>
#include <hw_native_pd/client.h>
using namespace Genode;
static Parent *parent_ptr;
static Pd_session::Native_pd *native_pd_ptr;
void Genode::init_cap_slab(Pd_session &pd, Parent &parent)
{
static Hw_native_pd_client native_pd(pd.native_pd());
parent_ptr = &parent;
native_pd_ptr = &native_pd;
}
void Genode::upgrade_capability_slab()
{
if (!native_pd_ptr || !parent_ptr) {
error("missing call of 'init_cap_slab'");
return;
}
auto request_resources_from_parent = [&] (Ram_quota ram, Cap_quota caps)
{
/*
* The call of 'resource_request' is handled synchronously by
* 'Expanding_parent_client'.
*/
String<100> const args("ram_quota=", ram, ", cap_quota=", caps);
parent_ptr->resource_request(args.string());
};
retry<Genode::Out_of_caps>(
[&] () {
retry<Genode::Out_of_ram>(
[&] () {
native_pd_ptr->upgrade_cap_slab(); },
[&] () {
request_resources_from_parent(Ram_quota{8192}, Cap_quota{0});
});
},
[&] () {
request_resources_from_parent(Ram_quota{0}, Cap_quota{2});
});
}

View File

@ -1,124 +0,0 @@
/*
* \brief Environment initialization
* \author Norman Feske
* \author Christian Helmuth
* \date 2006-07-27
*/
/*
* Copyright (C) 2006-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.
*/
#include <deprecated/env.h>
#include <base/internal/platform.h>
#include <base/internal/globals.h>
#include <base/internal/native_env.h>
#include <base/connection.h>
#include <base/service.h>
#include <hw_native_pd/client.h>
using namespace Genode;
static Platform *_platform_ptr;
Env_deprecated *Genode::env_deprecated()
{
if (!_platform_ptr) {
error("missing call of init_platform");
for (;;);
}
struct Impl : Env_deprecated, Noncopyable
{
Platform &_pf;
Impl(Platform &pf) : _pf(pf) { }
Parent *parent() override { return &_pf.parent; }
Cpu_session *cpu_session() override { return &_pf.cpu; }
Cpu_session_capability cpu_session_cap() override { return _pf.cpu.rpc_cap(); }
Region_map *rm_session() override { return &_pf.rm; }
Pd_session *pd_session() override { return &_pf.pd; }
Pd_session_capability pd_session_cap() override { return _pf.pd.rpc_cap(); }
};
static Impl impl { *_platform_ptr };
return &impl;
}
using Native_pd_capability = Genode::Capability<Genode::Pd_session::Native_pd>;
static Native_pd_capability native_pd_cap;
void Genode::init_parent_resource_requests(Genode::Env &env)
{
/**
* Catch up asynchronous resource request and notification
* mechanism construction of the expanding parent environment
*/
using Parent = Expanding_parent_client;
static_cast<Parent*>(&env.parent())->init_fallback_signal_handling();
native_pd_cap = env.pd().native_pd();
}
void Genode::init_platform()
{
static Genode::Platform 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;
_platform_ptr = &platform;
}
void Genode::binary_ready_hook_for_platform() { }
void Genode::upgrade_capability_slab()
{
if (!native_pd_cap.valid() || !_platform_ptr) {
Genode::error("cannot upgrade capability slab, "
"not initialized appropriatedly");
return;
}
auto request_resources_from_parent = [&] (Ram_quota ram, Cap_quota caps)
{
/*
* The call of 'resource_request' is handled synchronously by
* 'Expanding_parent_client'.
*/
String<100> const args("ram_quota=", ram, ", cap_quota=", caps);
_platform_ptr->parent.resource_request(args.string());
};
retry<Genode::Out_of_caps>(
[&] () {
retry<Genode::Out_of_ram>(
[&] () {
Genode::Hw_native_pd_client pd(native_pd_cap);
pd.upgrade_cap_slab();
},
[&] () {
request_resources_from_parent(Ram_quota{8192}, Cap_quota{0});
});
},
[&] () {
request_resources_from_parent(Ram_quota{0}, Cap_quota{2});
});
}

View File

@ -6,5 +6,6 @@
include $(BASE_DIR)/lib/mk/base.inc
SRC_CC += platform.cc
SRC_CC += capability_slab.cc
LIBS += syscall-linux

View File

@ -4,6 +4,7 @@ LIBS += base-nova-common cxx timeout
SRC_CC += thread_start.cc
SRC_CC += cache.cc
SRC_CC += signal.cc
SRC_CC += capability_slab.cc
#
# Prevent the compiler from deleting null pointer checks related to 'this == 0'

View File

@ -3,6 +3,7 @@ include $(BASE_DIR)/lib/mk/base.inc
LIBS += base-okl4-common syscall-okl4 cxx timeout
SRC_CC += thread_start.cc
SRC_CC += cache.cc
SRC_CC += capability_slab.cc
SRC_CC += capability_space.cc
SRC_CC += signal_transmitter.cc
SRC_CC += signal.cc

View File

@ -4,6 +4,7 @@ LIBS += base-pistachio-common syscall-pistachio cxx timeout
SRC_CC += thread_start.cc
SRC_CC += cache.cc
SRC_CC += capability_slab.cc
SRC_CC += capability_space.cc
SRC_CC += signal_transmitter.cc
SRC_CC += signal.cc

View File

@ -1,6 +1,6 @@
include $(BASE_DIR)/lib/mk/base.inc
SRC_CC += capability_space.cc
SRC_CC += capability_space.cc capability_slab.cc
SRC_CC += thread_start.cc thread_init.cc
SRC_CC += cache.cc
SRC_CC += signal_transmitter.cc signal.cc

View File

@ -31,6 +31,7 @@ namespace Genode {
void init_exception_handling(Env &);
void init_signal_transmitter(Env &);
void init_signal_receiver(Pd_session &, Parent &);
void init_cap_slab(Pd_session &, Parent &);
void init_cxx_heap(Env &);
void init_cxx_guard();
void init_ldso_phdr(Env &);

View File

@ -0,0 +1,16 @@
/*
* \brief Capability slab init for kernels without an expandable cap space
* \author Norman Feske
* \date 2023-06-20
*/
/*
* Copyright (C) 2023 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.
*/
#include <base/internal/globals.h>
void Genode::init_cap_slab(Pd_session &, Parent &) { }

View File

@ -67,6 +67,7 @@ void Genode::init_platform()
init_log(platform.parent);
init_rpc_cap_alloc(platform.parent);
init_cap_slab(platform.pd, platform.parent);
init_thread(platform.cpu, platform.rm);
init_thread_start(platform.pd.rpc_cap());
init_thread_bootstrap(platform.parent.main_thread_cap());