mirror of
https://github.com/genodelabs/genode.git
synced 2025-01-18 02:40:08 +00:00
parent
0d7d60a1f4
commit
5181d08d05
@ -38,10 +38,14 @@ struct Genode::Local_rm_session : Rm_session, Local_session
|
||||
_local_rm(local_rm), _md_alloc(md_alloc)
|
||||
{ }
|
||||
|
||||
Capability<Region_map> create(size_t size) override
|
||||
Create_result create(size_t size) override
|
||||
{
|
||||
Region_map *rm = new (_md_alloc) Region_map_mmap(true, size);
|
||||
return Local_capability<Region_map>::local_cap(rm);
|
||||
try {
|
||||
Region_map *rm = new (_md_alloc) Region_map_mmap(true, size);
|
||||
return Local_capability<Region_map>::local_cap(rm);
|
||||
}
|
||||
catch (Out_of_ram) { return Create_error::OUT_OF_RAM; }
|
||||
catch (Out_of_caps) { return Create_error::OUT_OF_CAPS; }
|
||||
}
|
||||
|
||||
void destroy(Capability<Region_map> cap) override
|
||||
|
@ -35,7 +35,7 @@ Rm_session_client::Rm_session_client(Capability<Rm_session> session)
|
||||
: Rpc_client<Rm_session>(session) { }
|
||||
|
||||
|
||||
Capability<Region_map> Rm_session_client::create(size_t size) {
|
||||
Rm_session::Create_result Rm_session_client::create(size_t size) {
|
||||
return _local(rpc_cap())->create(size); }
|
||||
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
#ifndef _INCLUDE__REGION_MAP__REGION_MAP_H_
|
||||
#define _INCLUDE__REGION_MAP__REGION_MAP_H_
|
||||
|
||||
#include <util/attempt.h>
|
||||
#include <base/exception.h>
|
||||
#include <base/stdint.h>
|
||||
#include <base/signal.h>
|
||||
|
@ -24,7 +24,7 @@ struct Genode::Rm_session_client : Rpc_client<Rm_session>
|
||||
{
|
||||
explicit Rm_session_client(Rm_session_capability);
|
||||
|
||||
Capability<Region_map> create(size_t) override;
|
||||
Create_result create(size_t) override;
|
||||
void destroy(Capability<Region_map>) override;
|
||||
};
|
||||
|
||||
|
@ -21,31 +21,35 @@
|
||||
namespace Genode { struct Rm_connection; }
|
||||
|
||||
|
||||
struct Genode::Rm_connection : Connection<Rm_session>, Rm_session_client
|
||||
struct Genode::Rm_connection : Connection<Rm_session>
|
||||
{
|
||||
Rm_session_client _client { cap() };
|
||||
|
||||
Rm_connection(Env &env)
|
||||
:
|
||||
Connection<Rm_session>(env, Label(), Ram_quota { 64*1024 }, Args()),
|
||||
Rm_session_client(cap())
|
||||
Connection<Rm_session>(env, {}, Ram_quota { 64*1024 }, Args())
|
||||
{ }
|
||||
|
||||
/**
|
||||
* Wrapper over 'create' that handles resource requests from the server
|
||||
* Wrapper of 'create' that handles session-quota upgrades on demand
|
||||
*/
|
||||
Capability<Region_map> create(size_t size) override
|
||||
Capability<Region_map> create(size_t size)
|
||||
{
|
||||
enum { UPGRADE_ATTEMPTS = 16U };
|
||||
|
||||
return Genode::retry<Out_of_ram>(
|
||||
[&] () {
|
||||
return Genode::retry<Out_of_caps>(
|
||||
[&] () { return Rm_session_client::create(size); },
|
||||
[&] () { upgrade_caps(2); },
|
||||
UPGRADE_ATTEMPTS);
|
||||
},
|
||||
[&] () { upgrade_ram(8*1024); },
|
||||
UPGRADE_ATTEMPTS);
|
||||
Capability<Region_map> result { };
|
||||
using Error = Rm_session::Create_error;
|
||||
while (!result.valid())
|
||||
_client.create(size).with_result(
|
||||
[&] (Capability<Region_map> cap) { result = cap; },
|
||||
[&] (Error e) {
|
||||
switch (e) {
|
||||
case Error::OUT_OF_RAM: upgrade_ram(8*1024); break;
|
||||
case Error::OUT_OF_CAPS: upgrade_caps(2); break;
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
void destroy(Capability<Region_map> cap) { _client.destroy(cap); }
|
||||
};
|
||||
|
||||
#endif /* _INCLUDE__RM_SESSION__CONNECTION_H_ */
|
||||
|
@ -33,15 +33,16 @@ struct Genode::Rm_session : Session
|
||||
*/
|
||||
enum { CAP_QUOTA = 2 };
|
||||
|
||||
enum class Create_error { OUT_OF_RAM, OUT_OF_CAPS };
|
||||
using Create_result = Attempt<Capability<Region_map>, Create_error>;
|
||||
|
||||
/**
|
||||
* Create region map
|
||||
*
|
||||
* \param size upper bound of region map
|
||||
* \return region-map capability
|
||||
* \throw Out_of_ram
|
||||
* \throw Out_of_caps
|
||||
*/
|
||||
virtual Capability<Region_map> create(size_t size) = 0;
|
||||
virtual Create_result create(size_t size) = 0;
|
||||
|
||||
/**
|
||||
* Destroy region map
|
||||
@ -53,8 +54,7 @@ struct Genode::Rm_session : Session
|
||||
** RPC declaration **
|
||||
*********************/
|
||||
|
||||
GENODE_RPC_THROW(Rpc_create, Capability<Region_map>, create,
|
||||
GENODE_TYPE_LIST(Out_of_ram, Out_of_caps), size_t);
|
||||
GENODE_RPC(Rpc_create, Create_result, create, size_t);
|
||||
GENODE_RPC(Rpc_destroy, void, destroy, Capability<Region_map>);
|
||||
|
||||
GENODE_RPC_INTERFACE(Rpc_create, Rpc_destroy);
|
||||
|
@ -72,7 +72,7 @@ class Core::Rm_session_component : public Session_object<Rm_session>
|
||||
** Rm_session interface **
|
||||
**************************/
|
||||
|
||||
Capability<Region_map> create(size_t size) override
|
||||
Create_result create(size_t size) override
|
||||
{
|
||||
Mutex::Guard guard(_region_maps_lock);
|
||||
|
||||
@ -86,7 +86,8 @@ class Core::Rm_session_component : public Session_object<Rm_session>
|
||||
|
||||
return rm->cap();
|
||||
}
|
||||
catch (Allocator::Out_of_memory) { throw Out_of_ram(); }
|
||||
catch (Out_of_ram) { return Create_error::OUT_OF_RAM; }
|
||||
catch (Out_of_caps) { return Create_error::OUT_OF_CAPS; }
|
||||
}
|
||||
|
||||
void destroy(Capability<Region_map> cap) override
|
||||
|
@ -20,7 +20,7 @@ Rm_session_client::Rm_session_client(Capability<Rm_session> cap)
|
||||
: Rpc_client<Rm_session>(cap) { }
|
||||
|
||||
|
||||
Capability<Region_map> Rm_session_client::create(size_t size) {
|
||||
Rm_session::Create_result Rm_session_client::create(size_t size) {
|
||||
return call<Rpc_create>(size); }
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user