mirror of
https://github.com/apache/nuttx.git
synced 2026-05-27 19:36:35 +08:00
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:
@@ -135,6 +135,7 @@ void mm_addregion(FAR struct mm_heap_s *heap, FAR void *heapstart,
|
|||||||
heap->mm_heapstart[IDX]->preceding = MM_ALLOC_BIT;
|
heap->mm_heapstart[IDX]->preceding = MM_ALLOC_BIT;
|
||||||
node = (FAR struct mm_freenode_s *)
|
node = (FAR struct mm_freenode_s *)
|
||||||
(heapbase + SIZEOF_MM_ALLOCNODE);
|
(heapbase + SIZEOF_MM_ALLOCNODE);
|
||||||
|
DEBUGASSERT((((uintptr_t)node + SIZEOF_MM_ALLOCNODE) % MM_MIN_CHUNK) == 0);
|
||||||
node->size = heapsize - 2*SIZEOF_MM_ALLOCNODE;
|
node->size = heapsize - 2*SIZEOF_MM_ALLOCNODE;
|
||||||
node->preceding = SIZEOF_MM_ALLOCNODE;
|
node->preceding = SIZEOF_MM_ALLOCNODE;
|
||||||
heap->mm_heapend[IDX] = (FAR struct mm_allocnode_s *)
|
heap->mm_heapend[IDX] = (FAR struct mm_allocnode_s *)
|
||||||
|
|||||||
@@ -271,5 +271,6 @@ FAR void *mm_malloc(FAR struct mm_heap_s *heap, size_t size)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
DEBUGASSERT(ret == NULL || ((uintptr_t)ret) % MM_MIN_CHUNK == 0);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,7 +79,9 @@ FAR void *mm_memalign(FAR struct mm_heap_s *heap, size_t alignment,
|
|||||||
|
|
||||||
if (alignment <= MM_MIN_CHUNK)
|
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)
|
/* 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,
|
kasan_unpoison((FAR void *)alignedchunk,
|
||||||
mm_malloc_size((FAR void *)alignedchunk));
|
mm_malloc_size((FAR void *)alignedchunk));
|
||||||
|
|
||||||
|
DEBUGASSERT(alignedchunk % alignment == 0);
|
||||||
return (FAR void *)alignedchunk;
|
return (FAR void *)alignedchunk;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user