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:
Stefan Kalkowski 2012-05-02 11:28:58 +02:00 committed by Norman Feske
parent eeb0896d06
commit 685add4774
2 changed files with 4 additions and 16 deletions

View File

@ -293,15 +293,12 @@ namespace Genode {
Capability<RPC_INTERFACE>
reinterpret_cap_cast(Untyped_capability const &untyped_cap)
{
Capability<RPC_INTERFACE> typed_cap;
/*
* The object layout of untyped and typed capabilities is identical.
* Hence we can use memcpy to load the values of the supplied untyped
* capability into a typed capability.
* Hence we can just use it's copy-constructors.
*/
::Genode::memcpy(&typed_cap, &untyped_cap, sizeof(untyped_cap));
return typed_cap;
Untyped_capability *ptr = const_cast<Untyped_capability*>(&untyped_cap);
return *static_cast<Capability<RPC_INTERFACE>*>(ptr);
}

View File

@ -325,16 +325,7 @@ namespace Genode {
Capability<RPC_INTERFACE>
manage(Rpc_object<RPC_INTERFACE, RPC_SERVER> *obj)
{
Untyped_capability untyped_cap = _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;
return reinterpret_cap_cast<RPC_INTERFACE>(_manage(obj));
}
/**