diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2014-09-01 07:57:54 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2014-09-01 07:57:54 -0600 |
commit | f9fd0eeaf37fef3863e59fd535701778ea9d2667 (patch) | |
tree | 3768faf0d50dc871fae21ca79e46a0ff366e16b8 /nuttx/arch/arm/src/common | |
parent | 51e9420e1a721ccd8c77fa7038b9fad9f0372872 (diff) | |
download | nuttx-f9fd0eeaf37fef3863e59fd535701778ea9d2667.tar.gz nuttx-f9fd0eeaf37fef3863e59fd535701778ea9d2667.tar.bz2 nuttx-f9fd0eeaf37fef3863e59fd535701778ea9d2667.zip |
Fix common heap allocation logic, taking into account the kernel build requirements
Diffstat (limited to 'nuttx/arch/arm/src/common')
-rw-r--r-- | nuttx/arch/arm/src/common/up_allocateheap.c | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/nuttx/arch/arm/src/common/up_allocateheap.c b/nuttx/arch/arm/src/common/up_allocateheap.c index f312ae067..e3443639a 100644 --- a/nuttx/arch/arm/src/common/up_allocateheap.c +++ b/nuttx/arch/arm/src/common/up_allocateheap.c @@ -55,13 +55,21 @@ /**************************************************************************** * Private Definitions ****************************************************************************/ -/* Configuration */ - -#undef HAVE_KERNEL_HEAP -#if (defined(CONFIG_BUILD_PROTECTED) || defined(CONFIG_BUILD_KERNEL)) && \ - defined(CONFIG_MM_KERNEL_HEAP) -# define HAVE_KERNEL_HEAP 1 -#endif +/* Configuration ************************************************************/ +/* Terminology. In the flat build (CONFIG_BUILD_FLAT=y), there is only a + * single heap access with the standard allocations (malloc/free). This + * heap is referred to as the user heap. In the protected build + * (CONFIG_BUILD_PROTECTED=y) where an MPU is used to protect a region of + * otherwise flat memory, there will be two allocators: One that allocates + * protected (kernel) memory and one that allocates unprotected (user) + * memory. These are referred to as the kernel and user heaps, + * respectively. + * + * The ARMv7 has no MPU but does have an MMU. With this MMU, it can support + * the kernel build (CONFIG_BUILD_KERNEL=y). In this configuration, there + * is again only one heap but, retaining the terminology, this is the kernel + * heap. + */ /**************************************************************************** * Private Data @@ -76,14 +84,18 @@ ****************************************************************************/ /**************************************************************************** - * Name: up_allocate_heap + * Name: up_allocate_heap/up_allocate_kheap * * Description: * This function will be called to dynamically set aside the heap region. * - * For the kernel build (CONFIG_BUILD_KERNEL/PROTECTED=y) with both kernel- - * and user-space heaps (CONFIG_MM_KERNEL_HEAP=y), this function provides - * the size of the unprotected, user-space heap. + * - For the normal "flat" build, this function returns the size of the + * single heap. + * - For the protected build (CONFIG_BUILD_PROTECTED=y) with both kernel- + * and user-space heaps (CONFIG_MM_KERNEL_HEAP=y), this function + * provides the size of the unprotected, user-space heap. + * - For the kernel build (CONFIG_BUILD_KERNEL=y), this function provides + * the size of the protected, kernel-space heap. * * If a protected kernel-space heap is provided, the kernel heap must be * allocated by an analogous up_allocate_kheap(). A custom version of this @@ -109,9 +121,13 @@ * ****************************************************************************/ +#ifdef CONFIG_BUILD_KERNEL +void up_allocate_kheap(FAR void **heap_start, size_t *heap_size) +#else void up_allocate_heap(FAR void **heap_start, size_t *heap_size) +#endif { -#ifdef HAVE_KERNEL_HEAP +#if defined(CONFIG_BUILD_PROTECTED) && defined(CONFIG_MM_KERNEL_HEAP) /* Get the unaligned size and position of the user-space heap. * This heap begins after the user-space .bss section at an offset * of CONFIG_MM_KERNEL_HEAPSIZE (subject to alignment). @@ -143,12 +159,12 @@ void up_allocate_heap(FAR void **heap_start, size_t *heap_size) * Description: * For the kernel build (CONFIG_BUILD_PROTECTED/KERNEL=y) with both kernel- * and user-space heaps (CONFIG_MM_KERNEL_HEAP=y), this function allocates - * the kernel-space heap. A custom version of this function is need if + * the kernel-space heap. A custom version of this function is needed if * memory protection of the kernel heap is required. * ****************************************************************************/ -#ifdef HAVE_KERNEL_HEAP +#if defined(CONFIG_BUILD_PROTECTED) && defined(CONFIG_MM_KERNEL_HEAP) void up_allocate_kheap(FAR void **heap_start, size_t *heap_size) { /* Get the unaligned size and position of the user-space heap. |