mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-18 21:27:56 +00:00
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.
This commit is contained in:
parent
a6bac95fbd
commit
8495a5fc96
78
os/include/os/attached_rom_dataspace.h
Normal file
78
os/include/os/attached_rom_dataspace.h
Normal file
@ -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 <rom_session/connection.h>
|
||||
#include <dataspace/client.h>
|
||||
#include <base/env.h>
|
||||
|
||||
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 <typename T>
|
||||
T *local_addr() { return static_cast<T *>(_local_addr); }
|
||||
|
||||
/**
|
||||
* Return size
|
||||
*/
|
||||
size_t size() const { return _size; }
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* _INCLUDE__OS__ATTACHED_ROM_DATASPACE_H_ */
|
Loading…
Reference in New Issue
Block a user