diff --git a/mm/Kconfig b/mm/Kconfig index 2966d9f300..7c029878b1 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -69,6 +69,13 @@ config MM_DEFAULT_ALIGNMENT memory default alignment is equal to sizoef(uintptr), if this value is not 0, this value must be 2^n and at least sizeof(uintptr). +config MM_NODE_GUARDSIZE + int "Memory node guard size" + default 0 + ---help--- + After it is enabled, the front and rear nodes will maintain a safety + distance of at least CONFIG_MM_NODE_GUARDSIZE. + config MM_SMALL bool "Small memory model" default n diff --git a/mm/mm_heap/mm.h b/mm/mm_heap/mm.h index 58d432716f..0a818b06dd 100644 --- a/mm/mm_heap/mm.h +++ b/mm/mm_heap/mm.h @@ -143,7 +143,8 @@ * previous freenode */ -#define MM_ALLOCNODE_OVERHEAD (MM_SIZEOF_ALLOCNODE - sizeof(mmsize_t)) +#define MM_ALLOCNODE_OVERHEAD (CONFIG_MM_NODE_GUARDSIZE + \ + MM_SIZEOF_ALLOCNODE - sizeof(mmsize_t)) /* Get the node size */ diff --git a/mm/mm_heap/mm_realloc.c b/mm/mm_heap/mm_realloc.c index d41619a66a..6600290f58 100644 --- a/mm/mm_heap/mm_realloc.c +++ b/mm/mm_heap/mm_realloc.c @@ -153,7 +153,8 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem, heap->mm_curused += newsize - oldsize; mm_shrinkchunk(heap, oldnode, newsize); kasan_poison((FAR char *)oldnode + MM_SIZEOF_NODE(oldnode) + - sizeof(mmsize_t), oldsize - MM_SIZEOF_NODE(oldnode)); + sizeof(mmsize_t) - CONFIG_MM_NODE_GUARDSIZE, + oldsize - MM_SIZEOF_NODE(oldnode)); } /* Then return the original address */