2016-08-15 12:27:54 +02:00
|
|
|
/*
|
|
|
|
* \brief VirtualBox memory manager (MMR3)
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2013-08-20
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2013-2017 Genode Labs GmbH
|
2016-08-15 12:27:54 +02:00
|
|
|
*
|
|
|
|
* This file is distributed under the terms of the GNU General Public License
|
|
|
|
* version 2.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <rm_session/rm_session.h>
|
|
|
|
#include <rm_session/connection.h>
|
|
|
|
#include <region_map/client.h>
|
|
|
|
|
|
|
|
#include <util/retry.h>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sub rm_session as backend for the Libc::Mem_alloc implementation.
|
|
|
|
* Purpose is that memory allocation by vbox of a specific type (MMTYP) are
|
|
|
|
* all located within a 2G virtual window. Reason is that virtualbox converts
|
|
|
|
* internally pointers at several places in base + offset, whereby offset is
|
|
|
|
* a int32_t type.
|
|
|
|
*/
|
|
|
|
class Sub_rm_connection : private Genode::Rm_connection,
|
|
|
|
public Genode::Region_map_client
|
|
|
|
{
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
Genode::addr_t const _offset;
|
|
|
|
Genode::size_t const _size;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2017-01-05 13:45:37 +01:00
|
|
|
Sub_rm_connection(Genode::Env &env, Genode::size_t size)
|
2016-08-15 12:27:54 +02:00
|
|
|
:
|
2017-01-05 13:45:37 +01:00
|
|
|
Rm_connection(env),
|
2016-08-15 12:27:54 +02:00
|
|
|
Genode::Region_map_client(Rm_connection::create(size)),
|
2017-01-05 13:45:37 +01:00
|
|
|
_offset(env.rm().attach(dataspace())),
|
2016-08-15 12:27:54 +02:00
|
|
|
_size(size)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
Local_addr attach(Genode::Dataspace_capability ds,
|
|
|
|
Genode::size_t size = 0, Genode::off_t offset = 0,
|
|
|
|
bool use_local_addr = false,
|
|
|
|
Local_addr local_addr = (void *)0,
|
2018-05-08 11:21:10 +02:00
|
|
|
bool executable = false,
|
|
|
|
bool writeable = true) override
|
2016-08-15 12:27:54 +02:00
|
|
|
{
|
Streamline exception types
This patch reduces the number of exception types by facilitating
globally defined exceptions for common usage patterns shared by most
services. In particular, RPC functions that demand a session-resource
upgrade not longer reflect this condition via a session-specific
exception but via the 'Out_of_ram' or 'Out_of_caps' types.
Furthermore, the 'Parent::Service_denied', 'Parent::Unavailable',
'Root::Invalid_args', 'Root::Unavailable', 'Service::Invalid_args',
'Service::Unavailable', and 'Local_service::Factory::Denied' types have
been replaced by the single 'Service_denied' exception type defined in
'session/session.h'.
This consolidation eases the error handling (there are fewer exceptions
to handle), alleviates the need to convert exceptions along the
session-creation call chain, and avoids possible aliasing problems
(catching the wrong type with the same name but living in a different
scope).
2017-05-07 22:03:22 +02:00
|
|
|
Local_addr addr = Genode::retry<Genode::Out_of_ram>(
|
2016-08-15 12:27:54 +02:00
|
|
|
[&] () {
|
Streamline exception types
This patch reduces the number of exception types by facilitating
globally defined exceptions for common usage patterns shared by most
services. In particular, RPC functions that demand a session-resource
upgrade not longer reflect this condition via a session-specific
exception but via the 'Out_of_ram' or 'Out_of_caps' types.
Furthermore, the 'Parent::Service_denied', 'Parent::Unavailable',
'Root::Invalid_args', 'Root::Unavailable', 'Service::Invalid_args',
'Service::Unavailable', and 'Local_service::Factory::Denied' types have
been replaced by the single 'Service_denied' exception type defined in
'session/session.h'.
This consolidation eases the error handling (there are fewer exceptions
to handle), alleviates the need to convert exceptions along the
session-creation call chain, and avoids possible aliasing problems
(catching the wrong type with the same name but living in a different
scope).
2017-05-07 22:03:22 +02:00
|
|
|
return Genode::retry<Genode::Out_of_caps>(
|
|
|
|
[&] () {
|
|
|
|
return Region_map_client::attach(ds, size, offset,
|
|
|
|
use_local_addr,
|
|
|
|
local_addr,
|
2018-05-08 11:21:10 +02:00
|
|
|
executable,
|
|
|
|
writeable); },
|
Streamline exception types
This patch reduces the number of exception types by facilitating
globally defined exceptions for common usage patterns shared by most
services. In particular, RPC functions that demand a session-resource
upgrade not longer reflect this condition via a session-specific
exception but via the 'Out_of_ram' or 'Out_of_caps' types.
Furthermore, the 'Parent::Service_denied', 'Parent::Unavailable',
'Root::Invalid_args', 'Root::Unavailable', 'Service::Invalid_args',
'Service::Unavailable', and 'Local_service::Factory::Denied' types have
been replaced by the single 'Service_denied' exception type defined in
'session/session.h'.
This consolidation eases the error handling (there are fewer exceptions
to handle), alleviates the need to convert exceptions along the
session-creation call chain, and avoids possible aliasing problems
(catching the wrong type with the same name but living in a different
scope).
2017-05-07 22:03:22 +02:00
|
|
|
[&] () { upgrade_caps(2); });
|
|
|
|
},
|
2016-11-23 17:07:49 +01:00
|
|
|
[&] () { upgrade_ram(8192); });
|
2016-08-15 12:27:54 +02:00
|
|
|
|
|
|
|
Genode::addr_t new_addr = addr;
|
|
|
|
new_addr += _offset;
|
|
|
|
return Local_addr(new_addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool contains(void * ptr) const
|
|
|
|
{
|
|
|
|
Genode::addr_t addr = reinterpret_cast<Genode::addr_t>(ptr);
|
|
|
|
|
|
|
|
return (_offset <= addr && addr < _offset + _size);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool contains(Genode::addr_t addr) const {
|
|
|
|
return (_offset <= addr && addr < _offset + _size); }
|
|
|
|
|
|
|
|
Genode::addr_t local_addr(Genode::addr_t addr) const {
|
|
|
|
return _offset + addr; }
|
|
|
|
};
|