From b373cc7ddb1d372d871418f5bb8459683e9f3bf0 Mon Sep 17 00:00:00 2001 From: Fangyi Zhou Date: Thu, 3 Aug 2017 09:57:27 +0100 Subject: [PATCH] pool_queue: Add static assert for management_array offset In order for the GNU extension of static initialisation of flexible array member to work. Care must be taken to check whether the offset of management_array is the size of the structure, so that accessing the management_array will be to the allocated static memory following the pool struct. If this assertion fails, accessing management_array might end of accessing the struct padding inserted by the compiler. --- core/system/src/pool_queue.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/system/src/pool_queue.c b/core/system/src/pool_queue.c index fad35b77..00228d0a 100644 --- a/core/system/src/pool_queue.c +++ b/core/system/src/pool_queue.c @@ -17,6 +17,7 @@ #include "api/inc/linker_exports.h" #include "api/inc/pool_queue_exports.h" #include "api/inc/uvisor_spinlock_exports.h" +#include #include int uvisor_pool_init(uvisor_pool_t * pool, void * array, size_t stride, size_t num) @@ -46,6 +47,10 @@ int uvisor_pool_init(uvisor_pool_t * pool, void * array, size_t stride, size_t n uvisor_spin_init(&pool->spinlock); + UVISOR_STATIC_ASSERT( + sizeof(uvisor_pool_t) == offsetof(uvisor_pool_t, management_array), + management_array_offset_must_be_aligned_to_pool_structure_size); + return 0; }