Skip to content

Commit 2549506

Browse files
committed
mm: Add CONFIG_MM_NODE_PENDING configuration
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]>
1 parent 0ae633c commit 2549506

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

mm/Kconfig

+8
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ config MM_DEFAULT_ALIGNMENT
6969
memory default alignment is equal to sizoef(uintptr), if this value
7070
is not 0, this value must be 2^n and at least sizeof(uintptr).
7171

72+
config MM_NODE_PENDING
73+
bool "Enable pending memory node"
74+
default n
75+
---help---
76+
After it is enabled, the "preceding" member will be retained
77+
forever regardless of whether the previous node is in the
78+
alloc state or the free state.
79+
7280
config MM_SMALL
7381
bool "Small memory model"
7482
default n

mm/mm_heap/mm.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,11 @@
143143
* previous freenode
144144
*/
145145

146-
#define MM_ALLOCNODE_OVERHEAD (MM_SIZEOF_ALLOCNODE - sizeof(mmsize_t))
146+
#ifdef CONFIG_MM_NODE_PENDING
147+
# define MM_ALLOCNODE_OVERHEAD (MM_SIZEOF_ALLOCNODE)
148+
#else
149+
# define MM_ALLOCNODE_OVERHEAD (MM_SIZEOF_ALLOCNODE - sizeof(mmsize_t))
150+
#endif
147151

148152
/* Get the node size */
149153

mm/mm_heap/mm_realloc.c

+6
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,14 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem,
152152
{
153153
heap->mm_curused += newsize - oldsize;
154154
mm_shrinkchunk(heap, oldnode, newsize);
155+
156+
#ifdef CONFIG_MM_NODE_PENDING
157+
kasan_poison((FAR char *)oldnode + MM_SIZEOF_NODE(oldnode),
158+
oldsize - MM_SIZEOF_NODE(oldnode));
159+
#else
155160
kasan_poison((FAR char *)oldnode + MM_SIZEOF_NODE(oldnode) +
156161
sizeof(mmsize_t), oldsize - MM_SIZEOF_NODE(oldnode));
162+
#endif
157163
}
158164

159165
/* Then return the original address */

0 commit comments

Comments
 (0)