Fix common heap allocation logic, taking into account the kernel build requirements
This commit is contained in:
parent
ec086adfae
commit
2fd3413d35
@ -55,13 +55,21 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Definitions
|
* Private Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
/* Configuration */
|
/* Configuration ************************************************************/
|
||||||
|
/* Terminology. In the flat build (CONFIG_BUILD_FLAT=y), there is only a
|
||||||
#undef HAVE_KERNEL_HEAP
|
* single heap access with the standard allocations (malloc/free). This
|
||||||
#if (defined(CONFIG_BUILD_PROTECTED) || defined(CONFIG_BUILD_KERNEL)) && \
|
* heap is referred to as the user heap. In the protected build
|
||||||
defined(CONFIG_MM_KERNEL_HEAP)
|
* (CONFIG_BUILD_PROTECTED=y) where an MPU is used to protect a region of
|
||||||
# define HAVE_KERNEL_HEAP 1
|
* otherwise flat memory, there will be two allocators: One that allocates
|
||||||
#endif
|
* 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
|
* Private Data
|
||||||
@ -76,14 +84,18 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: up_allocate_heap
|
* Name: up_allocate_heap/up_allocate_kheap
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* This function will be called to dynamically set aside the heap region.
|
* This function will be called to dynamically set aside the heap region.
|
||||||
*
|
*
|
||||||
* For the kernel build (CONFIG_BUILD_KERNEL/PROTECTED=y) with both kernel-
|
* - For the normal "flat" build, this function returns the size of the
|
||||||
* and user-space heaps (CONFIG_MM_KERNEL_HEAP=y), this function provides
|
* single heap.
|
||||||
* the size of the unprotected, user-space 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
|
* 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
|
* 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)
|
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.
|
/* Get the unaligned size and position of the user-space heap.
|
||||||
* This heap begins after the user-space .bss section at an offset
|
* This heap begins after the user-space .bss section at an offset
|
||||||
* of CONFIG_MM_KERNEL_HEAPSIZE (subject to alignment).
|
* 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:
|
* Description:
|
||||||
* For the kernel build (CONFIG_BUILD_PROTECTED/KERNEL=y) with both kernel-
|
* For the kernel build (CONFIG_BUILD_PROTECTED/KERNEL=y) with both kernel-
|
||||||
* and user-space heaps (CONFIG_MM_KERNEL_HEAP=y), this function allocates
|
* 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.
|
* 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)
|
void up_allocate_kheap(FAR void **heap_start, size_t *heap_size)
|
||||||
{
|
{
|
||||||
/* Get the unaligned size and position of the user-space heap.
|
/* Get the unaligned size and position of the user-space heap.
|
||||||
|
Loading…
Reference in New Issue
Block a user