base: setup thread object for main thread in CRT0

For a main thread a thread object is created by the CRT0 before _main gets
called so that _main can already run in a generic environment that, e.g.,
catches stack overflows as a page-fault instead of corrupting the BSS.
Additionally dynamic programs have only one CRT0 - the one of the LDSO -
which does the initialization for both LDSO and program.

ref #989
This commit is contained in:
Martin Stein
2014-01-28 14:30:36 +01:00
committed by Norman Feske
parent ba8e61653f
commit 0b64328944
80 changed files with 1299 additions and 823 deletions

View File

@ -154,6 +154,10 @@ 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<Ram_session>(_parent().session("Env::ram_session", "")),

View File

@ -432,13 +432,15 @@ namespace Genode {
*/
~Platform_env() { _parent().exit(0); }
/**
* Reload parent capability and reinitialize environment resources
/*
* Support functions for implementing fork on Noux.
*
* Not supported on Linux.
*
* See the documentation in 'base/src/base/env/platform_env.h'
*/
void reload_parent_cap(Capability<Parent>::Dst, long)
{
/* not supported on Linux */
}
void reinit(Native_capability::Dst, long);
void reinit_main_thread(Rm_session_capability &);
/*************************************

View File

@ -0,0 +1,49 @@
/*
* \brief Thread-environment support common to all programs
* \author Martin Stein
* \date 2013-12-13
*/
/*
* Copyright (C) 2013 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
/* Genode includes */
#include <base/stdint.h>
#include <base/env.h>
using namespace Genode;
extern addr_t * __initial_sp;
/*
* Define 'lx_environ' pointer.
*/
char **lx_environ;
/**
* Natively aligned memory location used in the lock implementation
*/
int main_thread_futex_counter __attribute__((aligned(sizeof(addr_t))));
/*****************************
** Startup library support **
*****************************/
void prepare_init_main_thread()
{
/*
* Initialize the 'lx_environ' pointer
*
* environ = &argv[argc + 1]
* __initial_sp[0] = argc (always 1 in Genode)
* __initial_sp[1] = argv[0]
* __initial_sp[2] = NULL
* __initial_sp[3] = environ
*/
lx_environ = (char**)&__initial_sp[3];
}

View File

@ -1,6 +1,7 @@
/*
* \brief Implementation of the Thread API via Linux threads
* \author Norman Feske
* \author Martin Stein
* \date 2006-06-13
*/
@ -23,6 +24,7 @@
using namespace Genode;
extern int main_thread_futex_counter;
static void empty_signal_handler(int) { }
@ -67,9 +69,16 @@ void Thread_base::_thread_start()
}
void Thread_base::_init_platform_thread()
void Thread_base::_init_platform_thread(Type type)
{
_thread_cap = env()->cpu_session()->create_thread(_context->name);
/* for normal threads create an object at the CPU session */
if (type == NORMAL) {
_thread_cap = env()->cpu_session()->create_thread(_context->name);
return;
}
/* adjust initial object state for main threads */
tid().futex_counter = main_thread_futex_counter;
_thread_cap = env()->parent()->main_thread_cap();
}

View File

@ -46,7 +46,7 @@ void Thread_base::_thread_start()
}
void Thread_base::_init_platform_thread() { }
void Thread_base::_init_platform_thread(Type) { }
void Thread_base::_deinit_platform_thread() { }

View File

@ -401,7 +401,7 @@ void Thread_base::join()
}
Thread_base::Thread_base(const char *name, size_t stack_size)
Thread_base::Thread_base(const char *name, size_t stack_size, Type)
{
_tid.meta_data = new (env()->heap()) Thread_meta_data_created(this);

View File

@ -1,61 +0,0 @@
/*
* \brief Platform-specific helper functions for the _main() function
* \author Christian Prochaska
* \author Christian Helmuth
* \date 2009-08-05
*/
/*
* Copyright (C) 2009-2013 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
#include <base/thread.h>
#include <linux_syscalls.h>
namespace Genode { void platform_main_bootstrap(); }
/*
* Define 'lx_environ' pointer.
*/
char **lx_environ;
/**
* Natively aligned memory location used in the lock implementation
*/
int main_thread_futex_counter __attribute__((aligned(sizeof(Genode::addr_t))));
/**
* Initial value of SP register (in crt0)
*/
extern Genode::addr_t *__initial_sp;
/**
* Platform-specific bootstrap
*/
void Genode::platform_main_bootstrap()
{
static struct Bootstrap
{
Bootstrap()
{
/*
* Initialize the 'lx_environ' pointer
*
* environ = &argv[argc + 1]
* __initial_sp[0] = argc (always 1 in Genode)
* __initial_sp[1] = argv[0]
* __initial_sp[2] = NULL
* __initial_sp[3] = environ
*/
lx_environ = (char**)&__initial_sp[3];
}
} bootstrap;
}