From a27cbfd3715b15cb80c3876f25b19226a94b7e02 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Fri, 7 Oct 2016 15:36:23 +0200 Subject: [PATCH] os: make report_rom/rom_module.h better reusable --- repos/os/include/report_rom/rom_module.h | 20 ++++++++++++++----- repos/os/src/server/clipboard/main.cc | 7 ++++--- repos/os/src/server/report_rom/main.cc | 2 +- repos/os/src/server/report_rom/rom_registry.h | 9 ++++++--- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/repos/os/include/report_rom/rom_module.h b/repos/os/include/report_rom/rom_module.h index 1ba713ae96..7ee6aa7010 100644 --- a/repos/os/include/report_rom/rom_module.h +++ b/repos/os/include/report_rom/rom_module.h @@ -117,6 +117,9 @@ struct Rom::Module : Module_list::Element, Readable_module Name _name; + Genode::Ram_session &_ram; + Genode::Region_map &_rm; + Read_policy const &_read_policy; Write_policy const &_write_policy; @@ -152,17 +155,24 @@ struct Rom::Module : Module_list::Element, Readable_module /** * Constructor * + * \param ram RAM session from which to allocate the module's + * backing store + * \param rm region map of the local address space, needed + * to access the allocated backing store * \param name module name * \param read_policy policy hook function that is evaluated each * time when the module content is obtained * \param write_policy policy hook function that is evaluated each * time when the module content is changed */ - Module(Name const &name, - Read_policy const &read_policy, - Write_policy const &write_policy) + Module(Genode::Ram_session &ram, + Genode::Region_map &rm, + Name const &name, + Read_policy const &read_policy, + Write_policy const &write_policy) : - _name(name), _read_policy(read_policy), _write_policy(write_policy) + _name(name), _ram(ram), _rm(rm), + _read_policy(read_policy), _write_policy(write_policy) { } @@ -240,7 +250,7 @@ struct Rom::Module : Module_list::Element, Readable_module * append a zero termination to textual reports. */ if (!_ds.constructed() || _ds->size() < (src_len + 1)) - _ds.construct(Genode::env()->ram_session(), (src_len + 1)); + _ds.construct(_ram, _rm, (src_len + 1)); /* copy content into backing store */ _size = src_len; diff --git a/repos/os/src/server/clipboard/main.cc b/repos/os/src/server/clipboard/main.cc index 82990923df..e46acde9b8 100644 --- a/repos/os/src/server/clipboard/main.cc +++ b/repos/os/src/server/clipboard/main.cc @@ -59,10 +59,11 @@ struct Rom::Registry : Rom::Registry_for_reader, Rom::Registry_for_writer /** * Constructor */ - Registry(Module::Read_policy const &read_policy, + Registry(Genode::Ram_session &ram, Genode::Region_map &rm, + Module::Read_policy const &read_policy, Module::Write_policy const &write_policy) : - module("clipboard", read_policy, write_policy) + module(ram, rm, "clipboard", read_policy, write_policy) { } }; @@ -199,7 +200,7 @@ struct Clipboard::Main : Rom::Module::Read_policy, Rom::Module::Write_policy return false; } - Rom::Registry _rom_registry { *this, *this }; + Rom::Registry _rom_registry { _env.ram(), _env.rm(), *this, *this }; Report::Root report_root = { _env, _sliced_heap, _rom_registry, verbose }; Rom ::Root rom_root = { _env, _sliced_heap, _rom_registry }; diff --git a/repos/os/src/server/report_rom/main.cc b/repos/os/src/server/report_rom/main.cc index 103566ba0d..d6c87e2260 100644 --- a/repos/os/src/server/report_rom/main.cc +++ b/repos/os/src/server/report_rom/main.cc @@ -32,7 +32,7 @@ struct Report_rom::Main Genode::Sliced_heap sliced_heap { env.ram(), env.rm() }; - Rom::Registry rom_registry { sliced_heap, config_rom }; + Rom::Registry rom_registry { sliced_heap, env.ram(), env.rm(), config_rom }; Genode::Attached_rom_dataspace config_rom { env, "config" }; diff --git a/repos/os/src/server/report_rom/rom_registry.h b/repos/os/src/server/report_rom/rom_registry.h index 2ae6fed3f5..7d87db0920 100644 --- a/repos/os/src/server/report_rom/rom_registry.h +++ b/repos/os/src/server/report_rom/rom_registry.h @@ -25,7 +25,9 @@ struct Rom::Registry : Registry_for_reader, Registry_for_writer, Genode::Noncopy { private: - Genode::Allocator &_md_alloc; + Genode::Allocator &_md_alloc; + Genode::Ram_session &_ram; + Genode::Region_map &_rm; Genode::Attached_rom_dataspace &_config_rom; Module_list _modules; @@ -70,7 +72,7 @@ struct Rom::Registry : Registry_for_reader, Registry_for_writer, Genode::Noncopy /* XXX if we run out of memory, the server will abort */ Module * const module = new (&_md_alloc) - Module(name, _read_write_policy, _read_write_policy); + Module(_ram, _rm, name, _read_write_policy, _read_write_policy); _modules.insert(module); return *module; @@ -144,9 +146,10 @@ struct Rom::Registry : Registry_for_reader, Registry_for_writer, Genode::Noncopy public: Registry(Genode::Allocator &md_alloc, + Genode::Ram_session &ram, Genode::Region_map &rm, Genode::Attached_rom_dataspace &config_rom) : - _md_alloc(md_alloc), _config_rom(config_rom) + _md_alloc(md_alloc), _ram(ram), _rm(rm), _config_rom(config_rom) { } Module &lookup(Writer &writer, Module::Name const &name) override