mirror of
https://github.com/genodelabs/genode.git
synced 2025-06-13 20:58:20 +00:00
Move server API concept to base framework
This commit introduces the new `Component` interface in the form of the headers base/component.h and base/entrypoint.h. The os/server.h API has become merely a compatibilty wrapper and will eventually be removed. The same holds true for os/signal_rpc_dispatcher.h. The mechanism has moved to base/signal.h and is now called 'Signal_handler'. Since the patch shuffles headers around, please do a 'make clean' in the build directory. Issue #1832
This commit is contained in:
committed by
Christian Helmuth
parent
4ac7127f89
commit
051e84c4b4
15
repos/base-linux/src/base/env/platform_env.cc
vendored
15
repos/base-linux/src/base/env/platform_env.cc
vendored
@ -76,8 +76,7 @@ Platform_env::Local_parent::session(Service_name const &service_name,
|
||||
if (size != ~0UL)
|
||||
size = align_addr(size, get_page_size_log2());
|
||||
|
||||
Rm_session_mmap *rm = new (env()->heap())
|
||||
Rm_session_mmap(true, size);
|
||||
Rm_session_mmap *rm = new (_alloc) Rm_session_mmap(true, size);
|
||||
|
||||
return Local_capability<Session>::local_cap(rm);
|
||||
}
|
||||
@ -106,8 +105,10 @@ void Platform_env::Local_parent::close(Session_capability session)
|
||||
|
||||
|
||||
Platform_env::Local_parent::Local_parent(Parent_capability parent_cap,
|
||||
Emergency_ram_reserve &reserve)
|
||||
: Expanding_parent_client(parent_cap, reserve)
|
||||
Emergency_ram_reserve &reserve,
|
||||
Allocator &alloc)
|
||||
:
|
||||
Expanding_parent_client(parent_cap, reserve), _alloc(alloc)
|
||||
{ }
|
||||
|
||||
|
||||
@ -150,7 +151,7 @@ static Parent_capability obtain_parent_cap()
|
||||
|
||||
Platform_env::Local_parent &Platform_env::_parent()
|
||||
{
|
||||
static Local_parent local_parent(obtain_parent_cap(), *this);
|
||||
static Local_parent local_parent(obtain_parent_cap(), *this, _heap);
|
||||
return local_parent;
|
||||
}
|
||||
|
||||
@ -161,8 +162,12 @@ Platform_env::Platform_env()
|
||||
static_cap_cast<Cpu_session>(_parent().session("Env::cpu_session", "")),
|
||||
static_cap_cast<Pd_session> (_parent().session("Env::pd_session", ""))),
|
||||
_heap(Platform_env_base::ram_session(), Platform_env_base::rm_session()),
|
||||
_stack_area(*parent(), *rm_session()),
|
||||
_emergency_ram_ds(ram_session()->alloc(_emergency_ram_size()))
|
||||
{
|
||||
env_stack_area_ram_session = ram_session();
|
||||
env_stack_area_rm_session = &_stack_area;
|
||||
|
||||
/* register TID and PID of the main thread at core */
|
||||
cpu_session()->thread_id(parent()->main_thread_cap(),
|
||||
lx_getpid(), lx_gettid());
|
||||
|
@ -28,6 +28,8 @@
|
||||
/* base-internal includes */
|
||||
#include <base/internal/platform_env.h>
|
||||
|
||||
namespace Genode { void init_stack_area(); }
|
||||
|
||||
namespace Genode {
|
||||
|
||||
/**
|
||||
@ -136,7 +138,15 @@ namespace Genode {
|
||||
|
||||
typedef Synchronized_ram_session<Ram_session_component> Core_ram_session;
|
||||
|
||||
Core_parent _core_parent;
|
||||
Core_parent _core_parent;
|
||||
|
||||
/*
|
||||
* Initialize the stack area before creating the first thread,
|
||||
* which happens to be the '_entrypoint'.
|
||||
*/
|
||||
bool _init_stack_area() { init_stack_area(); return true; }
|
||||
bool _stack_area_initialized = _init_stack_area();
|
||||
|
||||
Entrypoint _entrypoint;
|
||||
Core_ram_session _ram_session;
|
||||
|
||||
@ -153,6 +163,8 @@ namespace Genode {
|
||||
Heap _heap;
|
||||
Ram_session_capability const _ram_session_cap;
|
||||
|
||||
enum { SIGNAL_RAM_QUOTA = 1024*sizeof(long) };
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
@ -195,7 +207,7 @@ namespace Genode {
|
||||
Pd_session *pd_session() override { return &_pd_session_client; }
|
||||
Allocator *heap() override { return &_heap; }
|
||||
|
||||
Cpu_session_capability cpu_session_cap()
|
||||
Cpu_session_capability cpu_session_cap() override
|
||||
{
|
||||
PWRN("%s:%u not implemented", __FILE__, __LINE__);
|
||||
return Cpu_session_capability();
|
||||
|
@ -105,16 +105,16 @@ class Stack_area_ram_session : public Genode::Ram_session
|
||||
*/
|
||||
namespace Genode {
|
||||
|
||||
Rm_session *env_stack_area_rm_session()
|
||||
{
|
||||
static Stack_area_rm_session inst;
|
||||
return &inst;
|
||||
}
|
||||
Rm_session *env_stack_area_rm_session;
|
||||
Ram_session *env_stack_area_ram_session;
|
||||
|
||||
Ram_session *env_stack_area_ram_session()
|
||||
void init_stack_area()
|
||||
{
|
||||
static Stack_area_ram_session inst;
|
||||
return &inst;
|
||||
static Stack_area_rm_session rm_inst;
|
||||
env_stack_area_rm_session = &rm_inst;
|
||||
|
||||
static Stack_area_ram_session ram_inst;
|
||||
env_stack_area_ram_session = &ram_inst;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -314,10 +314,6 @@ namespace Genode {
|
||||
|
||||
private:
|
||||
|
||||
/*******************************
|
||||
** Platform-specific members **
|
||||
*******************************/
|
||||
|
||||
Ram_session_capability _ram_session_cap;
|
||||
Expanding_ram_session_client _ram_session_client;
|
||||
Cpu_session_capability _cpu_session_cap;
|
||||
@ -362,8 +358,8 @@ namespace Genode {
|
||||
*
|
||||
* Not supported on Linux.
|
||||
*/
|
||||
void reinit(Native_capability::Dst, long) { };
|
||||
void reinit_main_thread(Rm_session_capability &) { };
|
||||
void reinit(Native_capability::Dst, long) override { }
|
||||
void reinit_main_thread(Rm_session_capability &) override { }
|
||||
};
|
||||
|
||||
|
||||
@ -388,6 +384,10 @@ namespace Genode {
|
||||
*/
|
||||
class Local_parent : public Expanding_parent_client
|
||||
{
|
||||
private:
|
||||
|
||||
Allocator &_alloc;
|
||||
|
||||
public:
|
||||
|
||||
/**********************
|
||||
@ -407,7 +407,8 @@ namespace Genode {
|
||||
* services
|
||||
*/
|
||||
Local_parent(Parent_capability parent_cap,
|
||||
Emergency_ram_reserve &);
|
||||
Emergency_ram_reserve &,
|
||||
Allocator &);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -417,6 +418,13 @@ namespace Genode {
|
||||
|
||||
Heap _heap;
|
||||
|
||||
/*
|
||||
* The '_heap' must be initialized before the '_stack_area'
|
||||
* because the 'Local_parent' performs a dynamic memory allocation
|
||||
* due to the creation of the stack area's sub-RM session.
|
||||
*/
|
||||
Attached_stack_area _stack_area;
|
||||
|
||||
/*
|
||||
* Emergency RAM reserve
|
||||
*
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* \brief Supplemental code for hybrid Genode/Linux programs
|
||||
* \brief Supplemental code for hybrid Genode/Linux components
|
||||
* \author Norman Feske
|
||||
* \date 2011-09-02
|
||||
*/
|
||||
@ -13,6 +13,7 @@
|
||||
|
||||
/* Genode includes */
|
||||
#include <base/printf.h>
|
||||
#include <base/component.h>
|
||||
#include <linux_syscalls.h>
|
||||
#include <linux_cpu_session/linux_cpu_session.h>
|
||||
|
||||
@ -66,16 +67,45 @@ __attribute__((constructor(101))) void lx_hybrid_init()
|
||||
lx_sigaction(LX_SIGUSR1, empty_signal_handler);
|
||||
}
|
||||
|
||||
namespace Genode {
|
||||
extern void bootstrap_component();
|
||||
extern void call_global_static_constructors();
|
||||
|
||||
/*
|
||||
* Hook for intercepting the call of the 'Component::construct' method. By
|
||||
* hooking this function pointer in a library constructor, the libc is able
|
||||
* to create a task context for the component code. This context is
|
||||
* scheduled by the libc in a cooperative fashion, i.e. when the
|
||||
* component's entrypoint is activated.
|
||||
*/
|
||||
|
||||
extern void (*call_component_construct)(Genode::Environment &) __attribute__((weak));
|
||||
}
|
||||
|
||||
static void lx_hybrid_component_construct(Genode::Environment &env)
|
||||
{
|
||||
Component::construct(env);
|
||||
}
|
||||
|
||||
void (*Genode::call_component_construct)(Genode::Environment &) = &lx_hybrid_component_construct;
|
||||
|
||||
/*
|
||||
* Dummy symbols to let generic tests programs (i.e., 'test-config_args') link
|
||||
* successfully. Please note that such programs are not expected to work when
|
||||
* built as hybrid Linux/Genode programs because when using the glibc startup
|
||||
* code, we cannot manipulate argv prior executing main. However, by defining
|
||||
* these symbols, we prevent the automated build bot from stumbling over such
|
||||
* binaries.
|
||||
* Static constructors are handled by the Linux startup code - so implement
|
||||
* this as empty function.
|
||||
*/
|
||||
char **genode_argv = 0;
|
||||
int genode_argc = 1;
|
||||
void Genode::call_global_static_constructors() { }
|
||||
|
||||
/*
|
||||
* Hybrid components are not allowed to implement legacy main(). This enables
|
||||
* us to hook in and bootstrap components as usual.
|
||||
*/
|
||||
|
||||
int main()
|
||||
{
|
||||
Genode::bootstrap_component();
|
||||
|
||||
/* never reached */
|
||||
}
|
||||
|
||||
|
||||
/************
|
||||
|
@ -11,11 +11,16 @@
|
||||
* under the terms of the GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
|
||||
/* Genode includes */
|
||||
#include <base/component.h>
|
||||
#include <base/printf.h>
|
||||
|
||||
/* local includes */
|
||||
#include "testlib.h"
|
||||
|
||||
/* Linux includes */
|
||||
#include <stdlib.h>
|
||||
|
||||
using namespace Genode;
|
||||
|
||||
|
||||
@ -35,7 +40,18 @@ extern Testlib_testclass testlib_testobject;
|
||||
Testapp_testclass testapp_testobject;
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
static int exit_status;
|
||||
static void exit_on_suspended() { exit(exit_status); }
|
||||
|
||||
|
||||
Genode::size_t Component::stack_size() { return 16*1024*sizeof(long); }
|
||||
char const * Component::name() { return "lx_hybrid_ctors"; }
|
||||
|
||||
|
||||
/*
|
||||
* Component implements classical main function in construct.
|
||||
*/
|
||||
void Component::construct(Genode::Environment &env)
|
||||
{
|
||||
printf("--- lx_hybrid global static constructor test ---\n");
|
||||
|
||||
@ -47,6 +63,6 @@ int main(int argc, char *argv[])
|
||||
testapp_testobject.dummy();
|
||||
|
||||
printf("--- returning from main ---\n");
|
||||
|
||||
return 0;
|
||||
exit_status = 0;
|
||||
env.ep().schedule_suspend(exit_on_suspended, nullptr);
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
/* Genode includes */
|
||||
#include <base/component.h>
|
||||
#include <base/thread.h>
|
||||
#include <base/printf.h>
|
||||
|
||||
@ -12,6 +13,7 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
enum { STACK_SIZE = 4096 };
|
||||
|
||||
@ -40,7 +42,20 @@ struct Thread : Genode::Thread<STACK_SIZE>
|
||||
};
|
||||
|
||||
|
||||
int main(int, char **)
|
||||
static int exit_status;
|
||||
static void exit_on_suspended() { exit(exit_status); }
|
||||
|
||||
|
||||
Genode::size_t Component::stack_size() { return 16*1024*sizeof(long); }
|
||||
char const * Component::name() { return "lx_hybrid_errno"; }
|
||||
|
||||
|
||||
struct Unexpected_errno_change { };
|
||||
|
||||
/*
|
||||
* Component implements classical main function in construct.
|
||||
*/
|
||||
void Component::construct(Genode::Environment &env)
|
||||
{
|
||||
Genode::printf("--- thread-local errno test ---\n");
|
||||
|
||||
@ -60,9 +75,10 @@ int main(int, char **)
|
||||
|
||||
if (orig_errno != errno) {
|
||||
PERR("unexpected change of main thread's errno value");
|
||||
return -1;
|
||||
throw Unexpected_errno_change();
|
||||
}
|
||||
|
||||
Genode::printf("--- finished thread-local errno test ---\n");
|
||||
return 0;
|
||||
exit_status = 0;
|
||||
env.ep().schedule_suspend(exit_on_suspended, nullptr);
|
||||
}
|
||||
|
@ -11,27 +11,41 @@
|
||||
* under the terms of the GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
/* Genode includes */
|
||||
#include <base/component.h>
|
||||
#include <base/printf.h>
|
||||
|
||||
/* Linux includes */
|
||||
#include <stdlib.h>
|
||||
|
||||
using namespace Genode;
|
||||
|
||||
|
||||
class Test_exception { };
|
||||
|
||||
/**
|
||||
* Main program
|
||||
static int exit_status;
|
||||
static void exit_on_suspended() { exit(exit_status); }
|
||||
|
||||
|
||||
Genode::size_t Component::stack_size() { return 16*1024*sizeof(long); }
|
||||
char const * Component::name() { return "lx_hybrid_exception"; }
|
||||
|
||||
|
||||
/*
|
||||
* Component implements classical main function in construct.
|
||||
*/
|
||||
int main(int, char **)
|
||||
void Component::construct(Genode::Environment &env)
|
||||
{
|
||||
printf("--- lx_hybrid exception test ---\n");
|
||||
|
||||
try {
|
||||
printf("Throwing Test_exception\n");
|
||||
throw Test_exception();
|
||||
} catch(Test_exception) {
|
||||
} catch (Test_exception) {
|
||||
printf("Caught Test_exception\n");
|
||||
}
|
||||
|
||||
printf("--- returning from main ---\n");
|
||||
|
||||
return 0;
|
||||
exit_status = 0;
|
||||
env.ep().schedule_suspend(exit_on_suspended, nullptr);
|
||||
}
|
||||
|
@ -12,11 +12,14 @@
|
||||
*/
|
||||
|
||||
/* Genode includes */
|
||||
#include <base/component.h>
|
||||
#include <base/thread.h>
|
||||
#include <base/printf.h>
|
||||
|
||||
/* libc includes */
|
||||
#include <pthread.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
|
||||
static Genode::Lock *main_wait_lock()
|
||||
@ -46,7 +49,18 @@ static void *pthread_entry(void *)
|
||||
}
|
||||
|
||||
|
||||
int main(int, char **)
|
||||
static int exit_status;
|
||||
static void exit_on_suspended() { exit(exit_status); }
|
||||
|
||||
|
||||
Genode::size_t Component::stack_size() { return 16*1024*sizeof(long); }
|
||||
char const * Component::name() { return "lx_hybrid_pthread_ipc"; }
|
||||
|
||||
|
||||
/*
|
||||
* Component implements classical main function in construct.
|
||||
*/
|
||||
void Component::construct(Genode::Environment &env)
|
||||
{
|
||||
Genode::printf("--- pthread IPC test ---\n");
|
||||
|
||||
@ -58,5 +72,6 @@ int main(int, char **)
|
||||
main_wait_lock()->lock();
|
||||
|
||||
Genode::printf("--- finished pthread IPC test ---\n");
|
||||
return 0;
|
||||
exit_status = 0;
|
||||
env.ep().schedule_suspend(exit_on_suspended, nullptr);
|
||||
}
|
||||
|
Reference in New Issue
Block a user