From 8495a5fc967f75773d9e2f99e62da92b4d3974b8 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Mon, 9 Jan 2012 21:44:36 +0100 Subject: [PATCH] Convenience helper for attached ROM dataspaces In the line of the 'Attached_ram_dataspace' and 'Attached_io_mem_dataspace' classes, this new helper simplifies the access to ROM dataspaces. --- os/include/os/attached_rom_dataspace.h | 78 ++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 os/include/os/attached_rom_dataspace.h diff --git a/os/include/os/attached_rom_dataspace.h b/os/include/os/attached_rom_dataspace.h new file mode 100644 index 000000000..4b50dadb2 --- /dev/null +++ b/os/include/os/attached_rom_dataspace.h @@ -0,0 +1,78 @@ +/* + * \brief ROM dataspace utility + * \author Norman Feske + * \date 2012-01-09 + */ + +/* + * Copyright (C) 2012 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 _INCLUDE__OS__ATTACHED_ROM_DATASPACE_H_ +#define _INCLUDE__OS__ATTACHED_ROM_DATASPACE_H_ + +#include +#include +#include + +namespace Genode { + + class Attached_rom_dataspace + { + private: + + Rom_connection _rom; + Rom_dataspace_capability _ds; + size_t _size; + void *_local_addr; + + public: + + /** + * Constructor + * + * \throw Rom_connection::Rom_session_failed + * \throw Rm_session::Attach_failed + */ + Attached_rom_dataspace(char const *name) + : + _rom(name), + _ds(_rom.dataspace()), + _size(Dataspace_client(_ds).size()), + _local_addr(env()->rm_session()->attach(_ds)) + { } + + /** + * Destructor + */ + ~Attached_rom_dataspace() + { + env()->rm_session()->detach(_local_addr); + } + + /** + * Return capability of the used ROM dataspace + */ + Rom_dataspace_capability cap() const { return _ds; } + + /** + * Request local address + * + * This is a template to avoid inconvenient casts at + * the caller. A newly allocated ROM dataspace is + * untyped memory anyway. + */ + template + T *local_addr() { return static_cast(_local_addr); } + + /** + * Return size + */ + size_t size() const { return _size; } + }; +} + +#endif /* _INCLUDE__OS__ATTACHED_ROM_DATASPACE_H_ */