mirror of
https://github.com/genodelabs/genode.git
synced 2025-01-18 10:46:25 +00:00
Use OO-means to copy capabilities (fix #182)
Whenever Native_capability or its derivation Capaility is memcpy'd no copy- constructor/assignment-operator is used and thereby implementation of reference-counting gets impossible for these objects. Use object-oriented means like e.g. copy-constructor instead.
This commit is contained in:
parent
eeb0896d06
commit
685add4774
@ -293,15 +293,12 @@ namespace Genode {
|
|||||||
Capability<RPC_INTERFACE>
|
Capability<RPC_INTERFACE>
|
||||||
reinterpret_cap_cast(Untyped_capability const &untyped_cap)
|
reinterpret_cap_cast(Untyped_capability const &untyped_cap)
|
||||||
{
|
{
|
||||||
Capability<RPC_INTERFACE> typed_cap;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The object layout of untyped and typed capabilities is identical.
|
* The object layout of untyped and typed capabilities is identical.
|
||||||
* Hence we can use memcpy to load the values of the supplied untyped
|
* Hence we can just use it's copy-constructors.
|
||||||
* capability into a typed capability.
|
|
||||||
*/
|
*/
|
||||||
::Genode::memcpy(&typed_cap, &untyped_cap, sizeof(untyped_cap));
|
Untyped_capability *ptr = const_cast<Untyped_capability*>(&untyped_cap);
|
||||||
return typed_cap;
|
return *static_cast<Capability<RPC_INTERFACE>*>(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -325,16 +325,7 @@ namespace Genode {
|
|||||||
Capability<RPC_INTERFACE>
|
Capability<RPC_INTERFACE>
|
||||||
manage(Rpc_object<RPC_INTERFACE, RPC_SERVER> *obj)
|
manage(Rpc_object<RPC_INTERFACE, RPC_SERVER> *obj)
|
||||||
{
|
{
|
||||||
Untyped_capability untyped_cap = _manage(obj);
|
return reinterpret_cap_cast<RPC_INTERFACE>(_manage(obj));
|
||||||
|
|
||||||
/*
|
|
||||||
* Turn untyped capability returned by '_entrypoint.manage()'
|
|
||||||
* to a capability with the type corresponding to the supplied
|
|
||||||
* RPC object.
|
|
||||||
*/
|
|
||||||
Capability<RPC_INTERFACE> typed_cap;
|
|
||||||
memcpy(&typed_cap, &untyped_cap, sizeof(typed_cap));
|
|
||||||
return typed_cap;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user