diff --git a/repos/gems/src/server/terminal_mux/main.cc b/repos/gems/src/server/terminal_mux/main.cc index 070a37e576..40a7bc96fe 100644 --- a/repos/gems/src/server/terminal_mux/main.cc +++ b/repos/gems/src/server/terminal_mux/main.cc @@ -13,12 +13,12 @@ /* Genode includes */ #include -#include -#include +#include #include +#include +#include #include #include -#include #include /* terminal includes */ @@ -349,7 +349,7 @@ class Terminal::Root_component : public Genode::Root_component(env.ep(), md_alloc), + Genode::Root_component(env.ep(), heap), _env(env), _ncurses(ncurses), - _session_manager(session_manager) + _session_manager(session_manager), + _heap(heap) { } }; @@ -664,17 +665,17 @@ struct Main { Genode::Env &env; - Genode::Sliced_heap sliced_heap { env.ram(), env.rm() }; + Libc::Allocator heap; Registry registry; - Ncurses ncurses; + Ncurses ncurses { heap }; Status_window status_window { ncurses }; Menu menu { ncurses, registry, status_window }; User_input user_input { ncurses }; Session_manager session_manager { ncurses, registry, status_window, menu }; - Terminal::Root_component root { env, sliced_heap, ncurses, session_manager }; + Terminal::Root_component root { env, heap, ncurses, session_manager }; Timer::Connection timer { env }; diff --git a/repos/gems/src/server/terminal_mux/ncurses.cc b/repos/gems/src/server/terminal_mux/ncurses.cc index 7e304a2f58..5ce8784728 100644 --- a/repos/gems/src/server/terminal_mux/ncurses.cc +++ b/repos/gems/src/server/terminal_mux/ncurses.cc @@ -6,7 +6,7 @@ /* Genode includes */ #include -#include +#include /* libc and ncurses includes */ #include @@ -68,13 +68,13 @@ void Ncurses::Window::horizontal_line(int line) Ncurses::Window *Ncurses::create_window(int x, int y, int w, int h) { - return new (Genode::env()->heap()) Ncurses::Window(x, y, w, h); + return new (_alloc) Ncurses::Window(x, y, w, h); } void Ncurses::destroy_window(Ncurses::Window *window) { - Genode::destroy(Genode::env()->heap(), window); + Genode::destroy(_alloc, window); } @@ -103,7 +103,7 @@ int Ncurses::read_character() } -Ncurses::Ncurses() +Ncurses::Ncurses(Genode::Allocator &alloc) : _alloc(alloc) { /* * Redirect stdio to terminal diff --git a/repos/gems/src/server/terminal_mux/ncurses_cxx.h b/repos/gems/src/server/terminal_mux/ncurses_cxx.h index b83e8ee95d..89ff819a4d 100644 --- a/repos/gems/src/server/terminal_mux/ncurses_cxx.h +++ b/repos/gems/src/server/terminal_mux/ncurses_cxx.h @@ -7,10 +7,14 @@ #ifndef _NCURSES_CXX_H_ #define _NCURSES_CXX_H_ +namespace Genode { class Allocator; } + class Ncurses { private: + Genode::Allocator &_alloc; + unsigned _columns; unsigned _lines; @@ -52,7 +56,7 @@ class Ncurses void do_update(); - Ncurses(); + Ncurses(Genode::Allocator &); void cursor_visible(bool); diff --git a/repos/libports/src/test/ldso/main.cc b/repos/libports/src/test/ldso/main.cc index 5066126c82..50b67b6eef 100644 --- a/repos/libports/src/test/ldso/main.cc +++ b/repos/libports/src/test/ldso/main.cc @@ -157,10 +157,11 @@ void test_dynamic_cast_call(Object_base *o) b->func(); } -static void test_dynamic_cast() +static void test_dynamic_cast(Genode::Allocator &heap) { - Object *o = new (Genode::env()->heap()) Object; + Object *o = new (heap) Object; test_dynamic_cast_call(o); + destroy(heap, o); } @@ -222,7 +223,7 @@ void Libc::Component::construct(Libc::Env &env) printf("Catch exceptions in program\n"); printf("---------------------------\n"); printf("exception in remote procedure call:\n"); - try { Rom_connection rom("unknown_file"); } + try { Rom_connection rom(env, "unknown_file"); } catch (Rom_connection::Rom_connection_failed) { printf("caught\n"); } printf("exception in program: "); @@ -250,7 +251,7 @@ void Libc::Component::construct(Libc::Env &env) printf("Dynamic cast\n"); printf("------------\n"); - test_dynamic_cast(); + test_dynamic_cast(heap); printf("\n"); printf("Shared-object API\n"); diff --git a/repos/libports/src/test/moon/main.cc b/repos/libports/src/test/moon/main.cc index db014b34bb..694c29f4c7 100644 --- a/repos/libports/src/test/moon/main.cc +++ b/repos/libports/src/test/moon/main.cc @@ -12,8 +12,8 @@ */ /* Genode includes */ -#include #include +#include #include /* Lua includes */ @@ -22,11 +22,15 @@ #include -static Timer::Session & timer_session() -{ - static Timer::Connection timer; +namespace Moon { - return timer; + struct Main; + struct Env + { + Timer::Session &timer; + Genode::Ram_session &ram; + }; + Env *env; } @@ -42,7 +46,7 @@ static int l_msleep(lua_State *lua) } luaL_checknumber(lua, 1); - timer_session().msleep(lua_tonumber(lua, 1)); + Moon::env->timer.msleep(lua_tonumber(lua, 1)); return 0; } @@ -59,7 +63,7 @@ static int l_quota(lua_State *lua) return 0; } - lua_pushnumber(lua, Genode::env()->ram_session()->quota()); + lua_pushnumber(lua, Moon::env->ram.quota()); return 1; } @@ -116,18 +120,32 @@ static char const *exec_string = ; -int main() +struct Moon::Main { - lua_State *lua = lua_open(); + Libc::Env &_env; - /* initialize libs */ - luaopen_base(lua); + Timer::Connection _timer { _env }; - /* register Genode Lua library */ - luaL_register(lua, "Genode", l_genode); + Moon::Env _moon_env { _timer, _env.ram() }; - if (luaL_dostring(lua, exec_string) != 0) - Genode::log(lua_tostring(lua, -1)); + Main(Libc::Env &env) : _env(env) + { + Moon::env = &_moon_env; - lua_close(lua); -} + lua_State *lua = lua_open(); + + /* initialize libs */ + luaopen_base(lua); + + /* register Genode Lua library */ + luaL_register(lua, "Genode", l_genode); + + if (luaL_dostring(lua, exec_string) != 0) + Genode::log(lua_tostring(lua, -1)); + + lua_close(lua); + } +}; + + +void Libc::Component::construct(Libc::Env &env) { static Moon::Main instance(env); } diff --git a/repos/libports/src/test/moon/target.mk b/repos/libports/src/test/moon/target.mk index 530b0753b2..c76682a65e 100644 --- a/repos/libports/src/test/moon/target.mk +++ b/repos/libports/src/test/moon/target.mk @@ -1,3 +1,3 @@ TARGET = test-moon -LIBS = luacxx posix +LIBS = luacxx libc SRC_CC = main.cc diff --git a/repos/os/src/test/fault_detection/main.cc b/repos/os/src/test/fault_detection/main.cc index 08197438bf..c2f3e152c3 100644 --- a/repos/os/src/test/fault_detection/main.cc +++ b/repos/os/src/test/fault_detection/main.cc @@ -211,7 +211,8 @@ struct Faulting_loader_grand_child_test /* import config into loader session */ { - Attached_dataspace ds(loader->alloc_rom_module("config", config_size())); + Attached_dataspace ds(env.rm(), + loader->alloc_rom_module("config", config_size())); memcpy(ds.local_addr(), config(), config_size()); loader->commit_rom_module("config"); } diff --git a/repos/os/src/test/framebuffer/main.cc b/repos/os/src/test/framebuffer/main.cc index 2f3ae08b56..ad64e9fde7 100644 --- a/repos/os/src/test/framebuffer/main.cc +++ b/repos/os/src/test/framebuffer/main.cc @@ -16,7 +16,6 @@ /* Genode includes */ #include #include -#include #include #include #include @@ -38,8 +37,10 @@ class Test_environment enum State { STRIPES, ALL_BLUE, ALL_GREEN, ALL_RED, COLORED }; - Framebuffer::Connection _fb; + Genode::Env &_env; + Framebuffer::Mode _mode; + Framebuffer::Connection _fb { _env, _mode }; Ds _fb_ds; Genode::Signal_handler _mode_sigh; Genode::Signal_handler _sync_sigh; @@ -61,9 +62,11 @@ class Test_environment public: - Test_environment(Genode::Entrypoint &ep) - : _mode_sigh(ep, *this, &Test_environment::_mode_handle), - _sync_sigh(ep, *this, &Test_environment::_sync_handle) + Test_environment(Genode::Env &env) + : + _env(env), + _mode_sigh(_env.ep(), *this, &Test_environment::_mode_handle), + _sync_sigh(_env.ep(), *this, &Test_environment::_sync_handle) { _fb.mode_sigh(_mode_sigh); _fb.sync_sigh(_sync_sigh); @@ -137,7 +140,7 @@ void Test_environment::_mode_handle() if (_fb_ds.is_constructed()) _fb_ds.destruct(); - _fb_ds.construct(_fb.dataspace()); + _fb_ds.construct(_env.rm(), _fb.dataspace()); Genode::log("framebuffer is ", _mode); @@ -152,8 +155,6 @@ void Test_environment::_mode_handle() void Component::construct(Genode::Env &env) { - using namespace Genode; - - Genode::log("--- Test framebuffer ---\n"); - static Test_environment te(env.ep()); + Genode::log("--- Test framebuffer ---"); + static Test_environment te(env); }