mm/: add mm_heapmember function and reimplement kmm_heapmember base on mm_heapmember since this function is very useful if multiple heaps exist.
This commit is contained in:
parent
377eb30129
commit
86eef8ce3a
8 changed files with 288 additions and 46 deletions
101
binfmt/binfmt_initialize.c
Normal file
101
binfmt/binfmt_initialize.c
Normal file
|
|
@ -0,0 +1,101 @@
|
||||||
|
/****************************************************************************
|
||||||
|
* binfmt/binfmt_initialize.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2018 Pinecone Inc. All rights reserved.
|
||||||
|
* Author: Xiang Xiao <xiaoxiang@pinecone.net>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <nuttx/binfmt/binfmt.h>
|
||||||
|
#include <nuttx/binfmt/builtin.h>
|
||||||
|
#include <nuttx/binfmt/elf.h>
|
||||||
|
#include <nuttx/binfmt/pcode.h>
|
||||||
|
#include <nuttx/binfmt/nxflat.h>
|
||||||
|
|
||||||
|
#ifndef CONFIG_BINFMT_DISABLE
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: binfmt_initialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* initialize binfmt subsystem
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void binfmt_initialize(void)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
#ifdef CONFIG_FS_BINFS
|
||||||
|
ret = builtin_initialize();
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
berr("ERROR: builtin_initialize failed: %d\n", ret);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_ELF
|
||||||
|
ret = elf_initialize();
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
berr("ERROR: elf_initialize failed: %d\n", ret);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_BINFMT_PCODE
|
||||||
|
ret = pcode_initialize();
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
berr("ERROR: pcode_initialize failed: %d\n", ret);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_NXFLAT
|
||||||
|
ret = nxflat_initialize();
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
berr("ERROR: nxflat_initialize failed: %d\n", ret);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
UNUSED(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* CONFIG_BINFMT_DISABLE */
|
||||||
|
|
@ -426,9 +426,17 @@ FAR void *mm_memalign(FAR struct mm_heap_s *heap, size_t alignment,
|
||||||
FAR void *kmm_memalign(size_t alignment, size_t size);
|
FAR void *kmm_memalign(size_t alignment, size_t size);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Functions contained in mm_heapmember.c ***********************************/
|
||||||
|
|
||||||
|
bool mm_heapmember(FAR struct mm_heap_s *heap, FAR void *mem);
|
||||||
|
|
||||||
|
/* Functions contained in mm_uheapmember.c **********************************/
|
||||||
|
|
||||||
|
bool umm_heapmember(FAR void *mem);
|
||||||
|
|
||||||
/* Functions contained in kmm_heapmember.c **********************************/
|
/* Functions contained in kmm_heapmember.c **********************************/
|
||||||
|
|
||||||
#if defined(CONFIG_MM_KERNEL_HEAP) && defined(CONFIG_DEBUG_FEATURES)
|
#ifdef CONFIG_MM_KERNEL_HEAP
|
||||||
bool kmm_heapmember(FAR void *mem);
|
bool kmm_heapmember(FAR void *mem);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,16 +39,12 @@ ifeq ($(CONFIG_MM_KERNEL_HEAP),y)
|
||||||
|
|
||||||
CSRCS += kmm_initialize.c kmm_addregion.c kmm_sem.c
|
CSRCS += kmm_initialize.c kmm_addregion.c kmm_sem.c
|
||||||
CSRCS += kmm_brkaddr.c kmm_calloc.c kmm_extend.c kmm_free.c kmm_mallinfo.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
|
CSRCS += kmm_malloc.c kmm_memalign.c kmm_realloc.c kmm_zalloc.c kmm_heapmember.c
|
||||||
|
|
||||||
ifeq ($(CONFIG_BUILD_KERNEL),y)
|
ifeq ($(CONFIG_BUILD_KERNEL),y)
|
||||||
CSRCS += kmm_sbrk.c
|
CSRCS += kmm_sbrk.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(CONFIG_DEBUG_FEATURES),y)
|
|
||||||
CSRCS += kmm_heapmember.c
|
|
||||||
endif
|
|
||||||
|
|
||||||
# Add the kernel heap directory to the build
|
# Add the kernel heap directory to the build
|
||||||
|
|
||||||
DEPPATH += --dep-path kmm_heap
|
DEPPATH += --dep-path kmm_heap
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@
|
||||||
|
|
||||||
#include <nuttx/mm/mm.h>
|
#include <nuttx/mm/mm.h>
|
||||||
|
|
||||||
#if defined(CONFIG_MM_KERNEL_HEAP) && defined(CONFIG_DEBUG_FEATURES)
|
#ifdef CONFIG_MM_KERNEL_HEAP
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
|
|
@ -67,42 +67,7 @@
|
||||||
|
|
||||||
bool kmm_heapmember(FAR void *mem)
|
bool kmm_heapmember(FAR void *mem)
|
||||||
{
|
{
|
||||||
#if CONFIG_MM_REGIONS > 1
|
return mm_heapmember(&g_kmmheap, mem);
|
||||||
int i;
|
|
||||||
|
|
||||||
/* A valid address from the kernel heap for this region would have to lie
|
|
||||||
* between the region's two guard nodes.
|
|
||||||
*/
|
|
||||||
|
|
||||||
for (i = 0; i < g_kmmheap.mm_nregions; i++)
|
|
||||||
{
|
|
||||||
if (mem > (FAR void *)g_kmmheap.mm_heapstart[i] &&
|
|
||||||
mem < (FAR void *)g_kmmheap.mm_heapend[i])
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The address does not like any any region assigned to kernel heap */
|
|
||||||
|
|
||||||
return false;
|
|
||||||
|
|
||||||
#else
|
|
||||||
/* A valid address from the kernel heap would have to lie between the
|
|
||||||
* two guard nodes.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (mem > (FAR void *)g_kmmheap.mm_heapstart[0] &&
|
|
||||||
mem < (FAR void *)g_kmmheap.mm_heapend[0])
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Otherwise, the address does not lie in the kernel heap */
|
|
||||||
|
|
||||||
return false;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_MM_KERNEL_HEAP && CONFIG_DEBUG_FEATURES */
|
#endif /* CONFIG_MM_KERNEL_HEAP */
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@
|
||||||
CSRCS += mm_initialize.c mm_sem.c mm_addfreechunk.c mm_size2ndx.c
|
CSRCS += mm_initialize.c mm_sem.c mm_addfreechunk.c mm_size2ndx.c
|
||||||
CSRCS += mm_shrinkchunk.c
|
CSRCS += mm_shrinkchunk.c
|
||||||
CSRCS += mm_brkaddr.c mm_calloc.c mm_extend.c mm_free.c mm_mallinfo.c
|
CSRCS += mm_brkaddr.c mm_calloc.c mm_extend.c mm_free.c mm_mallinfo.c
|
||||||
CSRCS += mm_malloc.c mm_memalign.c mm_realloc.c mm_zalloc.c
|
CSRCS += mm_malloc.c mm_memalign.c mm_realloc.c mm_zalloc.c mm_heapmember.c
|
||||||
|
|
||||||
ifeq ($(CONFIG_BUILD_KERNEL),y)
|
ifeq ($(CONFIG_BUILD_KERNEL),y)
|
||||||
CSRCS += mm_sbrk.c
|
CSRCS += mm_sbrk.c
|
||||||
|
|
|
||||||
103
mm/mm_heap/mm_heapmember.c
Normal file
103
mm/mm_heap/mm_heapmember.c
Normal file
|
|
@ -0,0 +1,103 @@
|
||||||
|
/****************************************************************************
|
||||||
|
* mm/mm_heap/mm_heapmember.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <nuttx/mm/mm.h>
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: mm_heapmember
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Check if an address lies in the heap.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* heap - The heap to check
|
||||||
|
* mem - The address to check
|
||||||
|
*
|
||||||
|
* Return Value:
|
||||||
|
* true if the address is a member of the heap. false if not
|
||||||
|
* not. If the address is not a member of the heap, then it
|
||||||
|
* must be a member of the user-space heap (unchecked)
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
bool mm_heapmember(FAR struct mm_heap_s *heap, FAR void *mem)
|
||||||
|
{
|
||||||
|
#if CONFIG_MM_REGIONS > 1
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/* A valid address from the heap for this region would have to lie
|
||||||
|
* between the region's two guard nodes.
|
||||||
|
*/
|
||||||
|
|
||||||
|
for (i = 0; i < heap->mm_nregions; i++)
|
||||||
|
{
|
||||||
|
if (mem > (FAR void *)heap->mm_heapstart[i] &&
|
||||||
|
mem < (FAR void *)heap->mm_heapend[i])
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The address does not like any any region assigned to the heap */
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
#else
|
||||||
|
/* A valid address from the heap would have to lie between the
|
||||||
|
* two guard nodes.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (mem > (FAR void *)heap->mm_heapstart[0] &&
|
||||||
|
mem < (FAR void *)heap->mm_heapend[0])
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Otherwise, the address does not lie in the heap */
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
@ -37,7 +37,7 @@
|
||||||
|
|
||||||
CSRCS += umm_initialize.c umm_addregion.c umm_sem.c
|
CSRCS += umm_initialize.c umm_addregion.c umm_sem.c
|
||||||
CSRCS += umm_brkaddr.c umm_calloc.c umm_extend.c umm_free.c umm_mallinfo.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
|
CSRCS += umm_malloc.c umm_memalign.c umm_realloc.c umm_zalloc.c umm_heapmember.c
|
||||||
CSRCS += umm_globals.c
|
CSRCS += umm_globals.c
|
||||||
|
|
||||||
ifeq ($(CONFIG_BUILD_KERNEL),y)
|
ifeq ($(CONFIG_BUILD_KERNEL),y)
|
||||||
|
|
|
||||||
69
mm/umm_heap/umm_heapmember.c
Normal file
69
mm/umm_heap/umm_heapmember.c
Normal file
|
|
@ -0,0 +1,69 @@
|
||||||
|
/****************************************************************************
|
||||||
|
* umm/umm_heap/umm_heapmember.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <nuttx/mm/mm.h>
|
||||||
|
|
||||||
|
#include "umm_heap/umm_heap.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: umm_heapmember
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Check if an address lies in the user heap.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* mem - The address to check
|
||||||
|
*
|
||||||
|
* Return Value:
|
||||||
|
* true if the address is a member of the user heap. false if not
|
||||||
|
* not. If the address is not a member of the user heap, then it
|
||||||
|
* must be a member of the user-space heap (unchecked)
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
bool umm_heapmember(FAR void *mem)
|
||||||
|
{
|
||||||
|
return mm_heapmember(USR_HEAP, mem);
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue