From 3a378bb970186524da4d68d49a49802bb7e7bd17 Mon Sep 17 00:00:00 2001 From: Christian Prochaska Date: Mon, 11 May 2015 16:12:21 +0200 Subject: [PATCH] libc_noux: remove dependency on 'platform_env.h' Currently, libc_noux includes the 'base/src/base/env/platform_env.h' file to be able to reinitialize the environment using the 'Platform_env' interface. For base-linux, a special version of this file exists and the inclusion of the generic version in libc_noux causes GCC 4.9 to make wrong assumptions about the memory layout of the 'Env' object returned by 'Genode::env()'. This commit moves the reinitialization functions to the 'Env' interface to avoid the need to include the 'platform_env.h' file in libc_noux. Fixes #1510 --- repos/base-linux/src/base/env/platform_env.cc | 4 --- repos/base-linux/src/base/env/platform_env.h | 18 +++++------ repos/base/include/base/env.h | 30 +++++++++++++++++++ repos/base/src/base/env/platform_env.h | 22 ++------------ repos/ports/lib/mk/libc_noux.mk | 2 -- repos/ports/src/lib/libc_noux/plugin.cc | 6 ++-- 6 files changed, 42 insertions(+), 40 deletions(-) diff --git a/repos/base-linux/src/base/env/platform_env.cc b/repos/base-linux/src/base/env/platform_env.cc index 6cbfa50feb..ac0df83463 100644 --- a/repos/base-linux/src/base/env/platform_env.cc +++ b/repos/base-linux/src/base/env/platform_env.cc @@ -154,10 +154,6 @@ Platform_env::Local_parent &Platform_env::_parent() } -void Platform_env::reinit(Native_capability::Dst, long) { } -void Platform_env::reinit_main_thread(Rm_session_capability &) { } - - Platform_env::Platform_env() : Platform_env_base(static_cap_cast(_parent().session("Env::ram_session", "")), diff --git a/repos/base-linux/src/base/env/platform_env.h b/repos/base-linux/src/base/env/platform_env.h index b0d615bcf7..7d3dc045cd 100644 --- a/repos/base-linux/src/base/env/platform_env.h +++ b/repos/base-linux/src/base/env/platform_env.h @@ -353,6 +353,14 @@ namespace Genode { Linux_cpu_session *cpu_session() { return &_cpu_session_client; } Cpu_session_capability cpu_session_cap() { return _cpu_session_cap; } Pd_session *pd_session() { return &_pd_session_client; } + + /* + * Support functions for implementing fork on Noux. + * + * Not supported on Linux. + */ + void reinit(Native_capability::Dst, long) { }; + void reinit_main_thread(Rm_session_capability &) { }; }; @@ -431,16 +439,6 @@ namespace Genode { */ ~Platform_env() { _parent().exit(0); } - /* - * Support functions for implementing fork on Noux. - * - * Not supported on Linux. - * - * See the documentation in 'base/src/base/env/platform_env.h' - */ - void reinit(Native_capability::Dst, long); - void reinit_main_thread(Rm_session_capability &); - /************************************* ** Emergency_ram_reserve interface ** diff --git a/repos/base/include/base/env.h b/repos/base/include/base/env.h index 2f915ed9a9..29c9f201b8 100644 --- a/repos/base/include/base/env.h +++ b/repos/base/include/base/env.h @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -84,6 +85,35 @@ struct Genode::Env * Heap backed by the RAM session of the environment */ virtual Allocator *heap() = 0; + + /** + * Reload parent capability and reinitialize environment resources + * + * This function is solely used for implementing fork semantics. + * After forking a process, the new child process is executed + * within a copy of the address space of the forking process. + * Thereby, the new process inherits the original 'env' object of + * the forking process, which is meaningless in the context of the + * new process. By calling this function, the new process is able + * to reinitialize its 'env' with meaningful capabilities obtained + * via its updated parent capability. + * + * \noapi + */ + virtual void reinit(Native_capability::Dst, long) = 0; + + /** + * Reinitialize main-thread object + * + * \param context_area_rm new RM session of the context area + * + * This function is solely used for implementing fork semantics + * as provided by the Noux environment. + * + * \noapi + */ + virtual void reinit_main_thread(Rm_session_capability &) = 0; + }; diff --git a/repos/base/src/base/env/platform_env.h b/repos/base/src/base/env/platform_env.h index dcfa32ac93..867e06b4b9 100644 --- a/repos/base/src/base/env/platform_env.h +++ b/repos/base/src/base/env/platform_env.h @@ -114,28 +114,10 @@ class Genode::Platform_env : public Genode::Env, public Emergency_ram_reserve _emergency_ram_ds(_resources.ram.alloc(_emergency_ram_size())) { } - /** - * Reload parent capability and reinitialize environment resources - * - * This function is solely used for implementing fork semantics. - * After forking a process, the new child process is executed - * within a copy of the address space of the forking process. - * Thereby, the new process inherits the original 'env' object of - * the forking process, which is meaningless in the context of the - * new process. By calling this function, the new process is able - * to reinitialize its 'env' with meaningful capabilities obtained - * via its updated parent capability. + /* + * Support functions for implementing fork on Noux. */ void reinit(Native_capability::Dst, long); - - /** - * Reinitialize main-thread object - * - * \param context_area_rm new RM session of the context area - * - * This function is solely used for implementing fork semantics - * as provided by the Noux environment. - */ void reinit_main_thread(Rm_session_capability &); diff --git a/repos/ports/lib/mk/libc_noux.mk b/repos/ports/lib/mk/libc_noux.mk index 38c75a5a71..9b1806b8f5 100644 --- a/repos/ports/lib/mk/libc_noux.mk +++ b/repos/ports/lib/mk/libc_noux.mk @@ -4,8 +4,6 @@ LIBS += libc REP_INC_DIR += src/lib/libc -INC_DIR += $(BASE_DIR)/src/base/env/ - vpath %.cc $(REP_DIR)/src/lib/libc_noux SHARED_LIB = yes diff --git a/repos/ports/src/lib/libc_noux/plugin.cc b/repos/ports/src/lib/libc_noux/plugin.cc index 18d7df47c2..561cff81c4 100644 --- a/repos/ports/src/lib/libc_noux/plugin.cc +++ b/repos/ports/src/lib/libc_noux/plugin.cc @@ -20,7 +20,6 @@ #include #include #include -#include /* noux includes */ #include @@ -505,8 +504,7 @@ extern "C" void fork_trampoline() { /* reinitialize environment */ using namespace Genode; - Platform_env * const platform_env = dynamic_cast(env()); - platform_env->reinit(new_parent.dst, new_parent.local_name); + env()->reinit(new_parent.dst, new_parent.local_name); /* reinitialize standard-output connection */ stdout_reconnect(); @@ -520,7 +518,7 @@ extern "C" void fork_trampoline() /* reinitialize main-thread object which implies reinit of context area */ auto context_area_rm = noux_connection()->context_area_rm_session(); - platform_env->reinit_main_thread(context_area_rm); + env()->reinit_main_thread(context_area_rm); /* apply processor state that the forker had when he did the fork */ longjmp(fork_jmp_buf, 1);