base: remove Env arg from init_exception_handling

By supplying only the parts of the Env that are actually relevant for
initializing the cxx heap, we avoid the need for the 'Env' interface.
The patch also moves the call of 'init_ldso_phdr' to the outside
of the cxx library because it does not belong there.

Issue #4784
This commit is contained in:
Norman Feske
2023-06-21 14:18:01 +02:00
parent 59ce64b638
commit 54cc70f9b1
6 changed files with 34 additions and 38 deletions

View File

@ -89,14 +89,20 @@ namespace Genode {
/* /*
* This function is normally provided by the cxx library, which is not * For lx_hybrid programs, C++ support is initialized by the startup code
* used for lx_hybrid programs. For lx_hybrid programs, the exception * provided by the host toolchain.
* handling is initialized by the host system's regular startup code.
*
* However, we conveniently use this function to get hold of the
* component's environment and initialize the default log output.
*/ */
void Genode::init_exception_handling(Env &env) void Genode::init_exception_handling(Ram_allocator &, Region_map &) { }
/*
* This function is normally provided by the dynamic linker, which is not used
* for lx_hybrid programs. For lx_hybrid programs.
*
* However, we conveniently use this function to get hold of the component's
* environment and initialize the default log output.
*/
void Genode::init_ldso_phdr(Env &env)
{ {
_env_ptr = &env; _env_ptr = &env;

View File

@ -28,11 +28,11 @@ namespace Genode {
void init_platform(); void init_platform();
void init_stack_area(); void init_stack_area();
void init_exception_handling(Env &); void init_exception_handling(Ram_allocator &, Region_map &);
void init_signal_transmitter(Env &); void init_signal_transmitter(Env &);
void init_signal_receiver(Pd_session &, Parent &); void init_signal_receiver(Pd_session &, Parent &);
void init_cap_slab(Pd_session &, Parent &); void init_cap_slab(Pd_session &, Parent &);
void init_cxx_heap(Env &); void init_cxx_heap(Ram_allocator &, Region_map &);
void init_cxx_guard(); void init_cxx_guard();
void init_ldso_phdr(Env &); void init_ldso_phdr(Env &);
void init_signal_thread(Env &); void init_signal_thread(Env &);

View File

@ -234,6 +234,18 @@ Genode::size_t Component::stack_size() __attribute__((weak));
Genode::size_t Component::stack_size() { return 64*1024; } Genode::size_t Component::stack_size() { return 64*1024; }
/**
* Init program headers of the dynamic linker
*
* The weak function is used for statically linked binaries. The
* dynamic linker provides an implementation that loads the program
* headers of the linker. This must be done before the first exception
* is thrown.
*/
void Genode::init_ldso_phdr(Env &) __attribute__((weak));
void Genode::init_ldso_phdr(Env &) { }
/* /*
* We need to execute the constructor of the main entrypoint from a * We need to execute the constructor of the main entrypoint from a
* class called 'Startup' as 'Startup' is a friend of 'Entrypoint'. * class called 'Startup' as 'Startup' is a friend of 'Entrypoint'.
@ -242,7 +254,8 @@ struct Genode::Startup
{ {
::Env env { ep }; ::Env env { ep };
bool const exception_handling = (init_exception_handling(env), true); bool const ldso_phdr = (init_ldso_phdr(env), true);
bool const exception_handling = (init_exception_handling(env.pd(), env.rm()), true);
bool const signal_receiver = (init_signal_receiver(env.pd(), env.parent()), true); bool const signal_receiver = (init_signal_receiver(env.pd(), env.parent()), true);
/* /*

View File

@ -51,11 +51,7 @@ extern "C" int dl_iterate_phdr(int (*) (void *, unsigned long, void *), void *)
return -1; } return -1; }
/* static void terminate_handler()
* Terminate handler
*/
void terminate_handler()
{ {
std::type_info *t = __cxxabiv1::__cxa_current_exception_type(); std::type_info *t = __cxxabiv1::__cxa_current_exception_type();
@ -74,25 +70,9 @@ void terminate_handler()
} }
/** void Genode::init_exception_handling(Ram_allocator &ram, Region_map &rm)
* Init program headers of the dynamic linker
*
* The weak function is used for statically linked binaries. The
* dynamic linker provides an implementation that loads the program
* headers of the linker. This must be done before the first exception
* is thrown.
*/
void Genode::init_ldso_phdr(Env &) __attribute__((weak));
void Genode::init_ldso_phdr(Env &) { }
/*
* Initialization
*/
void Genode::init_exception_handling(Env &env)
{ {
init_ldso_phdr(env); init_cxx_heap(ram, rm);
init_cxx_heap(env);
__register_frame(__eh_frame_start__); __register_frame(__eh_frame_start__);

View File

@ -15,7 +15,6 @@
*/ */
/* Genode includes */ /* Genode includes */
#include <base/env.h>
#include <base/heap.h> #include <base/heap.h>
#include <util/string.h> #include <util/string.h>
#include <util/reconstructible.h> #include <util/reconstructible.h>
@ -47,7 +46,7 @@ Heap &cxx_heap()
* '__cxa_allocate_exception', which, in turn, calls 'malloc'. The cxx library * '__cxa_allocate_exception', which, in turn, calls 'malloc'. The cxx library
* uses a local implementation of 'malloc' using a dedicated heap instance. * uses a local implementation of 'malloc' using a dedicated heap instance.
*/ */
void Genode::init_cxx_heap(Env &env) void Genode::init_cxx_heap(Ram_allocator &ram, Region_map &rm)
{ {
/* /*
* Exception frames are small. Hence, a small static backing store suffices * Exception frames are small. Hence, a small static backing store suffices
@ -56,7 +55,7 @@ void Genode::init_cxx_heap(Env &env)
*/ */
static char initial_block[1024*sizeof(long)]; static char initial_block[1024*sizeof(long)];
cxx_heap_ptr = unmanaged_singleton<Heap>(&env.ram(), &env.rm(), Heap::UNLIMITED, cxx_heap_ptr = unmanaged_singleton<Heap>(&ram, &rm, Heap::UNLIMITED,
initial_block, sizeof(initial_block)); initial_block, sizeof(initial_block));
} }

View File

@ -26,8 +26,6 @@ using namespace Genode;
addr_t init_main_thread_result; addr_t init_main_thread_result;
extern void init_exception_handling();
namespace Genode { extern Region_map * env_stack_area_region_map; } namespace Genode { extern Region_map * env_stack_area_region_map; }
void prepare_init_main_thread(); void prepare_init_main_thread();