mm_heap: add debug assert to check the alignment problem

Signed-off-by: wangbowen6 <wangbowen6@xiaomi.com>
Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
This commit is contained in:
wangbowen6 2022-10-31 20:09:23 +08:00 committed by Xiang Xiao
parent 5611d89015
commit fccda0c08b
3 changed files with 6 additions and 1 deletions

View File

@ -135,6 +135,7 @@ void mm_addregion(FAR struct mm_heap_s *heap, FAR void *heapstart,
heap->mm_heapstart[IDX]->preceding = MM_ALLOC_BIT;
node = (FAR struct mm_freenode_s *)
(heapbase + SIZEOF_MM_ALLOCNODE);
DEBUGASSERT((((uintptr_t)node + SIZEOF_MM_ALLOCNODE) % MM_MIN_CHUNK) == 0);
node->size = heapsize - 2*SIZEOF_MM_ALLOCNODE;
node->preceding = SIZEOF_MM_ALLOCNODE;
heap->mm_heapend[IDX] = (FAR struct mm_allocnode_s *)

View File

@ -271,5 +271,6 @@ FAR void *mm_malloc(FAR struct mm_heap_s *heap, size_t size)
}
#endif
DEBUGASSERT(ret == NULL || ((uintptr_t)ret) % MM_MIN_CHUNK == 0);
return ret;
}

View File

@ -79,7 +79,9 @@ FAR void *mm_memalign(FAR struct mm_heap_s *heap, size_t alignment,
if (alignment <= MM_MIN_CHUNK)
{
return mm_malloc(heap, size);
FAR void *ptr = mm_malloc(heap, size);
DEBUGASSERT(ptr == NULL || ((uintptr_t)ptr) % alignment == 0);
return ptr;
}
/* Adjust the size to account for (1) the size of the allocated node, (2)
@ -230,5 +232,6 @@ FAR void *mm_memalign(FAR struct mm_heap_s *heap, size_t alignment,
kasan_unpoison((FAR void *)alignedchunk,
mm_malloc_size((FAR void *)alignedchunk));
DEBUGASSERT(alignedchunk % alignment == 0);
return (FAR void *)alignedchunk;
}