mm: Support CONFIG_MM_NODE_GUARDSIZE configuration

After it is not zero, the preceding member of the next node will no longer belong to the valid area of the previous alloc node.
Due to the existence of precedence, the memory block size of the node can only be aligned with sizeof(mmsize_t).
This configuration will be applied in the following scenarios when set 8:
	ARM64 MTE hardware tag KASan, which requires the tag's memory address to be 16-byte aligned and the memory size must also be 16-byte aligned

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
This commit is contained in:
wangmingrong1 2025-02-19 16:25:09 +08:00 committed by Xiang Xiao
parent 5079105e17
commit a98f3f2417
3 changed files with 11 additions and 2 deletions

View file

@ -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

View file

@ -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 */

View file

@ -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 */