2011-12-22 16:19:25 +01:00
|
|
|
/*
|
|
|
|
* \brief Capability allocation service
|
2012-08-08 13:20:20 +02:00
|
|
|
* \author Alexander Boettcher
|
|
|
|
* \date 2012-07-27
|
2011-12-22 16:19:25 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2013-01-10 21:44:47 +01:00
|
|
|
* Copyright (C) 2006-2013 Genode Labs GmbH
|
2011-12-22 16:19:25 +01:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
|
|
|
* under the terms of the GNU General Public License version 2.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _CORE__INCLUDE__CAP_SESSION_COMPONENT_H_
|
|
|
|
#define _CORE__INCLUDE__CAP_SESSION_COMPONENT_H_
|
|
|
|
|
|
|
|
#include <cap_session/cap_session.h>
|
|
|
|
#include <base/rpc_server.h>
|
|
|
|
#include <base/lock.h>
|
|
|
|
|
2012-08-01 17:04:43 +02:00
|
|
|
/* core includes */
|
|
|
|
#include <platform_pd.h>
|
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
namespace Genode {
|
|
|
|
|
|
|
|
class Cap_session_component : public Rpc_object<Cap_session>
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
static long _unique_id_cnt;
|
|
|
|
|
2013-01-11 23:10:21 +01:00
|
|
|
struct Cap_object : Native_capability, List<Cap_object>::Element
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
2013-01-11 23:10:21 +01:00
|
|
|
Cap_object(addr_t cap_sel) : Native_capability(cap_sel) {}
|
2012-11-28 14:00:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
Tslab<Cap_object, 128> _cap_slab;
|
|
|
|
List<Cap_object> _cap_list;
|
|
|
|
Lock _cap_lock;
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2012-11-28 12:13:11 +01:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
2012-11-28 14:00:39 +01:00
|
|
|
Cap_session_component(Allocator *md_alloc, const char *args)
|
2013-01-11 23:10:21 +01:00
|
|
|
: _cap_slab(md_alloc) { }
|
2012-11-28 12:13:11 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor
|
|
|
|
*/
|
2012-11-28 14:00:39 +01:00
|
|
|
~Cap_session_component()
|
|
|
|
{
|
|
|
|
Lock::Guard cap_lock(_cap_lock);
|
|
|
|
|
|
|
|
for (Cap_object *obj; (obj = _cap_list.first()); ) {
|
|
|
|
Nova::revoke(Nova::Obj_crd(obj->local_name(), 0));
|
|
|
|
/* XXX cap_selector free up */
|
|
|
|
_cap_list.remove(obj);
|
|
|
|
destroy(&_cap_slab, obj);
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 12:13:11 +01:00
|
|
|
|
2012-11-28 14:00:39 +01:00
|
|
|
Native_capability alloc(Native_capability ep, addr_t entry,
|
2012-08-08 13:20:20 +02:00
|
|
|
addr_t mtd)
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
2012-07-30 10:56:07 +02:00
|
|
|
addr_t pt_sel = cap_selector_allocator()->alloc(0);
|
|
|
|
addr_t pd_sel = Platform_pd::pd_core_sel();
|
|
|
|
addr_t ec_sel = ep.local_name();
|
2013-01-11 23:10:21 +01:00
|
|
|
|
2012-07-30 10:56:07 +02:00
|
|
|
using namespace Nova;
|
2013-01-11 23:10:21 +01:00
|
|
|
|
2012-11-28 14:00:39 +01:00
|
|
|
Lock::Guard cap_lock(_cap_lock);
|
|
|
|
|
|
|
|
/* create cap object */
|
|
|
|
Cap_object * pt_cap = new (&_cap_slab) Cap_object(pt_sel);
|
|
|
|
if (!pt_cap)
|
|
|
|
return Native_capability::invalid_cap();
|
|
|
|
|
|
|
|
_cap_list.insert(pt_cap);
|
|
|
|
|
2012-07-30 10:56:07 +02:00
|
|
|
/* create portal */
|
2012-11-28 14:00:39 +01:00
|
|
|
uint8_t res = create_pt(pt_sel, pd_sel, ec_sel, Mtd(mtd),
|
|
|
|
entry);
|
2012-07-30 10:56:07 +02:00
|
|
|
if (res == NOVA_OK)
|
|
|
|
return Native_capability(pt_sel);
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2012-07-30 10:56:07 +02:00
|
|
|
PERR("cap_session - cap=%lx:%lx"
|
|
|
|
" addr=%lx flags=%lx xpt=%lx res=%u",
|
|
|
|
ec_sel, ep.local_name(),
|
|
|
|
entry, mtd, pt_sel, res);
|
|
|
|
|
2012-11-28 14:00:39 +01:00
|
|
|
_cap_list.remove(pt_cap);
|
|
|
|
destroy(&_cap_slab, pt_cap);
|
|
|
|
|
2012-07-30 10:56:07 +02:00
|
|
|
/* cleanup unused selectors */
|
|
|
|
cap_selector_allocator()->free(pt_sel, 0);
|
|
|
|
|
|
|
|
/* XXX revoke ec_sel if it was mapped !!!! */
|
|
|
|
|
|
|
|
return Native_capability::invalid_cap();
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
|
|
|
|
2013-01-11 23:10:21 +01:00
|
|
|
void free(Native_capability cap)
|
|
|
|
{
|
2012-11-28 14:00:39 +01:00
|
|
|
if (!cap.valid()) return;
|
|
|
|
|
|
|
|
Lock::Guard cap_lock(_cap_lock);
|
|
|
|
|
|
|
|
for (Cap_object *obj = _cap_list.first(); obj ; obj = obj->next()) {
|
|
|
|
if (cap.local_name() == obj->local_name()) {
|
|
|
|
Nova::revoke(Nova::Obj_crd(obj->local_name(), 0));
|
|
|
|
/* XXX cap_selector free up */
|
|
|
|
_cap_list.remove(obj);
|
|
|
|
destroy(&_cap_slab, obj);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PDBG("invalid cap object");
|
2013-01-11 23:10:21 +01:00
|
|
|
}
|
2011-12-22 16:19:25 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* _CORE__INCLUDE__CAP_SESSION_COMPONENT_H_ */
|