diff --git a/mm/mm_heap/mm_initialize.c b/mm/mm_heap/mm_initialize.c index 62759e9586..0801eae5d5 100644 --- a/mm/mm_heap/mm_initialize.c +++ b/mm/mm_heap/mm_initialize.c @@ -165,17 +165,23 @@ void mm_initialize(FAR struct mm_heap_s *heap, FAR void *heapstart, size_t heapsize) { FAR struct mm_heap_impl_s *heap_impl; - int i; + uintptr_t heap_adj; + int i; minfo("Heap: start=%p size=%zu\n", heapstart, heapsize); + /* First ensure the memory to be used is aligned */ + + heap_adj = MM_ALIGN_UP((uintptr_t) heapstart); + heapsize -= heap_adj - (uintptr_t) heapstart; + /* Reserve a block space for mm_heap_impl_s context */ DEBUGASSERT(heapsize > sizeof(struct mm_heap_impl_s)); - heap->mm_impl = (FAR struct mm_heap_impl_s *)heapstart; + heap->mm_impl = (FAR struct mm_heap_impl_s *)heap_adj; heap_impl = heap->mm_impl; heapsize -= sizeof(struct mm_heap_impl_s); - heapstart = (FAR char *)heapstart + sizeof(struct mm_heap_impl_s); + heapstart = (FAR char *)heap_adj + sizeof(struct mm_heap_impl_s); /* The following two lines have cause problems for some older ZiLog * compilers in the past (but not the more recent). Life is easier if we