From 685add4774a9f85c36cfd655f73b91a21b259c32 Mon Sep 17 00:00:00 2001 From: Stefan Kalkowski Date: Wed, 2 May 2012 11:28:58 +0200 Subject: [PATCH] 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. --- base/include/base/capability.h | 9 +++------ base/include/base/rpc_server.h | 11 +---------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/base/include/base/capability.h b/base/include/base/capability.h index 93d071e2e..a94b93036 100644 --- a/base/include/base/capability.h +++ b/base/include/base/capability.h @@ -293,15 +293,12 @@ namespace Genode { Capability reinterpret_cap_cast(Untyped_capability const &untyped_cap) { - Capability 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_cap); + return *static_cast*>(ptr); } diff --git a/base/include/base/rpc_server.h b/base/include/base/rpc_server.h index d445e8826..9f4f4754e 100644 --- a/base/include/base/rpc_server.h +++ b/base/include/base/rpc_server.h @@ -325,16 +325,7 @@ namespace Genode { Capability manage(Rpc_object *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 typed_cap; - memcpy(&typed_cap, &untyped_cap, sizeof(typed_cap)); - return typed_cap; + return reinterpret_cap_cast(_manage(obj)); } /**