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
This commit is contained in:
Christian Prochaska 2015-05-11 16:12:21 +02:00 committed by Christian Helmuth
parent 1207a4cecd
commit 3a378bb970
6 changed files with 42 additions and 40 deletions

View File

@ -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::Platform_env()
: :
Platform_env_base(static_cap_cast<Ram_session>(_parent().session("Env::ram_session", "")), Platform_env_base(static_cap_cast<Ram_session>(_parent().session("Env::ram_session", "")),

View File

@ -353,6 +353,14 @@ namespace Genode {
Linux_cpu_session *cpu_session() { return &_cpu_session_client; } Linux_cpu_session *cpu_session() { return &_cpu_session_client; }
Cpu_session_capability cpu_session_cap() { return _cpu_session_cap; } Cpu_session_capability cpu_session_cap() { return _cpu_session_cap; }
Pd_session *pd_session() { return &_pd_session_client; } 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); } ~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 ** ** Emergency_ram_reserve interface **

View File

@ -16,6 +16,7 @@
#include <parent/capability.h> #include <parent/capability.h>
#include <parent/parent.h> #include <parent/parent.h>
#include <rm_session/capability.h>
#include <rm_session/rm_session.h> #include <rm_session/rm_session.h>
#include <ram_session/ram_session.h> #include <ram_session/ram_session.h>
#include <cpu_session/cpu_session.h> #include <cpu_session/cpu_session.h>
@ -84,6 +85,35 @@ struct Genode::Env
* Heap backed by the RAM session of the environment * Heap backed by the RAM session of the environment
*/ */
virtual Allocator *heap() = 0; 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;
}; };

View File

@ -114,28 +114,10 @@ class Genode::Platform_env : public Genode::Env, public Emergency_ram_reserve
_emergency_ram_ds(_resources.ram.alloc(_emergency_ram_size())) _emergency_ram_ds(_resources.ram.alloc(_emergency_ram_size()))
{ } { }
/** /*
* Reload parent capability and reinitialize environment resources * Support functions for implementing fork on Noux.
*
* 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.
*/ */
void reinit(Native_capability::Dst, long); 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 &); void reinit_main_thread(Rm_session_capability &);

View File

@ -4,8 +4,6 @@ LIBS += libc
REP_INC_DIR += src/lib/libc REP_INC_DIR += src/lib/libc
INC_DIR += $(BASE_DIR)/src/base/env/
vpath %.cc $(REP_DIR)/src/lib/libc_noux vpath %.cc $(REP_DIR)/src/lib/libc_noux
SHARED_LIB = yes SHARED_LIB = yes

View File

@ -20,7 +20,6 @@
#include <rom_session/connection.h> #include <rom_session/connection.h>
#include <base/sleep.h> #include <base/sleep.h>
#include <dataspace/client.h> #include <dataspace/client.h>
#include <platform_env.h>
/* noux includes */ /* noux includes */
#include <noux_session/connection.h> #include <noux_session/connection.h>
@ -505,8 +504,7 @@ extern "C" void fork_trampoline()
{ {
/* reinitialize environment */ /* reinitialize environment */
using namespace Genode; using namespace Genode;
Platform_env * const platform_env = dynamic_cast<Platform_env *>(env()); env()->reinit(new_parent.dst, new_parent.local_name);
platform_env->reinit(new_parent.dst, new_parent.local_name);
/* reinitialize standard-output connection */ /* reinitialize standard-output connection */
stdout_reconnect(); stdout_reconnect();
@ -520,7 +518,7 @@ extern "C" void fork_trampoline()
/* reinitialize main-thread object which implies reinit of context area */ /* reinitialize main-thread object which implies reinit of context area */
auto context_area_rm = noux_connection()->context_area_rm_session(); 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 */ /* apply processor state that the forker had when he did the fork */
longjmp(fork_jmp_buf, 1); longjmp(fork_jmp_buf, 1);