mm:add heap args to mm_malloc_size
use malloc_size inside of where used mm_malloc_size Signed-off-by: anjiahao <anjiahao@xiaomi.com> Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
parent
3d7629a02c
commit
bc30b294aa
13 changed files with 36 additions and 27 deletions
|
@ -435,7 +435,7 @@ void mm_checkcorruption(struct mm_heap_s *heap)
|
|||
* Name: malloc_size
|
||||
****************************************************************************/
|
||||
|
||||
size_t mm_malloc_size(void *mem)
|
||||
size_t mm_malloc_size(FAR struct mm_heap_s *heap, FAR void *mem)
|
||||
{
|
||||
return host_mallocsize(mem);
|
||||
}
|
||||
|
|
|
@ -362,6 +362,7 @@ void mempool_multiple_free(FAR struct mempool_multiple_s *mpool,
|
|||
* Get size of memory block from multiple memory.
|
||||
*
|
||||
* Input Parameters:
|
||||
* mpool - The handle of multiple memory pool to be used.
|
||||
* blk - The pointer of memory block.
|
||||
*
|
||||
* Returned Value:
|
||||
|
@ -369,7 +370,8 @@ void mempool_multiple_free(FAR struct mempool_multiple_s *mpool,
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
size_t mempool_multiple_alloc_size(FAR void *blk);
|
||||
size_t mempool_multiple_alloc_size(FAR struct mempool_multiple_s *mpool,
|
||||
FAR void *blk);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mempool_multiple_memalign
|
||||
|
|
|
@ -196,7 +196,7 @@ FAR void *kmm_malloc(size_t size) malloc_like1(1);
|
|||
|
||||
/* Functions contained in mm_malloc_size.c **********************************/
|
||||
|
||||
size_t mm_malloc_size(FAR void *mem);
|
||||
size_t mm_malloc_size(FAR struct mm_heap_s *heap, FAR void *mem);
|
||||
|
||||
/* Functions contained in kmm_malloc_size.c *********************************/
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
|
||||
size_t kmm_malloc_size(FAR void *mem)
|
||||
{
|
||||
return mm_malloc_size(mem);
|
||||
return mm_malloc_size(g_kmmheap, mem);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_MM_KERNEL_HEAP */
|
||||
|
|
|
@ -581,7 +581,7 @@ int mempool_deinit(FAR struct mempool_s *pool)
|
|||
{
|
||||
blk = (FAR struct list_node *)((FAR char *)blk -
|
||||
count * blocksize);
|
||||
kasan_unpoison(blk, mm_malloc_size(blk));
|
||||
kasan_unpoison(blk, blocksize);
|
||||
mempool_mfree(pool, blk);
|
||||
count = pool->expandsize / blocksize;
|
||||
}
|
||||
|
|
|
@ -272,6 +272,7 @@ void mempool_multiple_free(FAR struct mempool_multiple_s *mpool,
|
|||
* Get size of memory block from multiple memory.
|
||||
*
|
||||
* Input Parameters:
|
||||
* mpool - The handle of multiple memory pool to be used.
|
||||
* blk - The pointer of memory block.
|
||||
*
|
||||
* Returned Value:
|
||||
|
@ -279,7 +280,8 @@ void mempool_multiple_free(FAR struct mempool_multiple_s *mpool,
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
size_t mempool_multiple_alloc_size(FAR void *blk)
|
||||
size_t mempool_multiple_alloc_size(FAR struct mempool_multiple_s *mpool,
|
||||
FAR void *blk)
|
||||
{
|
||||
FAR struct mempool_s *pool;
|
||||
FAR char *mem;
|
||||
|
|
|
@ -101,7 +101,7 @@ void mm_free(FAR struct mm_heap_s *heap, FAR void *mem)
|
|||
return;
|
||||
}
|
||||
|
||||
kasan_poison(mem, mm_malloc_size(mem));
|
||||
kasan_poison(mem, mm_malloc_size(heap, mem));
|
||||
|
||||
DEBUGASSERT(mm_heapmember(heap, mem));
|
||||
|
||||
|
|
|
@ -246,7 +246,7 @@ FAR void *mm_malloc(FAR struct mm_heap_s *heap, size_t size)
|
|||
if (ret)
|
||||
{
|
||||
MM_ADD_BACKTRACE(heap, node);
|
||||
kasan_unpoison(ret, mm_malloc_size(ret));
|
||||
kasan_unpoison(ret, mm_malloc_size(heap, ret));
|
||||
#ifdef CONFIG_MM_FILL_ALLOCATIONS
|
||||
memset(ret, 0xaa, alignsize - SIZEOF_MM_ALLOCNODE);
|
||||
#endif
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
size_t mm_malloc_size(FAR void *mem)
|
||||
size_t mm_malloc_size(FAR struct mm_heap_s *heap, FAR void *mem)
|
||||
{
|
||||
FAR struct mm_freenode_s *node;
|
||||
|
||||
|
@ -49,7 +49,7 @@ size_t mm_malloc_size(FAR void *mem)
|
|||
#if CONFIG_MM_HEAP_MEMPOOL_THRESHOLD != 0
|
||||
if (MM_IS_FROM_MEMPOOL(mem))
|
||||
{
|
||||
return mempool_multiple_alloc_size(mem);
|
||||
return mempool_multiple_alloc_size(&heap->mm_mpool, mem);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -121,7 +121,8 @@ FAR void *mm_memalign(FAR struct mm_heap_s *heap, size_t alignment,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
kasan_poison((FAR void *)rawchunk, mm_malloc_size((FAR void *)rawchunk));
|
||||
kasan_poison((FAR void *)rawchunk,
|
||||
mm_malloc_size(heap, (FAR void *)rawchunk));
|
||||
|
||||
/* We need to hold the MM mutex while we muck with the chunks and
|
||||
* nodelist.
|
||||
|
@ -235,7 +236,7 @@ FAR void *mm_memalign(FAR struct mm_heap_s *heap, size_t alignment,
|
|||
MM_ADD_BACKTRACE(heap, node);
|
||||
|
||||
kasan_unpoison((FAR void *)alignedchunk,
|
||||
mm_malloc_size((FAR void *)alignedchunk));
|
||||
mm_malloc_size(heap, (FAR void *)alignedchunk));
|
||||
|
||||
DEBUGASSERT(alignedchunk % alignment == 0);
|
||||
return (FAR void *)alignedchunk;
|
||||
|
|
|
@ -106,7 +106,8 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem,
|
|||
newmem = mm_malloc(heap, size);
|
||||
if (newmem != NULL)
|
||||
{
|
||||
memcpy(newmem, oldmem, mempool_multiple_alloc_size(oldmem));
|
||||
memcpy(newmem, oldmem,
|
||||
mempool_multiple_alloc_size(&heap->mm_mpool, oldmem));
|
||||
mempool_multiple_free(&heap->mm_mpool, oldmem);
|
||||
}
|
||||
|
||||
|
@ -117,7 +118,7 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem,
|
|||
newmem = mempool_multiple_alloc(&heap->mm_mpool, size);
|
||||
if (newmem != NULL)
|
||||
{
|
||||
memcpy(newmem, oldmem, MIN(size, mm_malloc_size(oldmem)));
|
||||
memcpy(newmem, oldmem, MIN(size, mm_malloc_size(heap, oldmem)));
|
||||
mm_free(heap, oldmem);
|
||||
return newmem;
|
||||
}
|
||||
|
@ -373,7 +374,7 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem,
|
|||
mm_unlock(heap);
|
||||
MM_ADD_BACKTRACE(heap, (FAR char *)newmem - SIZEOF_MM_ALLOCNODE);
|
||||
|
||||
kasan_unpoison(newmem, mm_malloc_size(newmem));
|
||||
kasan_unpoison(newmem, mm_malloc_size(heap, newmem));
|
||||
if (newmem != oldmem)
|
||||
{
|
||||
/* Now we have to move the user contents 'down' in memory. memcpy
|
||||
|
|
|
@ -661,7 +661,7 @@ void mm_free(FAR struct mm_heap_s *heap, FAR void *mem)
|
|||
|
||||
if (mm_lock(heap) == 0)
|
||||
{
|
||||
kasan_poison(mem, mm_malloc_size(mem));
|
||||
kasan_poison(mem, mm_malloc_size(heap, mem));
|
||||
|
||||
/* Pass, return to the tlsf pool */
|
||||
|
||||
|
@ -950,12 +950,12 @@ void mm_memdump(FAR struct mm_heap_s *heap, pid_t pid)
|
|||
* Name: mm_malloc_size
|
||||
****************************************************************************/
|
||||
|
||||
size_t mm_malloc_size(FAR void *mem)
|
||||
size_t mm_malloc_size(FAR struct mm_heap_s *heap, FAR void *mem)
|
||||
{
|
||||
#if CONFIG_MM_HEAP_MEMPOOL_THRESHOLD != 0
|
||||
if (MM_IS_FROM_MEMPOOL(mem))
|
||||
{
|
||||
return mempool_multiple_alloc_size(mem);
|
||||
return mempool_multiple_alloc_size(&heap->mm_mpool, mem);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1008,11 +1008,11 @@ FAR void *mm_malloc(FAR struct mm_heap_s *heap, size_t size)
|
|||
if (ret)
|
||||
{
|
||||
#if CONFIG_MM_BACKTRACE >= 0
|
||||
FAR struct memdump_backtrace_s *dump = ret + mm_malloc_size(ret);
|
||||
FAR struct memdump_backtrace_s *dump = ret + mm_malloc_size(heap, ret);
|
||||
|
||||
memdump_backtrace(heap, dump);
|
||||
#endif
|
||||
kasan_unpoison(ret, mm_malloc_size(ret));
|
||||
kasan_unpoison(ret, mm_malloc_size(heap, ret));
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -1062,11 +1062,11 @@ FAR void *mm_memalign(FAR struct mm_heap_s *heap, size_t alignment,
|
|||
if (ret)
|
||||
{
|
||||
#if CONFIG_MM_BACKTRACE >= 0
|
||||
FAR struct memdump_backtrace_s *dump = ret + mm_malloc_size(ret);
|
||||
FAR struct memdump_backtrace_s *dump = ret + mm_malloc_size(heap, ret);
|
||||
|
||||
memdump_backtrace(heap, dump);
|
||||
#endif
|
||||
kasan_unpoison(ret, mm_malloc_size(ret));
|
||||
kasan_unpoison(ret, mm_malloc_size(heap, ret));
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -1134,7 +1134,7 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem,
|
|||
newmem = mempool_multiple_alloc(&heap->mm_mpool, size);
|
||||
if (newmem != NULL)
|
||||
{
|
||||
memcpy(newmem, oldmem, MIN(size, mm_malloc_size(oldmem)));
|
||||
memcpy(newmem, oldmem, MIN(size, mm_malloc_size(heap, oldmem)));
|
||||
mm_free(heap, oldmem);
|
||||
return newmem;
|
||||
}
|
||||
|
@ -1146,9 +1146,9 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem,
|
|||
newmem = mm_malloc(heap, size);
|
||||
if (newmem)
|
||||
{
|
||||
if (size > mm_malloc_size(oldmem))
|
||||
if (size > mm_malloc_size(heap, oldmem))
|
||||
{
|
||||
size = mm_malloc_size(oldmem);
|
||||
size = mm_malloc_size(heap, oldmem);
|
||||
}
|
||||
|
||||
memcpy(newmem, oldmem, size);
|
||||
|
@ -1173,7 +1173,8 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem,
|
|||
#if CONFIG_MM_BACKTRACE >= 0
|
||||
if (newmem)
|
||||
{
|
||||
FAR struct memdump_backtrace_s *dump = newmem + mm_malloc_size(newmem);
|
||||
FAR struct memdump_backtrace_s *dump = newmem +
|
||||
mm_malloc_size(heap, newmem);
|
||||
|
||||
memdump_backtrace(heap, dump);
|
||||
}
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
|
||||
#include <nuttx/mm/mm.h>
|
||||
|
||||
#include "umm_heap.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
@ -35,5 +37,5 @@
|
|||
#undef malloc_size /* See mm/README.txt */
|
||||
size_t malloc_size(FAR void *mem)
|
||||
{
|
||||
return mm_malloc_size(mem);
|
||||
return mm_malloc_size(USR_HEAP, mem);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue