base: introduce platform_init function

The new 'init_platform' function performs the platform-specific
component-local low-level initialization. It allows for the
differentiation between core and regular components as well as
kernel-dependent peculiarities.

This patch introduces a consistent notion of a 'Platform'. Within core,
the 'Platform' contains the kernel-specific initialization. Outside
core, the platform sets up the interplay with the parent component. In
all cases, the platform is constructed while running on the initial
stack.

Issue #4784
This commit is contained in:
Norman Feske 2023-03-10 16:50:25 +01:00
parent 9e0ef550a8
commit 61926ebc07
29 changed files with 470 additions and 568 deletions

View File

@ -6,4 +6,3 @@ SRC_CC += thread_start.cc
SRC_CC += cache.cc
SRC_CC += capability_space.cc
SRC_CC += signal_transmitter.cc signal.cc
SRC_CC += platform.cc

View File

@ -13,4 +13,3 @@ SRC_CC += rpc_dispatch_loop.cc
SRC_CC += thread.cc thread_bootstrap.cc thread_myself.cc utcb.cc
SRC_CC += capability.cc
SRC_CC += signal_source_client.cc
SRC_CC += platform.cc

View File

@ -8,6 +8,5 @@ SRC_CC += raw_write_string.cc
SRC_CC += signal_receiver.cc
SRC_CC += stack_area_addr.cc
SRC_CC += native_utcb.cc
SRC_CC += platform.cc
LIBS += startup-hw base-hw-common syscall-hw cxx timeout-hw

View File

@ -1,6 +1,5 @@
LIBS = cxx
SRC_CC += bootstrap/env.cc
SRC_CC += bootstrap/init.cc
SRC_CC += bootstrap/lock.cc
SRC_CC += bootstrap/log.cc

View File

@ -1,22 +0,0 @@
/*
* \brief Environment dummy implementation needed by cxx library
* \author Stefan Kalkowski
* \date 2016-09-23
*/
/*
* Copyright (C) 2016-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 <base/env.h>
#include <hw/assert.h>
#include <deprecated/env.h>
Genode::Env_deprecated * Genode::env_deprecated()
{
assert(false);
return nullptr;
}

View File

@ -12,7 +12,8 @@
* under the terms of the GNU Affero General Public License version 3.
*/
#include <base/internal/platform_env.h>
#include <deprecated/env.h>
#include <base/internal/platform.h>
#include <base/internal/globals.h>
#include <base/internal/native_env.h>
#include <base/connection.h>
@ -20,20 +21,35 @@
#include <hw_native_pd/client.h>
namespace Genode {
using namespace Genode;
/*
* Request pointer to static environment of the Genode application
*/
Env_deprecated *env_deprecated()
{
/*
* By placing the environment as static object here, we ensure that its
* constructor gets called when this function is used the first time.
*/
static Genode::Platform_env _env;
return &_env;
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;
}
@ -41,7 +57,7 @@ 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)
void Genode::init_parent_resource_requests(Genode::Env &env)
{
/**
* Catch up asynchronous resource request and notification
@ -53,10 +69,27 @@ void Genode::init_parent_resource_requests(Genode::Env & env)
}
void Genode::init_platform()
{
static Genode::Platform platform;
init_log(platform.parent);
init_rpc_cap_alloc(platform.parent);
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()) {
Genode::error("Cannot upgrade capability slab "
if (!native_pd_cap.valid() || !_platform_ptr) {
Genode::error("cannot upgrade capability slab, "
"not initialized appropriatedly");
return;
}
@ -68,7 +101,7 @@ void Genode::upgrade_capability_slab()
* 'Expanding_parent_client'.
*/
String<100> const args("ram_quota=", ram, ", cap_quota=", caps);
internal_env().parent().resource_request(args.string());
_platform_ptr->parent.resource_request(args.string());
};
retry<Genode::Out_of_caps>(

View File

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

View File

@ -11,4 +11,3 @@ SRC_CC += thread.cc thread_myself.cc thread_linux.cc
SRC_CC += capability_space.cc capability_raw.cc
SRC_CC += attach_stack_area.cc
SRC_CC += signal_transmitter.cc signal.cc
SRC_CC += platform.cc

View File

@ -154,9 +154,9 @@ void Platform::wait_for_exit()
}
/****************************************************
** Support for Platform_env_base::Region_map_mmap **
****************************************************/
/*********************************
** Support for Region_map_mmap **
*********************************/
size_t Region_map_mmap::_dataspace_size(Capability<Dataspace> ds_cap)
{

View File

@ -0,0 +1,68 @@
/*
* \brief Linux-specific environment
* \author Norman Feske
* \author Christian Helmuth
* \date 2006-07-28
*/
/*
* 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.
*/
#ifndef _INCLUDE__BASE__INTERNAL__PLATFORM_H_
#define _INCLUDE__BASE__INTERNAL__PLATFORM_H_
/* Genode includes */
#include <base/heap.h>
/* base-internal includes */
#include <base/internal/expanding_cpu_session_client.h>
#include <base/internal/expanding_region_map_client.h>
#include <base/internal/expanding_pd_session_client.h>
#include <base/internal/expanding_parent_client.h>
#include <base/internal/region_map_mmap.h>
#include <base/internal/local_rm_session.h>
#include <base/internal/local_pd_session.h>
#include <base/internal/local_parent.h>
namespace Genode { struct Platform; }
struct Genode::Platform
{
Region_map_mmap rm { false };
Local_parent parent;
Pd_session_capability pd_cap =
static_cap_cast<Pd_session>(parent.session_cap(Parent::Env::pd()));
Cpu_session_capability cpu_cap =
static_cap_cast<Cpu_session>(parent.session_cap(Parent::Env::cpu()));
Local_pd_session pd { parent, pd_cap };
Expanding_cpu_session_client cpu { parent, cpu_cap, Parent::Env::cpu() };
Heap heap { pd, rm };
Platform(Parent_capability cap) : parent(cap, rm, heap)
{
_attach_stack_area();
}
~Platform()
{
parent.exit(0);
}
/**
* Attach stack area to local address space (for non-hybrid components)
*/
void _attach_stack_area();
};
#endif /* _INCLUDE__BASE__INTERNAL__PLATFORM_H_ */

View File

@ -1,128 +0,0 @@
/*
* \brief Linux-specific environment
* \author Norman Feske
* \author Christian Helmuth
* \date 2006-07-28
*/
/*
* 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.
*/
#ifndef _INCLUDE__BASE__INTERNAL__PLATFORM_ENV_H_
#define _INCLUDE__BASE__INTERNAL__PLATFORM_ENV_H_
/* Genode includes */
#include <base/heap.h>
/* base-internal includes */
#include <base/internal/expanding_cpu_session_client.h>
#include <base/internal/expanding_region_map_client.h>
#include <base/internal/expanding_pd_session_client.h>
#include <base/internal/expanding_parent_client.h>
#include <base/internal/region_map_mmap.h>
#include <base/internal/local_rm_session.h>
#include <base/internal/local_pd_session.h>
#include <base/internal/local_parent.h>
#include <deprecated/env.h>
namespace Genode {
class Platform_env_base;
class Platform_env;
}
/**
* Common base class of the 'Platform_env' implementations for core and
* non-core processes.
*/
class Genode::Platform_env_base : public Env_deprecated
{
private:
Cpu_session_capability _cpu_session_cap;
Expanding_cpu_session_client _cpu_session_client;
Region_map_mmap &_region_map_mmap;
Pd_session_capability _pd_session_cap;
protected:
/*
* The '_local_pd_session' is protected because it is needed by
* 'Platform_env' to initialize the stack area. This must not happen
* in 'Platform_env_base' because the procedure differs between
* core and non-core components.
*/
Local_pd_session _local_pd_session;
public:
Platform_env_base(Parent &parent,
Region_map_mmap &local_rm,
Cpu_session_capability cpu_cap,
Pd_session_capability pd_cap)
:
_cpu_session_cap(cpu_cap),
_cpu_session_client(parent, cpu_cap, Parent::Env::cpu()),
_region_map_mmap(local_rm),
_pd_session_cap(pd_cap),
_local_pd_session(parent, _pd_session_cap)
{ }
/******************************
** Env_deprecated interface **
******************************/
Region_map *rm_session() override { return &_region_map_mmap; }
Cpu_session *cpu_session() override { return &_cpu_session_client; }
Cpu_session_capability cpu_session_cap() override { return _cpu_session_cap; }
Pd_session *pd_session() override { return &_local_pd_session; }
Pd_session_capability pd_session_cap() override { return _pd_session_cap; }
};
/**
* 'Platform_env' used by all processes except for core
*/
class Genode::Platform_env : public Platform_env_base
{
private:
/**
* Return instance of parent interface
*/
Local_parent &_parent();
Heap _heap;
/**
* Attach stack area to local address space (for non-hybrid components)
*/
void _attach_stack_area();
public:
/**
* Constructor
*/
Platform_env();
/**
* Destructor
*/
~Platform_env() { _parent().exit(0); }
/******************************
** Env_deprecated interface **
******************************/
Parent *parent() override { return &_parent(); }
};
#endif /* _INCLUDE__BASE__INTERNAL__PLATFORM_ENV_H_ */

View File

@ -16,14 +16,14 @@
*/
/* base-internal includes */
#include <base/internal/platform_env.h>
#include <base/internal/platform.h>
using namespace Genode;
void Platform_env::_attach_stack_area()
void Platform::_attach_stack_area()
{
_local_pd_session._address_space.attach_at(_local_pd_session._stack_area.dataspace(),
stack_area_virtual_base(),
stack_area_virtual_size());
pd._address_space.attach_at(pd._stack_area.dataspace(),
stack_area_virtual_base(),
stack_area_virtual_size());
}

View File

@ -29,7 +29,7 @@ using namespace Genode;
*
* At this point in time, we do not yet know the TID and PID of the new
* thread. Those information will be provided to core by the constructor of
* the 'Platform_env' of the new process.
* the 'Platform' of the new process.
*/
Child::Initial_thread::Initial_thread(Cpu_session &cpu,
Pd_session_capability pd,

View File

@ -1,42 +1,230 @@
/*
* \brief Platform dependant hook after binary ready
* \brief Support for the Linux-specific environment
* \author Norman Feske
* \author Stefan Thoeni
* \date 2019-12-13
* \date 2008-12-12
*/
/*
* Copyright (C) 2019 Genode Labs GmbH
* Copyright (C) 2019 gapfruit AG
* Copyright (C) 2008-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/log.h>
#include <util/arg_string.h>
#include <base/thread.h>
#include <linux_dataspace/client.h>
#include <linux_syscalls.h>
/* base-internal includes */
#include <base/internal/platform.h>
#include <base/internal/native_thread.h>
#include <base/internal/globals.h>
#include <linux_syscalls.h>
#include <base/internal/parent_socket_handle.h>
#include <base/internal/capability_space_tpl.h>
#include <deprecated/env.h>
using namespace Genode;
/*********************************
** Support for Rm_session_mmap **
*********************************/
size_t Region_map_mmap::_dataspace_size(Dataspace_capability ds)
{
if (local(ds))
return Local_capability<Dataspace>::deref(ds)->size();
return Dataspace_client(ds).size();
}
int Region_map_mmap::_dataspace_fd(Dataspace_capability ds)
{
Untyped_capability fd_cap = Linux_dataspace_client(ds).fd();
return lx_dup(Capability_space::ipc_cap_data(fd_cap).dst.socket.value);
}
bool Region_map_mmap::_dataspace_writeable(Dataspace_capability ds)
{
return Dataspace_client(ds).writeable();
}
/******************
** Local_parent **
******************/
Session_capability Local_parent::session(Parent::Client::Id id,
Service_name const &service_name,
Session_args const &args,
Affinity const &affinity)
{
if (strcmp(service_name.string(), Rm_session::service_name()) == 0) {
Local_rm_session *local_rm_session = new (_alloc)
Local_rm_session(_local_rm, _alloc, _local_sessions_id_space, id);
return local_rm_session->local_session_cap();
}
return Expanding_parent_client::session(id, service_name, args, affinity);
}
Parent::Close_result Local_parent::close(Client::Id id)
{
auto close_local_fn = [&] (Local_session &local_session)
{
Capability<Rm_session> rm =
static_cap_cast<Rm_session>(local_session.local_session_cap());
destroy(_alloc, Local_capability<Rm_session>::deref(rm));
};
/*
* Local RM sessions are present in the '_local_sessions_id_space'. If the
* apply succeeds, 'id' referred to the local session. Otherwise, we
* forward the request to the parent.
*/
try {
_local_sessions_id_space.apply<Local_session>(id, close_local_fn);
return CLOSE_DONE;
}
catch (Id_space<Client>::Unknown_id) { }
return Parent_client::close(id);
}
Local_parent::Local_parent(Parent_capability parent_cap,
Region_map &local_rm, Allocator &alloc)
:
Expanding_parent_client(parent_cap), _local_rm(local_rm), _alloc(alloc)
{ }
/**************
** Platform **
**************/
/**
* List of Unix environment variables, initialized by the startup code
*/
extern char **lx_environ;
/**
* Read environment variable as long value
*/
static unsigned long get_env_ulong(const char *key)
{
for (char **curr = lx_environ; curr && *curr; curr++) {
Arg arg = Arg_string::find_arg(*curr, key);
if (arg.valid())
return arg.ulong_value(0);
}
return 0;
}
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_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_cap; }
};
static Impl impl { *_platform_ptr };
return &impl;
}
static Parent_capability obtain_parent_cap()
{
long const local_name = get_env_ulong("parent_local_name");
Untyped_capability parent_cap =
Capability_space::import(Rpc_destination(Lx_sd{PARENT_SOCKET_HANDLE}),
Rpc_obj_key(local_name));
return reinterpret_cap_cast<Parent>(parent_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();
}
void Genode::init_platform()
{
static Platform platform { obtain_parent_cap() };
/* allow use of deprecated_env */
_platform_ptr = &platform;
init_log(platform.parent);
init_rpc_cap_alloc(platform.parent);
env_stack_area_region_map = &platform.pd._stack_area;
env_stack_area_ram_allocator = &platform.pd;
/* register TID and PID of the main thread at core */
Linux_native_cpu_client native_cpu(platform.cpu.native_cpu());
native_cpu.thread_id(platform.parent.main_thread_cap(),
lx_getpid(), lx_gettid());
init_rpc_cap_alloc(platform.parent);
}
/*************************
** Support for seccomp **
*************************/
/* Linux includes */
#include <errno.h>
#include <sys/prctl.h> /* prctl */
#include <linux/seccomp.h> /* seccomp's constants */
using namespace Genode;
extern char _binary_seccomp_bpf_policy_bin_start[];
extern char _binary_seccomp_bpf_policy_bin_end[];
namespace Genode {
struct Bpf_program
{
uint16_t blk_cnt;
uint64_t *blks;
};
}
void Genode::binary_ready_hook_for_platform()
{
if (lx_prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) != 0) {
@ -44,6 +232,12 @@ void Genode::binary_ready_hook_for_platform()
throw Exception();
}
struct Bpf_program
{
uint16_t blk_cnt;
uint64_t *blks;
};
for (char* i = _binary_seccomp_bpf_policy_bin_start;
i < _binary_seccomp_bpf_policy_bin_end - sizeof(uint32_t); i++) {
@ -67,4 +261,3 @@ void Genode::binary_ready_hook_for_platform()
throw Exception();
}
}

View File

@ -1,180 +0,0 @@
/*
* \brief Support for the Linux-specific environment
* \author Norman Feske
* \date 2008-12-12
*/
/*
* Copyright (C) 2008-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 <util/arg_string.h>
#include <base/thread.h>
#include <linux_dataspace/client.h>
#include <linux_syscalls.h>
/* base-internal includes */
#include <base/internal/platform_env.h>
#include <base/internal/native_thread.h>
#include <base/internal/globals.h>
#include <base/internal/parent_socket_handle.h>
#include <base/internal/capability_space_tpl.h>
using namespace Genode;
/****************************************************
** Support for Platform_env_base::Rm_session_mmap **
****************************************************/
size_t Region_map_mmap::_dataspace_size(Dataspace_capability ds)
{
if (local(ds))
return Local_capability<Dataspace>::deref(ds)->size();
return Dataspace_client(ds).size();
}
int Region_map_mmap::_dataspace_fd(Dataspace_capability ds)
{
Untyped_capability fd_cap = Linux_dataspace_client(ds).fd();
return lx_dup(Capability_space::ipc_cap_data(fd_cap).dst.socket.value);
}
bool Region_map_mmap::_dataspace_writeable(Dataspace_capability ds)
{
return Dataspace_client(ds).writeable();
}
/******************
** Local_parent **
******************/
Session_capability Local_parent::session(Parent::Client::Id id,
Service_name const &service_name,
Session_args const &args,
Affinity const &affinity)
{
if (strcmp(service_name.string(), Rm_session::service_name()) == 0) {
Local_rm_session *local_rm_session = new (_alloc)
Local_rm_session(_local_rm, _alloc, _local_sessions_id_space, id);
return local_rm_session->local_session_cap();
}
return Expanding_parent_client::session(id, service_name, args, affinity);
}
Parent::Close_result Local_parent::close(Client::Id id)
{
auto close_local_fn = [&] (Local_session &local_session)
{
Capability<Rm_session> rm =
static_cap_cast<Rm_session>(local_session.local_session_cap());
destroy(_alloc, Local_capability<Rm_session>::deref(rm));
};
/*
* Local RM sessions are present in the '_local_sessions_id_space'. If the
* apply succeeds, 'id' referred to the local session. Otherwise, we
* forward the request to the parent.
*/
try {
_local_sessions_id_space.apply<Local_session>(id, close_local_fn);
return CLOSE_DONE;
}
catch (Id_space<Client>::Unknown_id) { }
return Parent_client::close(id);
}
Local_parent::Local_parent(Parent_capability parent_cap,
Region_map &local_rm, Allocator &alloc)
:
Expanding_parent_client(parent_cap), _local_rm(local_rm), _alloc(alloc)
{ }
/******************
** Platform_env **
******************/
/**
* List of Unix environment variables, initialized by the startup code
*/
extern char **lx_environ;
/**
* Read environment variable as long value
*/
static unsigned long get_env_ulong(const char *key)
{
for (char **curr = lx_environ; curr && *curr; curr++) {
Arg arg = Arg_string::find_arg(*curr, key);
if (arg.valid())
return arg.ulong_value(0);
}
return 0;
}
static Parent_capability obtain_parent_cap()
{
long const local_name = get_env_ulong("parent_local_name");
Untyped_capability parent_cap =
Capability_space::import(Rpc_destination(Lx_sd{PARENT_SOCKET_HANDLE}),
Rpc_obj_key(local_name));
return reinterpret_cap_cast<Parent>(parent_cap);
}
static Region_map_mmap &local_rm()
{
static Region_map_mmap local_rm(false);
return local_rm;
}
Local_parent &Platform_env::_parent()
{
static Local_parent local_parent(obtain_parent_cap(), local_rm(), _heap);
return local_parent;
}
Platform_env::Platform_env()
:
Platform_env_base(_parent(), local_rm(),
static_cap_cast<Cpu_session>(_parent().session_cap(Parent::Env::cpu())),
static_cap_cast<Pd_session> (_parent().session_cap(Parent::Env::pd()))),
_heap(Platform_env_base::pd_session(), Platform_env_base::rm_session())
{
_attach_stack_area();
env_stack_area_region_map = &_local_pd_session._stack_area;
env_stack_area_ram_allocator = Platform_env_base::pd_session();
/* register TID and PID of the main thread at core */
Linux_native_cpu_client native_cpu(cpu_session()->native_cpu());
native_cpu.thread_id(parent()->main_thread_cap(), lx_getpid(), lx_gettid());
init_rpc_cap_alloc(_parent());
}

View File

@ -20,7 +20,7 @@
/* base-internal includes */
#include <base/internal/native_thread.h>
#include <base/internal/globals.h>
#include <base/internal/platform_env.h>
#include <base/internal/platform.h>
/**
@ -125,6 +125,7 @@ Genode::size_t Component::stack_size()
int main()
{
Genode::init_platform();
Genode::bootstrap_component();
/* never reached */
@ -558,11 +559,11 @@ Thread::~Thread()
}
/******************
** Platform_env **
******************/
/**************
** Platform **
**************/
void Platform_env::_attach_stack_area()
void Platform::_attach_stack_area()
{
/*
* Omit attaching the stack area to the local address space for hybrid

View File

@ -4,4 +4,3 @@ LIBS += base-nova-common cxx timeout
SRC_CC += thread_start.cc
SRC_CC += cache.cc
SRC_CC += signal.cc
SRC_CC += platform.cc

View File

@ -6,4 +6,3 @@ SRC_CC += cache.cc
SRC_CC += capability_space.cc
SRC_CC += signal_transmitter.cc
SRC_CC += signal.cc
SRC_CC += platform.cc

View File

@ -7,4 +7,3 @@ SRC_CC += cache.cc
SRC_CC += capability_space.cc
SRC_CC += signal_transmitter.cc
SRC_CC += signal.cc
SRC_CC += platform.cc

View File

@ -12,4 +12,3 @@ SRC_CC += rpc_dispatch_loop.cc
SRC_CC += thread.cc thread_myself.cc thread_bootstrap.cc
SRC_CC += capability.cc capability_raw.cc
SRC_CC += stack_area_addr.cc
SRC_CC += platform.cc

View File

@ -1,5 +1,5 @@
SRC_CC += default_log.cc
SRC_CC += env_deprecated.cc stack_area.cc main_thread_cap.cc
SRC_CC += platform.cc stack_area.cc main_thread_cap.cc
SRC_CC += rpc_cap_alloc.cc heartbeat.cc
SRC_CC += vm.cc

View File

@ -87,6 +87,9 @@ Platform &Core::platform_specific()
Platform_generic &Core::platform() { return platform_specific(); }
void Genode::init_platform() { core_env(); }
Thread_capability Genode::main_thread_cap() { return Thread_capability(); }
@ -185,12 +188,10 @@ class Core_child : public Child_policy
****************/
/*
* In contrast to the 'Platform_env' used by non-core components, core disables
* the signal thread but overriding 'Genode::init_signal_thread' with a dummy.
* Within core, the signal thread is not needed as core is never supposed to
* receive any signals. Otherwise, the signal thread would be the only
* non-entrypoint thread within core, which would be a problem on NOVA where
* the creation of regular threads within core is unsupported.
* In contrast to non-core components, core disables the signal thread by
* overriding 'Genode::init_signal_thread' with a dummy. Within core, the
* signal thread is not needed as core is never supposed to receive any
* signals.
*/
void Genode::init_signal_thread(Env &) { }

View File

@ -28,6 +28,7 @@ namespace Genode {
Thread_capability main_thread_cap();
void init_platform();
void init_stack_area();
void init_exception_handling(Env &);
void init_signal_transmitter(Env &);

View File

@ -0,0 +1,50 @@
/*
* \brief Platform of Genode component
* \author Norman Feske
* \author Christian Helmuth
* \date 2006-07-28
*/
/*
* Copyright (C) 2006-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.
*/
#ifndef _INCLUDE__BASE__INTERNAL__PLATFORM_H_
#define _INCLUDE__BASE__INTERNAL__PLATFORM_H_
/* base-internal includes */
#include <base/internal/parent_cap.h>
#include <base/internal/attached_stack_area.h>
#include <base/internal/expanding_cpu_session_client.h>
#include <base/internal/expanding_pd_session_client.h>
#include <base/internal/expanding_region_map_client.h>
#include <base/internal/expanding_parent_client.h>
namespace Genode { class Platform; }
struct Genode::Platform : Noncopyable
{
Expanding_parent_client parent { Genode::parent_cap() };
template <typename T> Capability<T> _request(Parent::Client::Id id)
{
return static_cap_cast<T>(parent.session_cap(id));
}
Expanding_pd_session_client pd {
parent, _request<Pd_session>(Parent::Env::pd()) };
Expanding_cpu_session_client cpu {
parent, _request<Cpu_session>(Parent::Env::cpu()), Parent::Env::cpu() };
Expanding_region_map_client rm {
parent, pd.rpc_cap(), pd.address_space(), Parent::Env::pd() };
Attached_stack_area stack_area { parent, pd.rpc_cap() };
};
#endif /* _INCLUDE__BASE__INTERNAL__PLATFORM_H_ */

View File

@ -1,112 +0,0 @@
/*
* \brief Platform environment of Genode process
* \author Norman Feske
* \author Christian Helmuth
* \date 2006-07-28
*
* This file is a generic variant of the platform environment, which is
* suitable for platforms such as L4ka::Pistachio and L4/Fiasco. On other
* platforms, it may be replaced by a platform-specific version residing
* in the corresponding 'base-<platform>' repository.
*/
/*
* 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.
*/
#ifndef _INCLUDE__BASE__INTERNAL__PLATFORM_ENV_H_
#define _INCLUDE__BASE__INTERNAL__PLATFORM_ENV_H_
/* Genode includes */
#include <base/log.h>
#include <base/env.h>
#include <base/heap.h>
#include <deprecated/env.h>
/* base-internal includes */
#include <base/internal/globals.h>
#include <base/internal/parent_cap.h>
#include <base/internal/attached_stack_area.h>
#include <base/internal/expanding_cpu_session_client.h>
#include <base/internal/expanding_pd_session_client.h>
#include <base/internal/expanding_region_map_client.h>
#include <base/internal/expanding_parent_client.h>
namespace Genode {
class Platform_env_base : public Env_deprecated { };
class Platform_env;
}
class Genode::Platform_env : public Platform_env_base
{
private:
Expanding_parent_client _parent_client;
struct Resources
{
template <typename T>
Capability<T> request(Parent &parent, Parent::Client::Id id)
{
return static_cap_cast<T>(parent.session_cap(id));
}
Expanding_pd_session_client pd;
Expanding_cpu_session_client cpu;
Expanding_region_map_client rm;
Resources(Parent &parent)
:
pd (parent, request<Pd_session> (parent, Parent::Env::pd())),
cpu(parent, request<Cpu_session>(parent, Parent::Env::cpu()),
Parent::Env::cpu()),
rm(parent, pd.rpc_cap(), pd.address_space(), Parent::Env::pd())
{ }
};
Resources _resources;
Heap _heap;
/*
* The '_heap' must be initialized before the '_stack_area'
* because the 'Local_parent' performs a dynamic memory allocation
* due to the creation of the stack area's sub-RM session.
*/
Attached_stack_area _stack_area { _parent_client, _resources.pd.rpc_cap() };
public:
/**
* Standard constructor
*/
Platform_env()
:
_parent_client(Genode::parent_cap()),
_resources(_parent_client),
_heap(&_resources.pd, &_resources.rm, Heap::UNLIMITED)
{
env_stack_area_ram_allocator = &_resources.pd;
env_stack_area_region_map = &_stack_area;
}
/******************************
** Env_deprecated interface **
******************************/
Parent *parent() override { return &_parent_client; }
Cpu_session *cpu_session() override { return &_resources.cpu; }
Cpu_session_capability cpu_session_cap() override { return _resources.cpu.rpc_cap(); }
Pd_session *pd_session() override { return &_resources.pd; }
Pd_session_capability pd_session_cap() override { return _resources.pd.rpc_cap(); }
Region_map *rm_session() override { return &_resources.rm; }
};
#endif /* _INCLUDE__BASE__INTERNAL__PLATFORM_ENV_H_ */

View File

@ -1,45 +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 <base/internal/platform_env.h>
#include <base/internal/globals.h>
#include <base/connection.h>
#include <base/service.h>
namespace Genode {
/*
* Request pointer to static environment of the Genode application
*/
Env_deprecated *env_deprecated()
{
/*
* By placing the environment as static object here, we ensure that its
* constructor gets called when this function is used the first time.
*/
static Genode::Platform_env _env;
return &_env;
}
}
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();
}

View File

@ -1,20 +1,78 @@
/*
* \brief Platform dependant hook after binary ready
* \author Stefan Thoeni
* \date 2019-12-13
* \brief Environment initialization
* \author Norman Feske
* \author Christian Helmuth
* \date 2006-07-27
*/
/*
* Copyright (C) 2019 Genode Labs GmbH
* Copyright (C) 2019 gapfruit AG
* Copyright (C) 2006-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.
*/
/* base-internal includes */
#include <deprecated/env.h>
#include <base/internal/platform.h>
#include <base/internal/globals.h>
#include <base/connection.h>
#include <base/service.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;
}
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();
}
void Genode::init_platform()
{
static Genode::Platform platform;
init_log(platform.parent);
init_rpc_cap_alloc(platform.parent);
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() { }

View File

@ -21,7 +21,6 @@
#include <base/env.h>
#include <base/sleep.h>
#include <base/component.h>
#include <deprecated/env.h>
/* platform-specific local helper functions */
#include <base/internal/parent_cap.h>

View File

@ -93,13 +93,7 @@ extern "C" void init_main_thread()
/* do platform specific preparation */
prepare_init_main_thread();
/*
* Explicitly setup program environment at this point to ensure that its
* destructor won't be registered for the atexit routine.
*/
(void)env_deprecated();
init_log(*env_deprecated()->parent());
init_rpc_cap_alloc(*env_deprecated()->parent());
init_platform();
/* create a thread object for the main thread */
main_thread();