Space at the beginning of the process data space is now reserved for user heap management structures. In the kernel build mode, these heap structures are shared between the kernel and use code in order to allocate user-specific data.

This commit is contained in:
Gregory Nutt 2014-09-02 11:21:23 -06:00
parent 8b082a167b
commit b085e084f4
15 changed files with 270 additions and 66 deletions

View File

@ -329,7 +329,10 @@ static void up_addrenv_destroy_region(FAR uintptr_t **list,
* textsize - The size (in bytes) of the .text address environment needed
* by the task. This region may be read/execute only.
* datasize - The size (in bytes) of the .data/.bss address environment
* needed by the task. This region may be read/write only.
* needed by the task. This region may be read/write only. NOTE: The
* actual size of the data region that is allocated will include a
* OS private reserved region at the beginning. The size of the
* private, reserved region is give by ARCH_DATA_RESERVE.
* addrenv - The location to return the representation of the task address
* environment.
*
@ -368,10 +371,14 @@ int up_addrenv_create(size_t textsize, size_t datasize,
goto errout;
}
/* Allocate .bss/.data space pages */
/* Allocate .bss/.data space pages. NOTE that a configurable offset is
* added to the allocted size. This is matched by the offset that is
* used when reporting the virtual data address in up_addrenv_vdata().
*/
ret = up_addrenv_create_region(addrenv->data, ARCH_DATA_NSECTS,
CONFIG_ARCH_DATA_VBASE, datasize,
CONFIG_ARCH_DATA_VBASE,
datasize + ARCH_DATA_RESERVE,
MMU_L2_UDATAFLAGS);
if (ret < 0)
{
@ -488,7 +495,7 @@ int up_addrenv_vdata(FAR group_addrenv_t *addrenv, uintptr_t textsize,
/* Not much to do in this case */
DEBUGASSERT(addrenv && vdata);
*vdata = (FAR void *)CONFIG_ARCH_DATA_VBASE;
*vdata = (FAR void *)(CONFIG_ARCH_DATA_VBASE + ARCH_DATA_RESERVE);
return OK;
}

View File

@ -96,6 +96,22 @@
#define ARCH_DATA_SIZE (CONFIG_ARCH_DATA_NPAGES * CONFIG_MM_PGSIZE)
#define ARCH_DATA_VEND (CONFIG_ARCH_DATA_VBASE + ARCH_DATA_SIZE)
/* Reserved .bss/.data region. In the kernel build (CONFIG_BUILD_KERNEL),
* the region at the beginning of the .bss/.data region is reserved for use
* by the OS. This reserved region contains only the task group's heap
* memory management data structures.
*
* We don't use sizeof(struct mm_heap_s) but, instead, a nice even number
* that we must be assure is greater than or equal to
* sizeof(struct mm_heap_s)
*/
#ifdef CONFIG_BUILD_KERNEL
# define ARCH_DATA_RESERVE 512
#else
# define ARCH_DATA_RESERVE 0
#endif
/* Heap region */
#ifndef CONFIG_ARCH_HEAP_VBASE

View File

@ -41,12 +41,29 @@
#include <nuttx/mm.h>
#ifdef CONFIG_MM_USER_HEAP
#ifdef MM_KERNEL_USRHEAP_INTF
/************************************************************************
* Pre-processor definition
************************************************************************/
#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL)
/* In the kernel build, there a multiple user heaps; one for each task
* group. In this build configuration, the user heap structure lies
* in a reserved region at the beginning of the .bss/.data address
* space (CONFIG_ARCH_DATA_VBASE). The size of that region is given by
* ARCH_DATA_RESERVE
*/
# include <nuttx/addrenv.h>
# define USR_HEAP ((FAR struct mm_heap_s *)CONFIG_ARCH_DATA_VBASE)
#else
/* Otherwise, the user heap data structures are in common .bss */
# define USR_HEAP &g_mmheap;
#endif
/************************************************************************
* Private Types
************************************************************************/
@ -82,7 +99,7 @@
void umm_addregion(FAR void *heap_start, size_t heap_size)
{
mm_addregion(&g_mmheap, heap_start, heap_size);
mm_addregion(USR_HEAP, heap_start, heap_size);
}
#endif /* CONFIG_MM_USER_HEAP */
#endif /* MM_KERNEL_USRHEAP_INTF */

View File

@ -43,12 +43,27 @@
#include <nuttx/mm.h>
#ifdef CONFIG_MM_USER_HEAP
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL)
/* In the kernel build, there a multiple user heaps; one for each task
* group. In this build configuration, the user heap structure lies
* in a reserved region at the beginning of the .bss/.data address
* space (CONFIG_ARCH_DATA_VBASE). The size of that region is given by
* ARCH_DATA_RESERVE
*/
# include <nuttx/addrenv.h>
# define USR_HEAP ((FAR struct mm_heap_s *)CONFIG_ARCH_DATA_VBASE)
#else
/* Otherwise, the user heap data structures are in common .bss */
# define USR_HEAP &g_mmheap;
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
@ -63,7 +78,5 @@
FAR void *umm_brkaddr(int region)
{
return mm_brkaddr(&g_mmheap, region);
return mm_brkaddr(USR_HEAP, region);
}
#endif /* CONFIG_MM_USER_HEAP */

View File

@ -43,12 +43,27 @@
#include <nuttx/mm.h>
#ifdef CONFIG_MM_USER_HEAP
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL)
/* In the kernel build, there a multiple user heaps; one for each task
* group. In this build configuration, the user heap structure lies
* in a reserved region at the beginning of the .bss/.data address
* space (CONFIG_ARCH_DATA_VBASE). The size of that region is given by
* ARCH_DATA_RESERVE
*/
# include <nuttx/addrenv.h>
# define USR_HEAP ((FAR struct mm_heap_s *)CONFIG_ARCH_DATA_VBASE)
#else
/* Otherwise, the user heap data structures are in common .bss */
# define USR_HEAP &g_mmheap;
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
@ -63,7 +78,5 @@
FAR void *calloc(size_t n, size_t elem_size)
{
return mm_calloc(&g_mmheap, n, elem_size);
return mm_calloc(USR_HEAP, n, elem_size);
}
#endif /* CONFIG_MM_USER_HEAP */

View File

@ -41,12 +41,27 @@
#include <nuttx/mm.h>
#ifdef CONFIG_MM_USER_HEAP
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL)
/* In the kernel build, there a multiple user heaps; one for each task
* group. In this build configuration, the user heap structure lies
* in a reserved region at the beginning of the .bss/.data address
* space (CONFIG_ARCH_DATA_VBASE). The size of that region is given by
* ARCH_DATA_RESERVE
*/
# include <nuttx/addrenv.h>
# define USR_HEAP ((FAR struct mm_heap_s *)CONFIG_ARCH_DATA_VBASE)
#else
/* Otherwise, the user heap data structures are in common .bss */
# define USR_HEAP &g_mmheap;
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
@ -62,7 +77,5 @@
void umm_extend(FAR void *mem, size_t size, int region)
{
mm_extend(&g_mmheap, mem, size, region);
mm_extend(USR_HEAP, mem, size, region);
}
#endif /* CONFIG_MM_USER_HEAP */

View File

@ -43,12 +43,27 @@
#include <nuttx/mm.h>
#ifdef CONFIG_MM_USER_HEAP
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL)
/* In the kernel build, there a multiple user heaps; one for each task
* group. In this build configuration, the user heap structure lies
* in a reserved region at the beginning of the .bss/.data address
* space (CONFIG_ARCH_DATA_VBASE). The size of that region is given by
* ARCH_DATA_RESERVE
*/
# include <nuttx/addrenv.h>
# define USR_HEAP ((FAR struct mm_heap_s *)CONFIG_ARCH_DATA_VBASE)
#else
/* Otherwise, the user heap data structures are in common .bss */
# define USR_HEAP &g_mmheap;
#endif
/****************************************************************************
* Private Functions
****************************************************************************/
@ -68,7 +83,5 @@
void free(FAR void *mem)
{
mm_free(&g_mmheap, mem);
mm_free(USR_HEAP, mem);
}
#endif /* CONFIG_MM_USER_HEAP */

View File

@ -41,7 +41,7 @@
#include <nuttx/mm.h>
#ifdef CONFIG_MM_USER_HEAP
#ifdef MM_KERNEL_USRHEAP_INTF
/************************************************************************
* Pre-processor definition
@ -55,9 +55,23 @@
* Public Data
************************************************************************/
/* This is the user heap */
#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL)
/* In the kernel build, there a multiple user heaps; one for each task
* group. In this build configuration, the user heap structure lies
* in a reserved region at the beginning of the .bss/.data address
* space (CONFIG_ARCH_DATA_VBASE). The size of that region is given by
* ARCH_DATA_RESERVE
*/
# include <nuttx/addrenv.h>
# define USR_HEAP ((FAR struct mm_heap_s *)CONFIG_ARCH_DATA_VBASE)
#else
/* Otherwise, the user heap data structures are in common .bss */
struct mm_heap_s g_mmheap;
#define USR_HEAP &g_mmheap;
#endif
/************************************************************************
* Private Functions
@ -86,7 +100,8 @@ struct mm_heap_s g_mmheap;
void umm_initialize(FAR void *heap_start, size_t heap_size)
{
mm_initialize(&g_mmheap, heap_start, heap_size);
DEBUGASSERT(ARCH_DATA_RESERVE >= sizeof(struct mm_heap_s));
mm_initialize(USR_HEAP, heap_start, heap_size);
}
#endif /* CONFIG_MM_USER_HEAP */
#endif /* MM_KERNEL_USRHEAP_INTF */

View File

@ -43,12 +43,27 @@
#include <nuttx/mm.h>
#ifdef CONFIG_MM_USER_HEAP
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL)
/* In the kernel build, there a multiple user heaps; one for each task
* group. In this build configuration, the user heap structure lies
* in a reserved region at the beginning of the .bss/.data address
* space (CONFIG_ARCH_DATA_VBASE). The size of that region is given by
* ARCH_DATA_RESERVE
*/
# include <nuttx/addrenv.h>
# define USR_HEAP ((FAR struct mm_heap_s *)CONFIG_ARCH_DATA_VBASE)
#else
/* Otherwise, the user heap data structures are in common .bss */
# define USR_HEAP &g_mmheap;
#endif
/****************************************************************************
* Private Data
****************************************************************************/
@ -75,7 +90,7 @@
struct mallinfo mallinfo(void)
{
struct mallinfo info;
mm_mallinfo(&g_mmheap, &info);
mm_mallinfo(USR_HEAP, &info);
return info;
}
@ -83,8 +98,7 @@ struct mallinfo mallinfo(void)
int mallinfo(struct mallinfo *info)
{
return mm_mallinfo(&g_mmheap, info);
return mm_mallinfo(USR_HEAP, info);
}
#endif /* CONFIG_CAN_PASS_STRUCTS */
#endif /* CONFIG_MM_USER_HEAP */

View File

@ -44,12 +44,27 @@
#include <nuttx/mm.h>
#ifdef CONFIG_MM_USER_HEAP
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL)
/* In the kernel build, there a multiple user heaps; one for each task
* group. In this build configuration, the user heap structure lies
* in a reserved region at the beginning of the .bss/.data address
* space (CONFIG_ARCH_DATA_VBASE). The size of that region is given by
* ARCH_DATA_RESERVE
*/
# include <nuttx/addrenv.h>
# define USR_HEAP ((FAR struct mm_heap_s *)CONFIG_ARCH_DATA_VBASE)
#else
/* Otherwise, the user heap data structures are in common .bss */
# define USR_HEAP &g_mmheap;
#endif
/****************************************************************************
* Type Definitions
****************************************************************************/
@ -103,7 +118,7 @@ FAR void *malloc(size_t size)
do
{
mem = mm_malloc(&g_mmheap, size);
mem = mm_malloc(USR_HEAP, size);
if (!mem)
{
brkaddr = sbrk(size);
@ -117,8 +132,6 @@ FAR void *malloc(size_t size)
return mem;
#else
return mm_malloc(&g_mmheap, size);
return mm_malloc(USR_HEAP, size);
#endif
}
#endif /* CONFIG_MM_USER_HEAP */

View File

@ -43,12 +43,27 @@
#include <nuttx/mm.h>
#ifdef CONFIG_MM_USER_HEAP
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL)
/* In the kernel build, there a multiple user heaps; one for each task
* group. In this build configuration, the user heap structure lies
* in a reserved region at the beginning of the .bss/.data address
* space (CONFIG_ARCH_DATA_VBASE). The size of that region is given by
* ARCH_DATA_RESERVE
*/
# include <nuttx/addrenv.h>
# define USR_HEAP ((FAR struct mm_heap_s *)CONFIG_ARCH_DATA_VBASE)
#else
/* Otherwise, the user heap data structures are in common .bss */
# define USR_HEAP &g_mmheap;
#endif
/****************************************************************************
* Private Functions
****************************************************************************/
@ -72,7 +87,5 @@
FAR void *memalign(size_t alignment, size_t size)
{
return mm_memalign(&g_mmheap, alignment, size);
return mm_memalign(USR_HEAP, alignment, size);
}
#endif /* CONFIG_MM_USER_HEAP */

View File

@ -43,12 +43,27 @@
#include <nuttx/mm.h>
#ifdef CONFIG_MM_USER_HEAP
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL)
/* In the kernel build, there a multiple user heaps; one for each task
* group. In this build configuration, the user heap structure lies
* in a reserved region at the beginning of the .bss/.data address
* space (CONFIG_ARCH_DATA_VBASE). The size of that region is given by
* ARCH_DATA_RESERVE
*/
# include <nuttx/addrenv.h>
# define USR_HEAP ((FAR struct mm_heap_s *)CONFIG_ARCH_DATA_VBASE)
#else
/* Otherwise, the user heap data structures are in common .bss */
# define USR_HEAP &g_mmheap;
#endif
/****************************************************************************
* Private Functions
****************************************************************************/
@ -74,7 +89,5 @@
FAR void *realloc(FAR void *oldmem, size_t size)
{
return mm_realloc(&g_mmheap, oldmem, size);
return mm_realloc(USR_HEAP, oldmem, size);
}
#endif /* CONFIG_MM_USER_HEAP */

View File

@ -44,12 +44,30 @@
#include <nuttx/mm.h>
#include <nuttx/pgalloc.h>
#if defined(CONFIG_MM_USER_HEAP) && defined(CONFIG_ARCH_ADDRENV)
#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_MM_PGALLOC) && \
defined(CONFIG_ARCH_USE_MMU)
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL)
/* In the kernel build, there a multiple user heaps; one for each task
* group. In this build configuration, the user heap structure lies
* in a reserved region at the beginning of the .bss/.data address
* space (CONFIG_ARCH_DATA_VBASE). The size of that region is given by
* ARCH_DATA_RESERVE
*/
# include <nuttx/addrenv.h>
# define USR_HEAP ((FAR struct mm_heap_s *)CONFIG_ARCH_DATA_VBASE)
#else
/* Otherwise, the user heap data structures are in common .bss */
# define USR_HEAP &g_mmheap;
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
@ -88,7 +106,7 @@
FAR void *sbrk(intptr_t incr)
{
return mm_sbrk(&g_mmheap, incr, CONFIG_ARCH_STACK_NPAGES << MM_PGSHIFT);
return mm_sbrk(USR_HEAP, incr, CONFIG_ARCH_STACK_NPAGES << MM_PGSHIFT);
}
#endif /* CONFIG_MM_USER_HEAP && CONFIG_ARCH_ADDRENV */
#endif /* CONFIG_ARCH_ADDRENV && CONFIG_MM_PGALLOC && CONFIG_ARCH_USE_MMU */

View File

@ -41,12 +41,27 @@
#include <nuttx/mm.h>
#ifdef CONFIG_MM_USER_HEAP
/************************************************************************
* Pre-processor definition
************************************************************************/
#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL)
/* In the kernel build, there a multiple user heaps; one for each task
* group. In this build configuration, the user heap structure lies
* in a reserved region at the beginning of the .bss/.data address
* space (CONFIG_ARCH_DATA_VBASE). The size of that region is given by
* ARCH_DATA_RESERVE
*/
# include <nuttx/addrenv.h>
# define USR_HEAP ((FAR struct mm_heap_s *)CONFIG_ARCH_DATA_VBASE)
#else
/* Otherwise, the user heap data structures are in common .bss */
# define USR_HEAP &g_mmheap;
#endif
/************************************************************************
* Private Types
************************************************************************/
@ -81,7 +96,7 @@
int umm_trysemaphore(void)
{
return mm_trysemaphore(&g_mmheap);
return mm_trysemaphore(USR_HEAP);
}
/************************************************************************
@ -102,7 +117,5 @@ int umm_trysemaphore(void)
void umm_givesemaphore(void)
{
mm_givesemaphore(&g_mmheap);
mm_givesemaphore(USR_HEAP);
}
#endif /* CONFIG_MM_USER_HEAP */

View File

@ -44,12 +44,27 @@
#include <nuttx/mm.h>
#ifdef CONFIG_MM_USER_HEAP
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL)
/* In the kernel build, there a multiple user heaps; one for each task
* group. In this build configuration, the user heap structure lies
* in a reserved region at the beginning of the .bss/.data address
* space (CONFIG_ARCH_DATA_VBASE). The size of that region is given by
* ARCH_DATA_RESERVE
*/
# include <nuttx/addrenv.h>
# define USR_HEAP ((FAR struct mm_heap_s *)CONFIG_ARCH_DATA_VBASE)
#else
/* Otherwise, the user heap data structures are in common .bss */
# define USR_HEAP &g_mmheap;
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
@ -84,8 +99,6 @@ FAR void *zalloc(size_t size)
#else
/* Use mm_zalloc() becuase it implements the clear */
return mm_zalloc(&g_mmheap, size);
return mm_zalloc(USR_HEAP, size);
#endif
}
#endif /* CONFIG_MM_USER_HEAP */