From ebd140cacbcfd1e829968065ab584eca117d6fb0 Mon Sep 17 00:00:00 2001 From: Martin Stein Date: Tue, 31 Aug 2021 12:32:32 +0200 Subject: [PATCH] reconstructible: respect alignment of payload If one has an object X that has a minimum alignment requirement specified through 'alignas' this requirement is normally inherited by objects that have object X as member, and by those that have objects as member that have X as member, and so on... . However, this chain used to get silently interrupted (dropping the minimum alignment requirement to 8 again) at objects that are managed with Genode::Reconstructible or Genode::Constructible. In order to fix this, the commit ensures that Genode::Reconstructible (and therefore also Genode::Constructible) has at least the minimum alignment requirement (using 'alignas') as the object it manages. Ref #4217 --- repos/base/include/util/reconstructible.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/repos/base/include/util/reconstructible.h b/repos/base/include/util/reconstructible.h index 5385749f70..036f430c5f 100644 --- a/repos/base/include/util/reconstructible.h +++ b/repos/base/include/util/reconstructible.h @@ -15,6 +15,7 @@ #define _INCLUDE__UTIL__RECONSTRUCTIBLE_H_ #include +#include #include #include @@ -36,14 +37,15 @@ namespace Genode { * \param MT type */ template -class Genode::Reconstructible : Noncopyable +class alignas(Genode::max(alignof(MT), sizeof(Genode::addr_t))) +Genode::Reconstructible : Noncopyable { private: /** * Static reservation of memory for the embedded object */ - char _space[sizeof(MT)] __attribute__((aligned(sizeof(addr_t)))); + char _space[sizeof(MT)] alignas(sizeof(addr_t)); /** * True if the volatile object contains a constructed object