Skip to content

Commit

Permalink
mm: Add CONFIG_MM_NODE_PENDING configuration
Browse files Browse the repository at this point in the history
After it is enabled, 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:
	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 <[email protected]>
  • Loading branch information
W-M-R committed Feb 6, 2025
1 parent 0ae633c commit 2549506
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
8 changes: 8 additions & 0 deletions mm/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ 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_PENDING
bool "Enable pending memory node"
default n
---help---
After it is enabled, the "preceding" member will be retained
forever regardless of whether the previous node is in the
alloc state or the free state.

config MM_SMALL
bool "Small memory model"
default n
Expand Down
6 changes: 5 additions & 1 deletion mm/mm_heap/mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@
* previous freenode
*/

#define MM_ALLOCNODE_OVERHEAD (MM_SIZEOF_ALLOCNODE - sizeof(mmsize_t))
#ifdef CONFIG_MM_NODE_PENDING
# define MM_ALLOCNODE_OVERHEAD (MM_SIZEOF_ALLOCNODE)
#else
# define MM_ALLOCNODE_OVERHEAD (MM_SIZEOF_ALLOCNODE - sizeof(mmsize_t))
#endif

/* Get the node size */

Expand Down
6 changes: 6 additions & 0 deletions mm/mm_heap/mm_realloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,14 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem,
{
heap->mm_curused += newsize - oldsize;
mm_shrinkchunk(heap, oldnode, newsize);

#ifdef CONFIG_MM_NODE_PENDING
kasan_poison((FAR char *)oldnode + MM_SIZEOF_NODE(oldnode),
oldsize - MM_SIZEOF_NODE(oldnode));
#else
kasan_poison((FAR char *)oldnode + MM_SIZEOF_NODE(oldnode) +
sizeof(mmsize_t), oldsize - MM_SIZEOF_NODE(oldnode));
#endif
}

/* Then return the original address */
Expand Down

0 comments on commit 2549506

Please sign in to comment.