nova: extend cap_session to free up portals
This commit is contained in:
parent
8c4e1b7eb0
commit
2426030c5b
|
@ -29,26 +29,43 @@ namespace Genode {
|
||||||
|
|
||||||
static long _unique_id_cnt;
|
static long _unique_id_cnt;
|
||||||
|
|
||||||
static Lock &_lock()
|
class Cap_object : public Native_capability,
|
||||||
|
public List<Cap_object>::Element
|
||||||
{
|
{
|
||||||
static Lock static_lock;
|
public:
|
||||||
return static_lock;
|
|
||||||
}
|
Cap_object(addr_t cap_sel) : Native_capability(cap_sel) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
Tslab<Cap_object, 128> _cap_slab;
|
||||||
|
List<Cap_object> _cap_list;
|
||||||
|
Lock _cap_lock;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
Cap_session_component(Allocator *md_alloc, const char *args) { }
|
Cap_session_component(Allocator *md_alloc, const char *args)
|
||||||
|
:
|
||||||
|
_cap_slab(md_alloc) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destructor
|
* Destructor
|
||||||
*/
|
*/
|
||||||
~Cap_session_component() { }
|
~Cap_session_component()
|
||||||
|
{
|
||||||
|
Lock::Guard cap_lock(_cap_lock);
|
||||||
|
|
||||||
Native_capability alloc(Native_capability ep,
|
for (Cap_object *obj; (obj = _cap_list.first()); ) {
|
||||||
addr_t entry,
|
Nova::revoke(Nova::Obj_crd(obj->local_name(), 0));
|
||||||
|
/* XXX cap_selector free up */
|
||||||
|
_cap_list.remove(obj);
|
||||||
|
destroy(&_cap_slab, obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Native_capability alloc(Native_capability ep, addr_t entry,
|
||||||
addr_t mtd)
|
addr_t mtd)
|
||||||
{
|
{
|
||||||
addr_t pt_sel = cap_selector_allocator()->alloc(0);
|
addr_t pt_sel = cap_selector_allocator()->alloc(0);
|
||||||
|
@ -56,10 +73,19 @@ namespace Genode {
|
||||||
addr_t ec_sel = ep.local_name();
|
addr_t ec_sel = ep.local_name();
|
||||||
|
|
||||||
using namespace Nova;
|
using namespace Nova;
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
/* create portal */
|
/* create portal */
|
||||||
uint8_t res = create_pt(pt_sel, pd_sel, ec_sel,
|
uint8_t res = create_pt(pt_sel, pd_sel, ec_sel, Mtd(mtd),
|
||||||
Mtd(mtd), entry);
|
entry);
|
||||||
if (res == NOVA_OK)
|
if (res == NOVA_OK)
|
||||||
return Native_capability(pt_sel);
|
return Native_capability(pt_sel);
|
||||||
|
|
||||||
|
@ -68,6 +94,9 @@ namespace Genode {
|
||||||
ec_sel, ep.local_name(),
|
ec_sel, ep.local_name(),
|
||||||
entry, mtd, pt_sel, res);
|
entry, mtd, pt_sel, res);
|
||||||
|
|
||||||
|
_cap_list.remove(pt_cap);
|
||||||
|
destroy(&_cap_slab, pt_cap);
|
||||||
|
|
||||||
/* cleanup unused selectors */
|
/* cleanup unused selectors */
|
||||||
cap_selector_allocator()->free(pt_sel, 0);
|
cap_selector_allocator()->free(pt_sel, 0);
|
||||||
|
|
||||||
|
@ -76,7 +105,22 @@ namespace Genode {
|
||||||
return Native_capability::invalid_cap();
|
return Native_capability::invalid_cap();
|
||||||
}
|
}
|
||||||
|
|
||||||
void free(Native_capability cap) { }
|
void free(Native_capability cap) {
|
||||||
|
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");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user