Commit 330ca0ec authored by Philippe Gerum's avatar Philippe Gerum Committed by Jan Kiszka

copperplate/heapobj-pshared: fix element size for array init

Heapmem aligns every requested element size to the next ^2 boundary,
which must be accounted for when determining the raw size of the
sub-heap we need for storing the array.
Signed-off-by: Philippe Gerum's avatarPhilippe Gerum <rpm@xenomai.org>
Signed-off-by: Jan Kiszka's avatarJan Kiszka <jan.kiszka@siemens.com>
parent ba59cd72
......@@ -1111,7 +1111,21 @@ int heapobj_init(struct heapobj *hobj, const char *name, size_t size)
int heapobj_init_array(struct heapobj *hobj, const char *name,
size_t size, int elems)
{
size = __align_to(size, SHEAPMEM_MIN_ALIGN);
int log2size;
if (size < SHEAPMEM_MIN_ALIGN) {
size = SHEAPMEM_MIN_ALIGN;
} else {
log2size = sizeof(size) * CHAR_BIT - 1 -
xenomai_count_leading_zeros(size);
if (log2size < SHEAPMEM_PAGE_SHIFT) {
if (size & (size - 1))
log2size++;
size = 1 << log2size;
} else
size = __align_to(size, SHEAPMEM_PAGE_SIZE);
}
return __bt(heapobj_init(hobj, name, size * elems));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment