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
This commit is contained in:
Martin Stein 2021-08-31 12:32:32 +02:00 committed by Norman Feske
parent 64e2912a2f
commit ebd140cacb

View File

@ -15,6 +15,7 @@
#define _INCLUDE__UTIL__RECONSTRUCTIBLE_H_ #define _INCLUDE__UTIL__RECONSTRUCTIBLE_H_
#include <util/construct_at.h> #include <util/construct_at.h>
#include <util/misc_math.h>
#include <base/stdint.h> #include <base/stdint.h>
#include <util/noncopyable.h> #include <util/noncopyable.h>
@ -36,14 +37,15 @@ namespace Genode {
* \param MT type * \param MT type
*/ */
template <typename MT> template <typename MT>
class Genode::Reconstructible : Noncopyable class alignas(Genode::max(alignof(MT), sizeof(Genode::addr_t)))
Genode::Reconstructible : Noncopyable
{ {
private: private:
/** /**
* Static reservation of memory for the embedded object * 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 * True if the volatile object contains a constructed object