mirror of
https://github.com/genodelabs/genode.git
synced 2025-06-18 15:18:20 +00:00
Move main bootstrap to platform-specific object
To prevent multiple execution of main-bootstrap, I moved the code to a statically initialized object. The reason for this change is that _main() is exeuted twice when starting dynamic binaries. Now, the object is part of the base-common library which is linked with ld.lib.so.
This commit is contained in:
@ -1,59 +0,0 @@
|
||||
/*
|
||||
* \brief Platform-specific helper functions for the _main() function
|
||||
* \author Christian Prochaska
|
||||
* \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.
|
||||
*/
|
||||
|
||||
#ifndef _PLATFORM___MAIN_HELPER_H_
|
||||
#define _PLATFORM___MAIN_HELPER_H_
|
||||
|
||||
#include <base/thread.h>
|
||||
|
||||
#include <linux_syscalls.h>
|
||||
|
||||
/*
|
||||
* 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))));
|
||||
|
||||
|
||||
static inline void main_thread_bootstrap()
|
||||
{
|
||||
using namespace Genode;
|
||||
|
||||
extern Genode::addr_t *__initial_sp;
|
||||
|
||||
/*
|
||||
* 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];
|
||||
|
||||
/* reserve context area */
|
||||
Genode::addr_t base = Native_config::context_area_virtual_base();
|
||||
Genode::size_t size = Native_config::context_area_virtual_size();
|
||||
if (lx_vm_reserve(base, size) != base)
|
||||
PERR("reservation of context area [%lx,%lx) failed",
|
||||
(unsigned long) base, (unsigned long) base + size);
|
||||
}
|
||||
|
||||
#endif /* _PLATFORM___MAIN_HELPER_H_ */
|
@ -13,7 +13,7 @@
|
||||
|
||||
#include <base/crt0.h>
|
||||
#include <base/printf.h>
|
||||
#include <_main_helper.h>
|
||||
#include <linux_syscalls.h>
|
||||
#include <linux_cpu_session/linux_cpu_session.h>
|
||||
|
||||
|
||||
|
71
base-linux/src/platform/main_bootstrap.cc
Normal file
71
base-linux/src/platform/main_bootstrap.cc
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* \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];
|
||||
|
||||
/*
|
||||
* Free context area preserved in linker script
|
||||
*/
|
||||
addr_t base = Native_config::context_area_virtual_base();
|
||||
Genode::size_t size = Native_config::context_area_virtual_size();
|
||||
int ret;
|
||||
if ((ret = lx_munmap((void *)base, size)) < 0)
|
||||
PERR("flushing of context area [%lx,%lx) failed (ret=%d)",
|
||||
(unsigned long) base, (unsigned long) base + size, ret);
|
||||
}
|
||||
} bootstrap;
|
||||
}
|
Reference in New Issue
Block a user