Remove CONFIG_MM_MULTIHEAP. Non-multiheap operation is no longer supported

This commit is contained in:
Gregory Nutt
2014-08-31 10:54:55 -06:00
parent 0571a59e12
commit 3c1a70c9dc
260 changed files with 1184 additions and 622 deletions
+1 -19
View File
@@ -3,22 +3,10 @@
# see misc/tools/kconfig-language.txt.
#
config MM_MULTIHEAP
bool "Build support for multiple heaps"
default n
---help---
Build interfaces to support multiple heaps. This should not be
confused with memory regions. One heap may be composed of multiple,
non-contiguous memory regions. The fact that the heap is composed
of such multiple regions is invisible to the end-user (other than
the heap comes pre-fragmented). Multiple heaps, on the other hand,
supports a separate set of allocators that operate on a separate set
of memory regions.
config MM_KERNEL_HEAP
bool "Support a protected, kernel heap"
default y
depends on (BUILD_PROTECTED && MM_MULTIHEAP) || BUILD_KERNEL
depends on BUILD_PROTECTED || BUILD_KERNEL
---help---
Partition heap memory into two parts: (1) a protected, kernel-mode
heap accessible only by the NuttX kernel, and (2) an unprotected
@@ -62,9 +50,6 @@ config MM_SMALL
only 4-byte alignment. This may be important on some platforms where
64-bit data is in allocated structures and 8-byte alignment is required.
NOTE: If MM_MULTIHEAP is selected, then this selection applies to all
heaps.
config MM_REGIONS
int "Number of memory regions"
default 1
@@ -74,9 +59,6 @@ config MM_REGIONS
that the memory manager must handle and enables the API
mm_addregion(heap, start, end);
NOTE: If MM_MULTIHEAP is selected, then this maximum number of regions
applies to all heaps.
config ARCH_HAVE_HEAP2
bool
default n
+12 -12
View File
@@ -51,23 +51,23 @@ endif
# Core allocator logic
ASRCS =
CSRCS = mm_initialize.c mm_sem.c mm_addfreechunk.c mm_size2ndx.c
CSRCS += mm_shrinkchunk.c mm_malloc.c mm_zalloc.c mm_calloc.c mm_realloc.c
CSRCS += mm_memalign.c mm_free.c mm_mallinfo.c
CSRCS = mm_initialize.c mm_sem.c mm_addfreechunk.c mm_size2ndx.c
CSRCS += mm_shrinkchunk.c
CSRCS += mm_calloc.c mm_free.c mm_mallinfo.c mm_malloc.c mm_memalign.c
CSRCS += mm_realloc.c mm_zalloc.c
# Allocator instances
# User allocator
CSRCS += mm_user.c
ifeq ($(CONFIG_BUILD_PROTECTED),y)
CSRCS += umm_calloc.c umm_free.c umm_mallinfo.c umm_malloc.c
CSRCS += umm_memalign.c umm_realloc.c umm_zalloc.c
# Kernel allocator
ifeq ($(CONFIG_MM_KERNEL_HEAP),y)
CSRCS += mm_kernel.c
endif
else
ifeq ($(CONFIG_BUILD_KERNEL),y)
ifeq ($(CONFIG_MM_KERNEL_HEAP),y)
CSRCS += mm_kernel.c
endif
endif
CSRCS += kmm_calloc.c kmm_free.c kmm_mallinfo.c kmm_malloc.c
CSRCS += kmm_memalign.c kmm_realloc.c kmm_zalloc.c
endif
# An optional granule allocator
+67
View File
@@ -0,0 +1,67 @@
/****************************************************************************
* mm/kmm_calloc.c
*
* Copyright (C) 2014 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.h>
#ifdef CONFIG_MM_KERNEL_HEAP
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: kmm_calloc
*
* Description:
* kmm_calloc is a thin wrapper for mm_calloc()
*
****************************************************************************/
FAR void *kmm_calloc(size_t n, size_t elem_size)
{
return mm_calloc(&g_kmmheap, n, elem_size);
}
#endif /* CONFIG_MM_KERNEL_HEAP */
+82
View File
@@ -0,0 +1,82 @@
/****************************************************************************
* mm/kmm_free.c
*
* Copyright (C) 2007, 2009, 2013-2014 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 <assert.h>
#include <debug.h>
#include <nuttx/mm.h>
#ifdef CONFIG_MM_KERNEL_HEAP
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/************************************************************************
* Name: kfree
*
* Description:
* Returns a chunk of kernel memory to the list of free nodes, merging
* with adjacent free chunks if possible.
*
* Parameters:
* None
*
* Return Value:
* None
*
************************************************************************/
void kfree(FAR void *mem)
{
DEBUGASSERT(kmm_heapmember(mem));
mm_free(&g_kmmheap, mem);
}
#endif /* CONFIG_MM_KERNEL_HEAP */
+90
View File
@@ -0,0 +1,90 @@
/****************************************************************************
* mm/kmm_mallinfo.c
*
* Copyright (C) 2014 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 <stdlib.h>
#include <nuttx/mm.h>
#ifdef CONFIG_MM_KERNEL_HEAP
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: kmm_mallinfo
*
* Description:
* kmm_mallinfo returns a copy of updated current heap information for the
* kernel heap
*
****************************************************************************/
#ifdef CONFIG_CAN_PASS_STRUCTS
struct mallinfo kmm_mallinfo(void)
{
struct mallinfo info;
mm_mallinfo(&g_kmmheap, &info);
return info;
}
#else
int kmm_mallinfo(struct mallinfo *info)
{
return mm_mallinfo(&g_kmmheap, info);
}
#endif /* CONFIG_CAN_PASS_STRUCTS */
#endif /* CONFIG_MM_KERNEL_HEAP */
+89
View File
@@ -0,0 +1,89 @@
/****************************************************************************
* mm/kmm_malloc.c
*
* Copyright (C) 2014 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.h>
#ifdef CONFIG_MM_KERNEL_HEAP
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Type Definitions
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/************************************************************************
* Name: kmalloc
*
* Description:
* Allocate memory from the kernel heap.
*
* Parameters:
* size - Size (in bytes) of the memory region to be allocated.
*
* Return Value:
* The address of the allocated memory (NULL on failure to allocate)
*
************************************************************************/
FAR void *kmalloc(size_t size)
{
return mm_malloc(&g_kmmheap, size);
}
#endif /* CONFIG_MM_KERNEL_HEAP */
+80
View File
@@ -0,0 +1,80 @@
/****************************************************************************
* mm/kmm_memalign.c
*
* Copyright (C) 2014 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 <stdlib.h>
#include <nuttx/mm.h>
#ifdef CONFIG_MM_KERNEL_HEAP
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/************************************************************************
* Name: kmemalign
*
* Description:
* Allocate aligned memory in the kernel heap.
*
* Parameters:
* alignment - Log2 byte alignment
* size - Size (in bytes) of the new memory region to be allocated.
*
* Return Value:
* The address of the re-allocated memory (NULL on failure to allocate)
*
************************************************************************/
FAR void *kmemalign(size_t alignment, size_t size)
{
return mm_memalign(&g_kmmheap, alignment, size);
}
#endif /* CONFIG_MM_KERNEL_HEAP */
+78
View File
@@ -0,0 +1,78 @@
/****************************************************************************
* mm/kmm_realloc.c
*
* Copyright (C) 2014 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.h>
#ifdef CONFIG_MM_KERNEL_HEAP
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: krealloc
*
* Description:
* Re-allocate memory in the kernel heap.
*
* Parameters:
* oldmem - The old memory allocated
* newsize - Size (in bytes) of the new memory region to be re-allocated.
*
* Return Value:
* The address of the re-allocated memory (NULL on failure to re-allocate)
*
****************************************************************************/
FAR void *krealloc(FAR void *oldmem, size_t newsize)
{
return mm_realloc(&g_kmmheap, oldmem, newsize);
}
#endif /* CONFIG_MM_KERNEL_HEAP */
+73
View File
@@ -0,0 +1,73 @@
/****************************************************************************
* mm/kmm_zalloc.c
*
* Copyright (C) 2014 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.h>
#ifdef CONFIG_MM_KERNEL_HEAP
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/************************************************************************
* Name: kzalloc
*
* Description:
* Allocate and zero memory from the kernel heap.
*
* Parameters:
* size - Size (in bytes) of the memory region to be allocated.
*
* Return Value:
* The address of the allocated memory (NULL on failure to allocate)
*
************************************************************************/
FAR void *kzalloc(size_t size)
{
return mm_zalloc(&g_kmmheap, size);
}
#endif /* CONFIG_MM_KERNEL_HEAP */
+3 -33
View File
@@ -39,8 +39,6 @@
#include <nuttx/config.h>
#include <stdlib.h>
#include <nuttx/mm.h>
/****************************************************************************
@@ -48,18 +46,17 @@
****************************************************************************/
/****************************************************************************
* Global Functions
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: mm_calloc
*
* Descripton:
* calloc calculates the size of the allocation and calls zalloc
* Descriptor:
* mm_calloc() calculates the size of the allocation and calls mm_zalloc()
*
****************************************************************************/
#ifdef CONFIG_MM_MULTIHEAP
FAR void *mm_calloc(FAR struct mm_heap_s *heap, size_t n, size_t elem_size)
{
FAR void *ret = NULL;
@@ -71,30 +68,3 @@ FAR void *mm_calloc(FAR struct mm_heap_s *heap, size_t n, size_t elem_size)
return ret;
}
#endif
/****************************************************************************
* Name: calloc
*
* Descripton:
* calloc calculates the size of the allocation and calls zalloc
*
****************************************************************************/
#ifdef CONFIG_MM_USER_HEAP
FAR void *calloc(size_t n, size_t elem_size)
{
#ifdef CONFIG_MM_MULTIHEAP
return mm_calloc(&g_mmheap, n, elem_size);
#else
FAR void *ret = NULL;
if (n > 0 && elem_size > 0)
{
ret = zalloc(n * elem_size);
}
return ret;
#endif
}
#endif
+4 -24
View File
@@ -39,7 +39,6 @@
#include <nuttx/config.h>
#include <stdlib.h>
#include <assert.h>
#include <debug.h>
@@ -53,6 +52,10 @@
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: mm_free
*
@@ -62,9 +65,6 @@
*
****************************************************************************/
#ifndef CONFIG_MM_MULTIHEAP
static inline
#endif
void mm_free(FAR struct mm_heap_s *heap, FAR void *mem)
{
FAR struct mm_freenode_s *node;
@@ -153,23 +153,3 @@ void mm_free(FAR struct mm_heap_s *heap, FAR void *mem)
mm_addfreechunk(heap, node);
mm_givesemaphore(heap);
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: free
*
* Description:
* Returns a chunk of memory to the list of free nodes, merging with
* adjacent free chunks if possible.
*
****************************************************************************/
#ifdef CONFIG_MM_USER_HEAP
void free(FAR void *mem)
{
mm_free(&g_mmheap, mem);
}
#endif
-98
View File
@@ -111,104 +111,6 @@ void kmm_addregion(FAR void *heap_start, size_t heap_size)
return mm_addregion(&g_kmmheap, heap_start, heap_size);
}
/************************************************************************
* Name: kmalloc
*
* Description:
* Allocate memory from the kernel heap.
*
* Parameters:
* size - Size (in bytes) of the memory region to be allocated.
*
* Return Value:
* The address of the allocated memory (NULL on failure to allocate)
*
************************************************************************/
FAR void *kmalloc(size_t size)
{
return mm_malloc(&g_kmmheap, size);
}
/************************************************************************
* Name: kzalloc
*
* Description:
* Allocate and zero memory from the kernel heap.
*
* Parameters:
* size - Size (in bytes) of the memory region to be allocated.
*
* Return Value:
* The address of the allocated memory (NULL on failure to allocate)
*
************************************************************************/
FAR void *kzalloc(size_t size)
{
return mm_zalloc(&g_kmmheap, size);
}
/************************************************************************
* Name: krealloc
*
* Description:
* Re-allocate memory in the kernel heap.
*
* Parameters:
* oldmem - The old memory allocated
* newsize - Size (in bytes) of the new memory region to be re-allocated.
*
* Return Value:
* The address of the re-allocated memory (NULL on failure to re-allocate)
*
************************************************************************/
FAR void *krealloc(FAR void *oldmem, size_t newsize)
{
return mm_realloc(&g_kmmheap, oldmem, newsize);
}
/************************************************************************
* Name: kmemalign
*
* Description:
* Allocate aligned memory in the kernel heap.
*
* Parameters:
* alignment - Log2 byte alignment
* size - Size (in bytes) of the new memory region to be allocated.
*
* Return Value:
* The address of the re-allocated memory (NULL on failure to allocate)
*
************************************************************************/
FAR void *kmemalign(size_t alignment, size_t size)
{
return mm_memalign(&g_kmmheap, alignment, size);
}
/************************************************************************
* Name: kfree
*
* Description:
* Return allocated memory to the kernel heap.
*
* Parameters:
* None
*
* Return Value:
* None
*
************************************************************************/
void kfree(FAR void *mem)
{
DEBUGASSERT(kmm_heapmember(mem));
return mm_free(&g_kmmheap, mem);
}
/************************************************************************
* Name: kmm_trysemaphore
*
+4 -37
View File
@@ -57,6 +57,10 @@
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: mm_mallinfo
*
@@ -65,9 +69,6 @@
*
****************************************************************************/
#ifndef CONFIG_MM_MULTIHEAP
static inline
#endif
int mm_mallinfo(FAR struct mm_heap_s *heap, FAR struct mallinfo *info)
{
struct mm_allocnode_s *node;
@@ -137,37 +138,3 @@ int mm_mallinfo(FAR struct mm_heap_s *heap, FAR struct mallinfo *info)
info->fordblks = fordblks;
return OK;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: kmallinfo and mallinfo
*
* Description:
* mallinfo returns a copy of updated current heap information for either
* the user heap (mallinfo) or the kernel heap (kmallinfo).
*
****************************************************************************/
#ifdef CONFIG_MM_USER_HEAP
# ifdef CONFIG_CAN_PASS_STRUCTS
struct mallinfo mallinfo(void)
{
struct mallinfo info;
mm_mallinfo(&g_mmheap, &info);
return info;
}
# else
int mallinfo(struct mallinfo *info)
{
return mm_mallinfo(&g_mmheap, info);
}
#endif
#endif /* CONFIG_MM_USER_HEAP */
+4 -27
View File
@@ -39,7 +39,6 @@
#include <nuttx/config.h>
#include <stdlib.h>
#include <assert.h>
#include <debug.h>
@@ -69,6 +68,10 @@
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: mm_malloc
*
@@ -80,9 +83,6 @@
*
****************************************************************************/
#ifndef CONFIG_MM_MULTIHEAP
static inline
#endif
FAR void *mm_malloc(FAR struct mm_heap_s *heap, size_t size)
{
FAR struct mm_freenode_s *node;
@@ -212,26 +212,3 @@ FAR void *mm_malloc(FAR struct mm_heap_s *heap, size_t size)
return ret;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: malloc
*
* Description:
* Find the smallest chunk that satisfies the request. Take the memory from
* that chunk, save the remaining, smaller chunk (if any).
*
* 8-byte alignment of the allocated data is assured.
*
****************************************************************************/
#ifdef CONFIG_MM_USER_HEAP
FAR void *malloc(size_t size)
{
return mm_malloc(&g_mmheap, size);
}
#endif
+7 -41
View File
@@ -39,7 +39,6 @@
#include <nuttx/config.h>
#include <stdlib.h>
#include <assert.h>
#include <nuttx/mm.h>
@@ -47,21 +46,15 @@
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* If multiple heaps are used, then the heap must be passed as a parameter to
* mm_malloc(). In the single heap case, mm_malloc() is not available and
* we have to use malloc() (which, internally, will use the same heap).
*/
#ifdef CONFIG_MM_MULTIHEAP
# define MM_MALLOC(h,s) mm_malloc(h,s)
#else
# define MM_MALLOC(h,s) malloc(s)
#endif
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: mm_memalign
*
@@ -75,9 +68,6 @@
*
****************************************************************************/
#ifndef CONFIG_MM_MULTIHEAP
static inline
#endif
FAR void *mm_memalign(FAR struct mm_heap_s *heap, size_t alignment,
size_t size)
{
@@ -87,13 +77,13 @@ FAR void *mm_memalign(FAR struct mm_heap_s *heap, size_t alignment,
size_t mask = (size_t)(alignment - 1);
size_t allocsize;
/* If this requested alignement less than or equal to the natural alignment
/* If this requested alinement's less than or equal to the natural alignment
* of malloc, then just let malloc do the work.
*/
if (alignment <= MM_MIN_CHUNK)
{
return MM_MALLOC(heap, size);
return mm_malloc(heap, size);
}
/* Adjust the size to account for (1) the size of the allocated node, (2)
@@ -113,7 +103,7 @@ FAR void *mm_memalign(FAR struct mm_heap_s *heap, size_t alignment,
/* Then malloc that size */
rawchunk = (size_t)MM_MALLOC(heap, allocsize);
rawchunk = (size_t)mm_malloc(heap, allocsize);
if (rawchunk == 0)
{
return NULL;
@@ -222,27 +212,3 @@ FAR void *mm_memalign(FAR struct mm_heap_s *heap, size_t alignment,
mm_givesemaphore(heap);
return (FAR void*)alignedchunk;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: memalign
*
* Description:
* memalign requests more than enough space from malloc, finds a region
* within that chunk that meets the alignment request and then frees any
* leading or trailing space.
*
* The alignment argument must be a power of two (not checked). 8-byte
* alignment is guaranteed by normal malloc calls.
*
****************************************************************************/
#ifdef CONFIG_MM_USER_HEAP
FAR void *memalign(size_t alignment, size_t size)
{
return mm_memalign(&g_mmheap, alignment, size);
}
#endif
+8 -54
View File
@@ -49,24 +49,15 @@
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* If multiple heaps are used, then the heap must be passed as a parameter to
* mm_malloc() and mm_free(). In the single heap case, mm_malloc() and
* mm_free() are not available and we have to use malloc() and free() (which,
* internally, will use the same heap).
*/
#ifdef CONFIG_MM_MULTIHEAP
# define MM_MALLOC(h,s) mm_malloc(h,s)
# define MM_FREE(h,m) mm_free(h,m)
#else
# define MM_MALLOC(h,s) malloc(s)
# define MM_FREE(h,m) free(m)
#endif
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: mm_realloc
*
@@ -90,9 +81,6 @@
*
****************************************************************************/
#ifndef CONFIG_MM_MULTIHEAP
static inline
#endif
FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem,
size_t size)
{
@@ -108,14 +96,14 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem,
if (!oldmem)
{
return MM_MALLOC(heap, size);
return mm_malloc(heap, size);
}
/* If size is zero, then realloc is equivalent to free */
if (size <= 0)
{
MM_FREE(heap, oldmem);
mm_free(heap, oldmem);
return NULL;
}
@@ -361,47 +349,13 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem,
*/
mm_givesemaphore(heap);
newmem = (FAR void*)MM_MALLOC(heap, size);
newmem = (FAR void*)mm_malloc(heap, size);
if (newmem)
{
memcpy(newmem, oldmem, oldsize);
MM_FREE(heap, oldmem);
mm_free(heap, oldmem);
}
return newmem;
}
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: realloc
*
* Description:
* If the reallocation is for less space, then:
*
* (1) the current allocation is reduced in size
* (2) the remainder at the end of the allocation is returned to the
* free list.
*
* If the request is for more space and the current allocation can be
* extended, it will be extended by:
*
* (1) Taking the additional space from the following free chunk, or
* (2) Taking the additional space from the preceding free chunk.
* (3) Or both
*
* If the request is for more space but the current chunk cannot be
* extended, then malloc a new buffer, copy the data into the new buffer,
* and free the old buffer.
*
****************************************************************************/
#ifdef CONFIG_MM_USER_HEAP
FAR void *realloc(FAR void *oldmem, size_t size)
{
return mm_realloc(&g_mmheap, oldmem, size);
}
#endif
-28
View File
@@ -39,7 +39,6 @@
#include <nuttx/config.h>
#include <stdlib.h>
#include <string.h>
#include <nuttx/mm.h>
@@ -60,7 +59,6 @@
*
****************************************************************************/
#ifdef CONFIG_MM_MULTIHEAP
FAR void *mm_zalloc(FAR struct mm_heap_s *heap, size_t size)
{
FAR void *alloc = mm_malloc(heap, size);
@@ -71,29 +69,3 @@ FAR void *mm_zalloc(FAR struct mm_heap_s *heap, size_t size)
return alloc;
}
#endif
/****************************************************************************
* Name: zalloc
*
* Description:
* zalloc calls malloc, then zeroes out the allocated chunk.
*
****************************************************************************/
#ifdef CONFIG_MM_USER_HEAP
FAR void *zalloc(size_t size)
{
#ifdef CONFIG_MM_MULTIHEAP
return mm_zalloc(&g_mmheap, size);
#else
FAR void *alloc = malloc(size);
if (alloc)
{
memset(alloc, 0, size);
}
return alloc;
#endif
}
#endif
+69
View File
@@ -0,0 +1,69 @@
/****************************************************************************
* mm/umm_calloc.c
*
* Copyright (C) 2007, 2009, 2014 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 <stdlib.h>
#include <nuttx/mm.h>
#ifdef CONFIG_MM_USER_HEAP
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: calloc
*
* Description:
* calloc is a thin wrapper for mm_calloc()
*
****************************************************************************/
FAR void *calloc(size_t n, size_t elem_size)
{
return mm_calloc(&g_mmheap, n, elem_size);
}
#endif /* CONFIG_MM_USER_HEAP */
+74
View File
@@ -0,0 +1,74 @@
/****************************************************************************
* mm/umm_free.c
*
* Copyright (C) 2007, 2009, 2013-2014 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 <stdlib.h>
#include <nuttx/mm.h>
#ifdef CONFIG_MM_USER_HEAP
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: free
*
* Description:
* Returns a chunk of user memory to the list of free nodes, merging with
* adjacent free chunks if possible.
*
****************************************************************************/
void free(FAR void *mem)
{
mm_free(&g_mmheap, mem);
}
#endif /* CONFIG_MM_USER_HEAP */
+90
View File
@@ -0,0 +1,90 @@
/****************************************************************************
* mm/umm_mallinfo.c
*
* Copyright (C) 2007, 2009, 2013-2014 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 <stdlib.h>
#include <nuttx/mm.h>
#ifdef CONFIG_MM_USER_HEAP
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: mallinfo
*
* Description:
* mallinfo returns a copy of updated current heap information for the
* user heap.
*
****************************************************************************/
#ifdef CONFIG_CAN_PASS_STRUCTS
struct mallinfo mallinfo(void)
{
struct mallinfo info;
mm_mallinfo(&g_mmheap, &info);
return info;
}
#else
int mallinfo(struct mallinfo *info)
{
return mm_mallinfo(&g_mmheap, info);
}
#endif /* CONFIG_CAN_PASS_STRUCTS */
#endif /* CONFIG_MM_USER_HEAP */
+91
View File
@@ -0,0 +1,91 @@
/****************************************************************************
* mm/umm_malloc.c
*
* Copyright (C) 2007, 2009, 2013-2014 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 <stdlib.h>
#include <nuttx/mm.h>
#ifdef CONFIG_MM_USER_HEAP
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Type Definitions
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/************************************************************************
* Name: malloc
*
* Description:
* Allocate memory from the user heap.
*
* Parameters:
* size - Size (in bytes) of the memory region to be allocated.
*
* Return Value:
* The address of the allocated memory (NULL on failure to allocate)
*
************************************************************************/
FAR void *malloc(size_t size)
{
return mm_malloc(&g_mmheap, size);
}
#endif /* CONFIG_MM_USER_HEAP */
+78
View File
@@ -0,0 +1,78 @@
/****************************************************************************
* mm/umm_memalign.c
*
* Copyright (C) 2007, 2009, 2011, 2013-2014 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 <stdlib.h>
#include <nuttx/mm.h>
#ifdef CONFIG_MM_USER_HEAP
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: memalign
*
* Description:
* memalign requests more than enough space from malloc, finds a region
* within that chunk that meets the alignment request and then frees any
* leading or trailing space.
*
* The alignment argument must be a power of two (not checked). 8-byte
* alignment is guaranteed by normal malloc calls.
*
****************************************************************************/
FAR void *memalign(size_t alignment, size_t size)
{
return mm_memalign(&g_mmheap, alignment, size);
}
#endif /* CONFIG_MM_USER_HEAP */
+80
View File
@@ -0,0 +1,80 @@
/****************************************************************************
* mm/mm_realloc.c
*
* Copyright (C) 2007, 2009, 2013-2014 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 <stdlib.h>
#include <nuttx/mm.h>
#ifdef CONFIG_MM_USER_HEAP
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: krealloc
*
* Description:
* Re-allocate memory in the user heap.
*
* Parameters:
* oldmem - The old memory allocated
* newsize - Size (in bytes) of the new memory region to be re-allocated.
*
* Return Value:
* The address of the re-allocated memory (NULL on failure to re-allocate)
*
****************************************************************************/
FAR void *realloc(FAR void *oldmem, size_t size)
{
return mm_realloc(&g_mmheap, oldmem, size);
}
#endif /* CONFIG_MM_USER_HEAP */
+75
View File
@@ -0,0 +1,75 @@
/****************************************************************************
* mm/mm_zalloc.c
*
* Copyright (C) 2007, 2009, 2014 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 <stdlib.h>
#include <nuttx/mm.h>
#ifdef CONFIG_MM_USER_HEAP
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/************************************************************************
* Name: kzalloc
*
* Description:
* Allocate and zero memory from the user heap.
*
* Parameters:
* size - Size (in bytes) of the memory region to be allocated.
*
* Return Value:
* The address of the allocated memory (NULL on failure to allocate)
*
************************************************************************/
FAR void *zalloc(size_t size)
{
return mm_zalloc(&g_mmheap, size);
}
#endif /* CONFIG_MM_USER_HEAP */