1
0
Fork 0
forked from nuttx/nuttx-update

mm: Add kmm_malloc_size and mm_malloc_size

make malloc_size implementation align with malloc

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I8d7781925f06e58a880437a16569dccbfd2ea035
This commit is contained in:
Xiang Xiao 2021-06-30 20:33:29 -07:00 committed by Masayuki Ishikawa
parent ddaa3e42b9
commit 75bfa4584c
9 changed files with 118 additions and 25 deletions

View file

@ -413,7 +413,7 @@ void mm_checkcorruption(FAR struct mm_heap_s *heap)
* Name: malloc_size
****************************************************************************/
size_t malloc_size(FAR void *mem)
size_t mm_malloc_size(FAR void *mem)
{
return host_malloc_size(mem);
}

View file

@ -73,6 +73,7 @@ extern "C"
#define kumm_calloc(n,s) calloc(n,s);
#define kumm_malloc(s) malloc(s)
#define kumm_malloc_size(p) malloc_size(p)
#define kumm_zalloc(s) zalloc(s)
#define kumm_realloc(p,s) realloc(p,s)
#define kumm_memalign(a,s) memalign(a,s)
@ -92,6 +93,7 @@ extern "C"
# define kmm_calloc(n,s) calloc(n,s);
# define kmm_malloc(s) malloc(s)
# define kmm_malloc_size(p) malloc_size(p)
# define kmm_zalloc(s) zalloc(s)
# define kmm_realloc(p,s) realloc(p,s)
# define kmm_memalign(a,s) memalign(a,s)

View file

@ -45,37 +45,41 @@
/* Domain-specific allocations */
# define lib_malloc(s) kmm_malloc(s)
# define lib_zalloc(s) kmm_zalloc(s)
# define lib_realloc(p,s) kmm_realloc(p,s)
# define lib_memalign(p,s) kmm_memalign(p,s)
# define lib_free(p) kmm_free(p)
# define lib_malloc(s) kmm_malloc(s)
# define lib_malloc_size(p) kmm_malloc_size(p)
# define lib_zalloc(s) kmm_zalloc(s)
# define lib_realloc(p,s) kmm_realloc(p,s)
# define lib_memalign(p,s) kmm_memalign(p,s)
# define lib_free(p) kmm_free(p)
/* User-accessible allocations */
# define lib_umalloc(s) kumm_malloc(s)
# define lib_uzalloc(s) kumm_zalloc(s)
# define lib_urealloc(p,s) kumm_realloc(p,s)
# define lib_umemalign(p,s) kumm_memalign(p,s)
# define lib_ufree(p) kumm_free(p)
# define lib_umalloc(s) kumm_malloc(s)
# define lib_umalloc_size(p) kumm_malloc_size(p)
# define lib_uzalloc(s) kumm_zalloc(s)
# define lib_urealloc(p,s) kumm_realloc(p,s)
# define lib_umemalign(p,s) kumm_memalign(p,s)
# define lib_ufree(p) kumm_free(p)
#else
/* Domain-specific allocations */
# define lib_malloc(s) malloc(s)
# define lib_zalloc(s) zalloc(s)
# define lib_realloc(p,s) realloc(p,s)
# define lib_memalign(p,s) memalign(p,s)
# define lib_free(p) free(p)
# define lib_malloc(s) malloc(s)
# define lib_malloc_size(p) malloc_size(p)
# define lib_zalloc(s) zalloc(s)
# define lib_realloc(p,s) realloc(p,s)
# define lib_memalign(p,s) memalign(p,s)
# define lib_free(p) free(p)
/* User-accessible allocations */
# define lib_umalloc(s) malloc(s)
# define lib_uzalloc(s) zalloc(s)
# define lib_urealloc(p,s) realloc(p,s)
# define lib_umemalign(p,s) memalign(p,s)
# define lib_ufree(p) free(p)
# define lib_umalloc(s) malloc(s)
# define lib_umalloc_size(p) malloc_size(p)
# define lib_uzalloc(s) zalloc(s)
# define lib_urealloc(p,s) realloc(p,s)
# define lib_umemalign(p,s) memalign(p,s)
# define lib_ufree(p) free(p)
#endif

View file

@ -193,6 +193,16 @@ FAR void *mm_malloc(FAR struct mm_heap_s *heap, size_t size);
FAR void *kmm_malloc(size_t size);
#endif
/* Functions contained in mm_malloc_size.c **********************************/
size_t mm_malloc_size(FAR void *mem);
/* Functions contained in kmm_malloc_size.c *********************************/
#ifdef CONFIG_MM_KERNEL_HEAP
size_t kmm_malloc_size(FAR void *mem);
#endif
/* Functions contained in mm_free.c *****************************************/
void mm_free(FAR struct mm_heap_s *heap, FAR void *mem);

View file

@ -22,7 +22,7 @@
ifeq ($(CONFIG_MM_KERNEL_HEAP),y)
CSRCS += kmm_initialize.c kmm_addregion.c
CSRCS += kmm_initialize.c kmm_addregion.c kmm_malloc_size.c
CSRCS += kmm_brkaddr.c kmm_calloc.c kmm_extend.c kmm_free.c kmm_mallinfo.c
CSRCS += kmm_malloc.c kmm_memalign.c kmm_realloc.c kmm_zalloc.c kmm_heapmember.c

View file

@ -0,0 +1,40 @@
/****************************************************************************
* mm/kmm_heap/kmm_malloc_size.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/mm/mm.h>
#ifdef CONFIG_MM_KERNEL_HEAP
/****************************************************************************
* Public Functions
****************************************************************************/
size_t kmm_malloc_size(FAR void *mem)
{
return mm_malloc_size(mem);
}
#endif /* CONFIG_MM_KERNEL_HEAP */

View file

@ -26,7 +26,6 @@
#include <assert.h>
#include <debug.h>
#include <malloc.h>
#include <nuttx/mm/mm.h>
@ -36,7 +35,7 @@
* Public Functions
****************************************************************************/
size_t malloc_size(FAR void *mem)
size_t mm_malloc_size(FAR void *mem)
{
FAR struct mm_freenode_s *node;

View file

@ -20,7 +20,7 @@
# User heap allocator
CSRCS += umm_globals.c umm_initialize.c umm_addregion.c
CSRCS += umm_globals.c umm_initialize.c umm_addregion.c umm_malloc_size.c
CSRCS += umm_brkaddr.c umm_calloc.c umm_extend.c umm_free.c umm_mallinfo.c
CSRCS += umm_malloc.c umm_memalign.c umm_realloc.c umm_zalloc.c umm_heapmember.c

View file

@ -0,0 +1,38 @@
/****************************************************************************
* mm/umm_heap/umm_malloc_size.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <malloc.h>
#include <nuttx/mm/mm.h>
/****************************************************************************
* Public Functions
****************************************************************************/
size_t malloc_size(FAR void *mem)
{
return mm_malloc_size(mem);
}