Skip to content

Commit

Permalink
mm: mm_malloc_size Switching using kasan_bypass_save
Browse files Browse the repository at this point in the history
Because it will be called in mm_lock and outside mm_unlock, it needs to keep the same state as before closing.

Signed-off-by: wangmingrong1 <[email protected]>
  • Loading branch information
W-M-R committed Jan 14, 2025
1 parent 5a66de8 commit a68993c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
8 changes: 4 additions & 4 deletions arch/arm64/include/memtag.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ void up_memtag_bypass(bool bypass);

/* Set memory tags for a given memory range */

void up_memtag_set_tag(const void *addr, size_t size);
void up_memtag_set_tag(FAR const void *addr, size_t size);

/* Get a random label based on the address through the mte register */

uint8_t up_memtag_get_random_tag(const void *addr);
uint8_t up_memtag_get_random_tag(FAR const void *addr);

/* Get the address without label */

FAR void *up_memtag_get_untagged_addr(const void *addr);
FAR void *up_memtag_get_untagged_addr(FAR const void *addr);

/* Get the address with label */

FAR void *up_memtag_get_tagged_addr(const void *addr, uint8_t tag);
FAR void *up_memtag_get_tagged_addr(FAR const void *addr, uint8_t tag);

#endif /* ___ARCH_ARM64_INCLUDE_MEMTAG_H */
10 changes: 5 additions & 5 deletions arch/arm64/src/common/arm64_mte.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static int mte_is_support(void)
return supported != 0;
}

static inline uint8_t mte_get_ptr_tag(const void *ptr)
static inline uint8_t mte_get_ptr_tag(FAR const void *ptr)
{
return 0xf0 | (uint8_t)(((uint64_t)(ptr)) >> MTE_TAG_SHIFT);
}
Expand All @@ -68,20 +68,20 @@ static inline uint8_t mte_get_ptr_tag(const void *ptr)
* Public Functions
****************************************************************************/

uint8_t up_memtag_get_random_tag(const void *addr)
uint8_t up_memtag_get_random_tag(FAR const void *addr)
{
asm("irg %0, %0" : "=r" (addr));

return mte_get_ptr_tag(addr);
}

FAR void *up_memtag_get_untagged_addr(const void *addr)
FAR void *up_memtag_get_untagged_addr(FAR const void *addr)
{
return (FAR void *)
(((uint64_t)(addr)) & ~((uint64_t)0xff << MTE_TAG_SHIFT));
}

FAR void *up_memtag_get_tagged_addr(const void *addr, uint8_t tag)
FAR void *up_memtag_get_tagged_addr(FAR const void *addr, uint8_t tag)
{
return (FAR void *)
(((uint64_t)(addr)) | ((uint64_t)tag << MTE_TAG_SHIFT));
Expand Down Expand Up @@ -116,7 +116,7 @@ void up_memtag_bypass(bool bypass)

/* Set memory tags for a given memory range */

void up_memtag_set_tag(const void *addr, size_t size)
void up_memtag_set_tag(FAR const void *addr, size_t size)
{
size_t i;

Expand Down
12 changes: 10 additions & 2 deletions mm/mm_heap/mm_malloc_size.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <assert.h>
#include <debug.h>

#include <nuttx/mm/kasan.h>
#include <nuttx/mm/mm.h>

#include "mm_heap/mm.h"
Expand All @@ -40,10 +41,14 @@
size_t mm_malloc_size(FAR struct mm_heap_s *heap, FAR void *mem)
{
FAR struct mm_freenode_s *node;
size_t size;
bool mte;

mte = kasan_bypass_save();
#ifdef CONFIG_MM_HEAP_MEMPOOL
if (heap->mm_mpool)
{
ssize_t size = mempool_multiple_alloc_size(heap->mm_mpool, mem);
size = mempool_multiple_alloc_size(heap->mm_mpool, mem);
if (size >= 0)
{
return size;
Expand All @@ -66,5 +71,8 @@ size_t mm_malloc_size(FAR struct mm_heap_s *heap, FAR void *mem)

DEBUGASSERT(MM_NODE_IS_ALLOC(node));

return MM_SIZEOF_NODE(node) - MM_ALLOCNODE_OVERHEAD;
size = MM_SIZEOF_NODE(node) - MM_ALLOCNODE_OVERHEAD;

kasan_bypass_restore(mte);
return size;
}

0 comments on commit a68993c

Please sign in to comment.