diff --git a/repos/base-fiasco/lib/mk/base-fiasco.mk b/repos/base-fiasco/lib/mk/base-fiasco.mk
index a0a328daa7..a98ceba70c 100644
--- a/repos/base-fiasco/lib/mk/base-fiasco.mk
+++ b/repos/base-fiasco/lib/mk/base-fiasco.mk
@@ -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
diff --git a/repos/base-foc/lib/mk/base-foc-common.inc b/repos/base-foc/lib/mk/base-foc-common.inc
index f40551ea65..e573f5d243 100644
--- a/repos/base-foc/lib/mk/base-foc-common.inc
+++ b/repos/base-foc/lib/mk/base-foc-common.inc
@@ -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
diff --git a/repos/base-hw/lib/mk/base-hw.inc b/repos/base-hw/lib/mk/base-hw.inc
index ed1b684450..cb71081d82 100644
--- a/repos/base-hw/lib/mk/base-hw.inc
+++ b/repos/base-hw/lib/mk/base-hw.inc
@@ -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
diff --git a/repos/base-hw/lib/mk/bootstrap-hw.inc b/repos/base-hw/lib/mk/bootstrap-hw.inc
index 54dff1e354..9fbc95b2b5 100644
--- a/repos/base-hw/lib/mk/bootstrap-hw.inc
+++ b/repos/base-hw/lib/mk/bootstrap-hw.inc
@@ -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
diff --git a/repos/base-hw/src/bootstrap/env.cc b/repos/base-hw/src/bootstrap/env.cc
deleted file mode 100644
index 64ab81b271..0000000000
--- a/repos/base-hw/src/bootstrap/env.cc
+++ /dev/null
@@ -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
-#include
-#include
-
-Genode::Env_deprecated * Genode::env_deprecated()
-{
- assert(false);
- return nullptr;
-}
diff --git a/repos/base-hw/src/lib/base/env_deprecated.cc b/repos/base-hw/src/lib/base/platform.cc
similarity index 53%
rename from repos/base-hw/src/lib/base/env_deprecated.cc
rename to repos/base-hw/src/lib/base/platform.cc
index 964beeb5f6..51cc656ab2 100644
--- a/repos/base-hw/src/lib/base/env_deprecated.cc
+++ b/repos/base-hw/src/lib/base/platform.cc
@@ -12,7 +12,8 @@
* under the terms of the GNU Affero General Public License version 3.
*/
-#include
+#include
+#include
#include
#include
#include
@@ -20,20 +21,35 @@
#include
-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;
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(
diff --git a/repos/base-linux/lib/mk/base-linux.inc b/repos/base-linux/lib/mk/base-linux.inc
index 55fc01c046..acecf0a16d 100644
--- a/repos/base-linux/lib/mk/base-linux.inc
+++ b/repos/base-linux/lib/mk/base-linux.inc
@@ -5,6 +5,6 @@
include $(BASE_DIR)/lib/mk/base.inc
-SRC_CC += platform_env.cc
+SRC_CC += platform.cc
LIBS += syscall-linux
diff --git a/repos/base-linux/lib/mk/base-linux.mk b/repos/base-linux/lib/mk/base-linux.mk
index abfa2aebda..b8fe14fcd0 100644
--- a/repos/base-linux/lib/mk/base-linux.mk
+++ b/repos/base-linux/lib/mk/base-linux.mk
@@ -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
diff --git a/repos/base-linux/src/core/platform.cc b/repos/base-linux/src/core/platform.cc
index 4dd5fa4181..6ca52b1264 100644
--- a/repos/base-linux/src/core/platform.cc
+++ b/repos/base-linux/src/core/platform.cc
@@ -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 ds_cap)
{
diff --git a/repos/base-linux/src/include/base/internal/platform.h b/repos/base-linux/src/include/base/internal/platform.h
new file mode 100644
index 0000000000..4e515a3145
--- /dev/null
+++ b/repos/base-linux/src/include/base/internal/platform.h
@@ -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-internal includes */
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+namespace Genode { struct Platform; }
+
+
+struct Genode::Platform
+{
+ Region_map_mmap rm { false };
+
+ Local_parent parent;
+
+ Pd_session_capability pd_cap =
+ static_cap_cast(parent.session_cap(Parent::Env::pd()));
+
+ Cpu_session_capability cpu_cap =
+ static_cap_cast(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_ */
diff --git a/repos/base-linux/src/include/base/internal/platform_env.h b/repos/base-linux/src/include/base/internal/platform_env.h
deleted file mode 100644
index 455177e4c7..0000000000
--- a/repos/base-linux/src/include/base/internal/platform_env.h
+++ /dev/null
@@ -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-internal includes */
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include
-
-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_ */
diff --git a/repos/base-linux/src/lib/base/attach_stack_area.cc b/repos/base-linux/src/lib/base/attach_stack_area.cc
index 8f75ab9c3e..29864ad2da 100644
--- a/repos/base-linux/src/lib/base/attach_stack_area.cc
+++ b/repos/base-linux/src/lib/base/attach_stack_area.cc
@@ -16,14 +16,14 @@
*/
/* base-internal includes */
-#include
+#include
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());
}
diff --git a/repos/base-linux/src/lib/base/child_process.cc b/repos/base-linux/src/lib/base/child_process.cc
index 5f80bc68b9..520c9be5d0 100644
--- a/repos/base-linux/src/lib/base/child_process.cc
+++ b/repos/base-linux/src/lib/base/child_process.cc
@@ -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,
diff --git a/repos/base-linux/src/lib/base/platform.cc b/repos/base-linux/src/lib/base/platform.cc
index 70d15d7ff2..55187c150e 100644
--- a/repos/base-linux/src/lib/base/platform.cc
+++ b/repos/base-linux/src/lib/base/platform.cc
@@ -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
+#include
+#include
+#include
+#include
/* base-internal includes */
+#include
+#include
#include
-#include
+#include
+#include
+
+#include
+
+using namespace Genode;
+
+
+/*********************************
+ ** Support for Rm_session_mmap **
+ *********************************/
+
+size_t Region_map_mmap::_dataspace_size(Dataspace_capability ds)
+{
+ if (local(ds))
+ return Local_capability::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 =
+ static_cap_cast(local_session.local_session_cap());
+ destroy(_alloc, Local_capability::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(id, close_local_fn);
+ return CLOSE_DONE;
+ }
+ catch (Id_space::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_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(&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
#include /* prctl */
#include /* 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();
}
}
-
diff --git a/repos/base-linux/src/lib/base/platform_env.cc b/repos/base-linux/src/lib/base/platform_env.cc
deleted file mode 100644
index da038c1905..0000000000
--- a/repos/base-linux/src/lib/base/platform_env.cc
+++ /dev/null
@@ -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
-#include
-#include
-#include
-
-/* base-internal includes */
-#include
-#include
-#include
-#include
-#include
-
-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::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 =
- static_cap_cast(local_session.local_session_cap());
- destroy(_alloc, Local_capability::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(id, close_local_fn);
- return CLOSE_DONE;
- }
- catch (Id_space::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_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(_parent().session_cap(Parent::Env::cpu())),
- static_cap_cast (_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());
-}
-
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 8cf10983bd..e201eb9b5f 100644
--- a/repos/base-linux/src/lib/lx_hybrid/lx_hybrid.cc
+++ b/repos/base-linux/src/lib/lx_hybrid/lx_hybrid.cc
@@ -20,7 +20,7 @@
/* base-internal includes */
#include
#include
-#include
+#include
/**
@@ -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
diff --git a/repos/base-nova/lib/mk/base-nova.mk b/repos/base-nova/lib/mk/base-nova.mk
index 3c8b8a4e53..0040696ef0 100644
--- a/repos/base-nova/lib/mk/base-nova.mk
+++ b/repos/base-nova/lib/mk/base-nova.mk
@@ -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
diff --git a/repos/base-okl4/lib/mk/base-okl4.mk b/repos/base-okl4/lib/mk/base-okl4.mk
index 0fa9cbb360..db7b34ae90 100644
--- a/repos/base-okl4/lib/mk/base-okl4.mk
+++ b/repos/base-okl4/lib/mk/base-okl4.mk
@@ -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
diff --git a/repos/base-pistachio/lib/mk/base-pistachio.mk b/repos/base-pistachio/lib/mk/base-pistachio.mk
index d77f60bb26..90c7de5c7e 100644
--- a/repos/base-pistachio/lib/mk/base-pistachio.mk
+++ b/repos/base-pistachio/lib/mk/base-pistachio.mk
@@ -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
diff --git a/repos/base-sel4/lib/mk/base-sel4-common.inc b/repos/base-sel4/lib/mk/base-sel4-common.inc
index 70171a9b49..a6606a746f 100644
--- a/repos/base-sel4/lib/mk/base-sel4-common.inc
+++ b/repos/base-sel4/lib/mk/base-sel4-common.inc
@@ -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
diff --git a/repos/base/lib/mk/base.inc b/repos/base/lib/mk/base.inc
index c72150c8f9..75370107db 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 += 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
diff --git a/repos/base/src/core/main.cc b/repos/base/src/core/main.cc
index 1307e2e189..65ff6ec488 100644
--- a/repos/base/src/core/main.cc
+++ b/repos/base/src/core/main.cc
@@ -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 &) { }
diff --git a/repos/base/src/include/base/internal/globals.h b/repos/base/src/include/base/internal/globals.h
index 78d3c347db..e5133de691 100644
--- a/repos/base/src/include/base/internal/globals.h
+++ b/repos/base/src/include/base/internal/globals.h
@@ -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 &);
diff --git a/repos/base/src/include/base/internal/platform.h b/repos/base/src/include/base/internal/platform.h
new file mode 100644
index 0000000000..f39e636313
--- /dev/null
+++ b/repos/base/src/include/base/internal/platform.h
@@ -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
+#include
+#include
+#include
+#include
+#include
+
+namespace Genode { class Platform; }
+
+
+struct Genode::Platform : Noncopyable
+{
+ Expanding_parent_client parent { Genode::parent_cap() };
+
+ template Capability _request(Parent::Client::Id id)
+ {
+ return static_cap_cast(parent.session_cap(id));
+ }
+
+ Expanding_pd_session_client pd {
+ parent, _request(Parent::Env::pd()) };
+
+ Expanding_cpu_session_client cpu {
+ parent, _request(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_ */
diff --git a/repos/base/src/include/base/internal/platform_env.h b/repos/base/src/include/base/internal/platform_env.h
deleted file mode 100644
index a4919ff640..0000000000
--- a/repos/base/src/include/base/internal/platform_env.h
+++ /dev/null
@@ -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-' 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
-#include
-#include
-#include
-
-/* base-internal includes */
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-
-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
- Capability request(Parent &parent, Parent::Client::Id id)
- {
- return static_cap_cast(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 (parent, Parent::Env::pd())),
- cpu(parent, request(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_ */
diff --git a/repos/base/src/lib/base/env_deprecated.cc b/repos/base/src/lib/base/env_deprecated.cc
deleted file mode 100644
index 16f734b390..0000000000
--- a/repos/base/src/lib/base/env_deprecated.cc
+++ /dev/null
@@ -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
-#include
-#include
-#include
-
-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(&env.parent())->init_fallback_signal_handling();
-}
diff --git a/repos/base/src/lib/base/platform.cc b/repos/base/src/lib/base/platform.cc
index 82e843931b..90203ef8b6 100644
--- a/repos/base/src/lib/base/platform.cc
+++ b/repos/base/src/lib/base/platform.cc
@@ -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
+#include
#include
+#include
+#include
+
+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(&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() { }
-
diff --git a/repos/base/src/lib/startup/_main.cc b/repos/base/src/lib/startup/_main.cc
index 3e8657d0c0..ca6baf6a5c 100644
--- a/repos/base/src/lib/startup/_main.cc
+++ b/repos/base/src/lib/startup/_main.cc
@@ -21,7 +21,6 @@
#include
#include
#include
-#include
/* platform-specific local helper functions */
#include
diff --git a/repos/base/src/lib/startup/init_main_thread.cc b/repos/base/src/lib/startup/init_main_thread.cc
index a8aa05a09c..4de48cc3fa 100644
--- a/repos/base/src/lib/startup/init_main_thread.cc
+++ b/repos/base/src/lib/startup/init_main_thread.cc
@@ -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();