mirror of
https://github.com/apache/nuttx.git
synced 2026-05-27 11:26:12 +08:00
More separation of kernel- and user-memory management
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3468 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
@@ -43,6 +43,8 @@
|
|||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
||||||
#include <nuttx/arch.h>
|
#include <nuttx/arch.h>
|
||||||
|
#include <nuttx/kmalloc.h>
|
||||||
|
|
||||||
#include <arch/board/board.h>
|
#include <arch/board/board.h>
|
||||||
|
|
||||||
#include "chip.h"
|
#include "chip.h"
|
||||||
@@ -117,10 +119,10 @@ void up_allocate_heap(FAR void **heap_start, size_t *heap_size)
|
|||||||
#if CONFIG_MM_REGIONS > 1
|
#if CONFIG_MM_REGIONS > 1
|
||||||
void up_addregion(void)
|
void up_addregion(void)
|
||||||
{
|
{
|
||||||
mm_addregion((FAR void*)SAM3U_INTSRAM1_BASE, CONFIG_SAM3U_SRAM1_SIZE);
|
kmm_addregion((FAR void*)SAM3U_INTSRAM1_BASE, CONFIG_SAM3U_SRAM1_SIZE);
|
||||||
|
|
||||||
#if CONFIG_MM_REGIONS > 2
|
#if CONFIG_MM_REGIONS > 2
|
||||||
mm_addregion((FAR void*)SAM3U_NFCSRAM_BASE, CONFIG_SAM3U_NFCSRAM_SIZE);
|
kmm_addregion((FAR void*)SAM3U_NFCSRAM_BASE, CONFIG_SAM3U_NFCSRAM_SIZE);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -96,8 +96,8 @@ $(BOARD_INCLUDE)/user_map.h: $(TOPDIR)/User.map
|
|||||||
@echo "" >> $(BOARD_INCLUDE)/user_map.h
|
@echo "" >> $(BOARD_INCLUDE)/user_map.h
|
||||||
@echo "#define CONFIG_USER_MMINIT 0x`grep \" mm_initialize$\" $(TOPDIR)/User.map | cut -d' ' -f1`" >> $(BOARD_INCLUDE)/user_map.h
|
@echo "#define CONFIG_USER_MMINIT 0x`grep \" mm_initialize$\" $(TOPDIR)/User.map | cut -d' ' -f1`" >> $(BOARD_INCLUDE)/user_map.h
|
||||||
@echo "#define CONFIG_USER_MMADDREGION 0x`grep \" mm_addregion$\" $(TOPDIR)/User.map | cut -d' ' -f1`" >> $(BOARD_INCLUDE)/user_map.h
|
@echo "#define CONFIG_USER_MMADDREGION 0x`grep \" mm_addregion$\" $(TOPDIR)/User.map | cut -d' ' -f1`" >> $(BOARD_INCLUDE)/user_map.h
|
||||||
@echo "#define CONFIG_USER_TRYSEM 0x`grep \" mm_trysemaphore$\" $(TOPDIR)/User.map | cut -d' ' -f1`" >> $(BOARD_INCLUDE)/user_map.h
|
@echo "#define CONFIG_USER_MMTRYSEM 0x`grep \" mm_trysemaphore$\" $(TOPDIR)/User.map | cut -d' ' -f1`" >> $(BOARD_INCLUDE)/user_map.h
|
||||||
@echo "#define CONFIG_USER_GIVSEM 0x`grep \" mm_givesemaphore$\" $(TOPDIR)/User.map | cut -d' ' -f1`" >> $(BOARD_INCLUDE)/user_map.h
|
@echo "#define CONFIG_USER_MMGIVESEM 0x`grep \" mm_givesemaphore$\" $(TOPDIR)/User.map | cut -d' ' -f1`" >> $(BOARD_INCLUDE)/user_map.h
|
||||||
@echo "" >> $(BOARD_INCLUDE)/user_map.h
|
@echo "" >> $(BOARD_INCLUDE)/user_map.h
|
||||||
@echo "#define CONFIG_USER_MALLOC 0x`grep \" malloc$\" $(TOPDIR)/User.map | cut -d' ' -f1`" >> $(BOARD_INCLUDE)/user_map.h
|
@echo "#define CONFIG_USER_MALLOC 0x`grep \" malloc$\" $(TOPDIR)/User.map | cut -d' ' -f1`" >> $(BOARD_INCLUDE)/user_map.h
|
||||||
@echo "#define CONFIG_USER_REALLOC 0x`grep \" realloc$\" $(TOPDIR)/User.map | cut -d' ' -f1`" >> $(BOARD_INCLUDE)/user_map.h
|
@echo "#define CONFIG_USER_REALLOC 0x`grep \" realloc$\" $(TOPDIR)/User.map | cut -d' ' -f1`" >> $(BOARD_INCLUDE)/user_map.h
|
||||||
|
|||||||
@@ -62,13 +62,14 @@ MEMORY
|
|||||||
sram2 (rwx) : ORIGIN = 0x20080000, LENGTH = 16K
|
sram2 (rwx) : ORIGIN = 0x20080000, LENGTH = 16K
|
||||||
}
|
}
|
||||||
|
|
||||||
# Force user_start into the link. This is the application entry point
|
/* Force user_start into the link. This is the application entry point */
|
||||||
|
|
||||||
EXTERN(user_start)
|
EXTERN(user_start)
|
||||||
|
|
||||||
# Make sure that the critical memory management functions are in user-space.
|
/* Make sure that the critical memory management functions are in user-space.
|
||||||
# Currently, the plan is that the memory manager will reside in user-space
|
* Currently, the plan is that the memory manager will reside in user-space
|
||||||
# but be usable both by kernel- and user-space code
|
* but be usable both by kernel- and user-space code
|
||||||
|
*/
|
||||||
|
|
||||||
EXTERN(mm_initialize)
|
EXTERN(mm_initialize)
|
||||||
EXTERN(mm_addregion)
|
EXTERN(mm_addregion)
|
||||||
|
|||||||
+16
-4
@@ -41,10 +41,12 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#ifndef CONFIG_NUTTX_KERNEL
|
#ifndef CONFIG_NUTTX_KERNEL
|
||||||
# include <stdlib.h>
|
# include <stdlib.h>
|
||||||
|
# include <nuttx/mm.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -74,13 +76,23 @@ extern "C" {
|
|||||||
|
|
||||||
#ifndef CONFIG_NUTTX_KERNEL
|
#ifndef CONFIG_NUTTX_KERNEL
|
||||||
|
|
||||||
# define kmalloc(s) malloc(s)
|
# define kmm_initialize(h,s) mm_initialize(h,s)
|
||||||
# define kzalloc(s) zalloc(s)
|
# define kmm_addregion(h,s) mm_addregion(h,s)
|
||||||
# define krealloc(p,s) realloc(p,s)
|
# define kmm_trysemaphore(h,s) mm_trysemaphore(h,s)
|
||||||
# define kfree(p) free(p)
|
# define kmm_givesemaphore(h,s) mm_givesemaphore(h,s)
|
||||||
|
|
||||||
|
# define kmalloc(s) malloc(s)
|
||||||
|
# define kzalloc(s) zalloc(s)
|
||||||
|
# define krealloc(p,s) realloc(p,s)
|
||||||
|
# define kfree(p) free(p)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
KMALLOC_EXTERN void kmm_initialize(FAR void *heap_start, size_t heap_size);
|
||||||
|
KMALLOC_EXTERN void kmm_addregion(FAR void *heapstart, size_t heapsize);
|
||||||
|
KMALLOC_EXTERN int kmm_trysemaphore(void);
|
||||||
|
KMALLOC_EXTERN void kmm_givesemaphore(void);
|
||||||
|
|
||||||
KMALLOC_EXTERN FAR void *kmalloc(size_t);
|
KMALLOC_EXTERN FAR void *kmalloc(size_t);
|
||||||
KMALLOC_EXTERN FAR void *kzalloc(size_t);
|
KMALLOC_EXTERN FAR void *kzalloc(size_t);
|
||||||
KMALLOC_EXTERN FAR void *krealloc(FAR void*, size_t);
|
KMALLOC_EXTERN FAR void *krealloc(FAR void*, size_t);
|
||||||
|
|||||||
+2
-1
@@ -134,7 +134,8 @@ endif
|
|||||||
|
|
||||||
IRQ_SRCS = irq_initialize.c irq_attach.c irq_dispatch.c irq_unexpectedisr.c
|
IRQ_SRCS = irq_initialize.c irq_attach.c irq_dispatch.c irq_unexpectedisr.c
|
||||||
|
|
||||||
KMM_SRCS = kmm_kmalloc.c kmm_kzalloc.c kmm_krealloc.c kmm_kfree.c
|
KMM_SRCS = kmm_initialize.c kmm_addregion.c kmm_semaphore.c \
|
||||||
|
kmm_kmalloc.c kmm_kzalloc.c kmm_krealloc.c kmm_kfree.c
|
||||||
|
|
||||||
CSRCS = $(MISC_SRCS) $(TSK_SRCS) $(SCHED_SRCS) $(WDOG_SRCS) $(TIME_SRCS) \
|
CSRCS = $(MISC_SRCS) $(TSK_SRCS) $(SCHED_SRCS) $(WDOG_SRCS) $(TIME_SRCS) \
|
||||||
$(SEM_SRCS) $(TIMER_SRCS) $(WORK_SRCS) $(PGFILL_SRCS) $(IRQ_SRCS)
|
$(SEM_SRCS) $(TIMER_SRCS) $(WORK_SRCS) $(PGFILL_SRCS) $(IRQ_SRCS)
|
||||||
|
|||||||
@@ -0,0 +1,113 @@
|
|||||||
|
/************************************************************************
|
||||||
|
* sched/kmm_addregion.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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/kmalloc.h>
|
||||||
|
|
||||||
|
#ifdef CONFIG_NUTTX_KERNEL
|
||||||
|
|
||||||
|
/* This logic is all tentatively and, hopefully, will grow in usability.
|
||||||
|
* For now, the kernel-mode build uses the memory manager that is
|
||||||
|
* provided in the user-space build. That is awkward but reasonable for
|
||||||
|
* the current level of support: At present, only memory protection is
|
||||||
|
* provided. Kernel-mode code may call into user-mode code, but not
|
||||||
|
* vice-versa. So hosting the memory manager in user-space allows the
|
||||||
|
* memory manager to be shared in both kernel- and user-mode spaces.
|
||||||
|
*
|
||||||
|
* In the longer run, if an MMU is support that can provide virtualized
|
||||||
|
* memory, then some SLAB memory manager will be required in kernel-space
|
||||||
|
* with some kind of brk() system call to obtain mapped heap space.
|
||||||
|
*
|
||||||
|
* In the current build model, the user-space module is built first. The
|
||||||
|
* file user_map.h is generated in the first pass and contains the
|
||||||
|
* addresses of the memory manager needed in this file:
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <arch/board/user_map.h>
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Pre-processor definition
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
/* This value is obtained from user_map.h */
|
||||||
|
|
||||||
|
#define KADDREGION(h,s) ((kmaddregion_t)CONFIG_USER_MMADDREGION)(h,s)
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Private Types
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
typedef void (*kmaddregion_t)(FAR void*, size_t);
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Function: kmm_addregion
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* This is a simple redirection to the user-space mm_addregion()
|
||||||
|
* function.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* heap_start - Address of the beginning of the memory region
|
||||||
|
* heap_size - The size (in bytes) if the memory region.
|
||||||
|
*
|
||||||
|
* Return Value:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
* Assumptions:
|
||||||
|
* 1. mm_addregion() resides in user-space
|
||||||
|
* 2. The address of the user space mm_addregion() is provided in
|
||||||
|
* user_map.h
|
||||||
|
* 3. The user-space mm_addregion() is callable from kernel-space.
|
||||||
|
*
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
void kmm_addregion(FAR void *heap_start, size_t heap_size)
|
||||||
|
{
|
||||||
|
return KADDREGION(heap_start, heap_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* CONFIG_NUTTX_KERNEL */
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
/************************************************************************
|
||||||
|
* sched/kmm_initialize.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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/kmalloc.h>
|
||||||
|
|
||||||
|
#ifdef CONFIG_NUTTX_KERNEL
|
||||||
|
|
||||||
|
/* This logic is all tentatively and, hopefully, will grow in usability.
|
||||||
|
* For now, the kernel-mode build uses the memory manager that is
|
||||||
|
* provided in the user-space build. That is awkward but reasonable for
|
||||||
|
* the current level of support: At present, only memory protection is
|
||||||
|
* provided. Kernel-mode code may call into user-mode code, but not
|
||||||
|
* vice-versa. So hosting the memory manager in user-space allows the
|
||||||
|
* memory manager to be shared in both kernel- and user-mode spaces.
|
||||||
|
*
|
||||||
|
* In the longer run, if an MMU is support that can provide virtualized
|
||||||
|
* memory, then some SLAB memory manager will be required in kernel-space
|
||||||
|
* with some kind of brk() system call to obtain mapped heap space.
|
||||||
|
*
|
||||||
|
* In the current build model, the user-space module is built first. The
|
||||||
|
* file user_map.h is generated in the first pass and contains the
|
||||||
|
* addresses of the memory manager needed in this file:
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <arch/board/user_map.h>
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Pre-processor definition
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
/* This value is obtained from user_map.h */
|
||||||
|
|
||||||
|
#define KINITIALIZE(h,s) ((kminitialize_t)CONFIG_USER_MMINIT)(h,s)
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Private Types
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
typedef void (*kminitialize_t)(FAR void*, size_t);
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Function: kmm_initialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* This is a simple redirection to the user-space mm_initialize()
|
||||||
|
* function.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* heap_start - Address of the beginning of the (initial) memory region
|
||||||
|
* heap_size - The size (in bytes) if the (initial) memory region.
|
||||||
|
*
|
||||||
|
* Return Value:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
* Assumptions:
|
||||||
|
* 1. mm_initialize() resides in user-space
|
||||||
|
* 2. The address of the user space mm_initialize() is provided in
|
||||||
|
* user_map.h
|
||||||
|
* 3. The user-space mm_initialize() is callable from kernel-space.
|
||||||
|
*
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
void kmm_initialize(FAR void *heap_start, size_t heap_size)
|
||||||
|
{
|
||||||
|
return KINITIALIZE(heap_start, heap_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* CONFIG_NUTTX_KERNEL */
|
||||||
+1
-1
@@ -102,7 +102,7 @@ typedef void (*kfree_t)(FAR void *);
|
|||||||
*
|
*
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
|
|
||||||
void free(FAR void *mem)
|
void kfree(FAR void *mem)
|
||||||
{
|
{
|
||||||
return KFREE(mem);
|
return KFREE(mem);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -90,7 +90,7 @@ typedef FAR void *(*kmalloc_t)(size_t);
|
|||||||
* This is a simple redirection to the user-space malloc() function.
|
* This is a simple redirection to the user-space malloc() function.
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* None
|
* size - Size (in bytes) of the memory region to be allocated.
|
||||||
*
|
*
|
||||||
* Return Value:
|
* Return Value:
|
||||||
* The address of the allocated memory (NULL on failure to allocate)
|
* The address of the allocated memory (NULL on failure to allocate)
|
||||||
|
|||||||
@@ -90,7 +90,8 @@ typedef FAR void *(*krealloc_t)(FAR void*, size_t);
|
|||||||
* This is a simple redirection to the user-space realloc() function.
|
* This is a simple redirection to the user-space realloc() function.
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* None
|
* oldmem - The old memory allocated
|
||||||
|
* size - Size (in bytes) of the new memory region to be re-allocated.
|
||||||
*
|
*
|
||||||
* Return Value:
|
* Return Value:
|
||||||
* The address of the re-allocated memory (NULL on failure to re-allocate)
|
* The address of the re-allocated memory (NULL on failure to re-allocate)
|
||||||
|
|||||||
+1
-1
@@ -90,7 +90,7 @@ typedef FAR void *(*kzalloc_t)(size_t);
|
|||||||
* This is a simple redirection to the user-space zalloc() function.
|
* This is a simple redirection to the user-space zalloc() function.
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* None
|
* size - Size (in bytes) of the memory region to be allocated.
|
||||||
*
|
*
|
||||||
* Return Value:
|
* Return Value:
|
||||||
* The address of the allocated memory (NULL on failure to allocate)
|
* The address of the allocated memory (NULL on failure to allocate)
|
||||||
|
|||||||
@@ -0,0 +1,140 @@
|
|||||||
|
/************************************************************************
|
||||||
|
* sched/kmm_semaphore.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* 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/kmalloc.h>
|
||||||
|
|
||||||
|
#ifdef CONFIG_NUTTX_KERNEL
|
||||||
|
|
||||||
|
/* This logic is all tentatively and, hopefully, will grow in usability.
|
||||||
|
* For now, the kernel-mode build uses the memory manager that is
|
||||||
|
* provided in the user-space build. That is awkward but reasonable for
|
||||||
|
* the current level of support: At present, only memory protection is
|
||||||
|
* provided. Kernel-mode code may call into user-mode code, but not
|
||||||
|
* vice-versa. So hosting the memory manager in user-space allows the
|
||||||
|
* memory manager to be shared in both kernel- and user-mode spaces.
|
||||||
|
*
|
||||||
|
* In the longer run, if an MMU is support that can provide virtualized
|
||||||
|
* memory, then some SLAB memory manager will be required in kernel-space
|
||||||
|
* with some kind of brk() system call to obtain mapped heap space.
|
||||||
|
*
|
||||||
|
* In the current build model, the user-space module is built first. The
|
||||||
|
* file user_map.h is generated in the first pass and contains the
|
||||||
|
* addresses of the memory manager needed in this file:
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <arch/board/user_map.h>
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Pre-processor definition
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
/* These values are obtained from user_map.h */
|
||||||
|
|
||||||
|
#define KTRYSEMAPHORE() ((kmtrysemaphore_t) CONFIG_USER_MMTRYSEM )()
|
||||||
|
#define KGIVESEMAPHORE() ((kmgivesemaphore_t)CONFIG_USER_MMGIVESEM)()
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Private Types
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
typedef int (*kmtrysemaphore_t)(void);
|
||||||
|
typedef void (*kmgivesemaphore_t)(void);
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Function: kmm_trysemaphore
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* This is a simple redirection to the user-space mm_trysemaphore()
|
||||||
|
* function.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
* Return Value:
|
||||||
|
* OK on success; a negated errno on failure
|
||||||
|
*
|
||||||
|
* Assumptions:
|
||||||
|
* 1. mm_trysemaphore() resides in user-space
|
||||||
|
* 2. The address of the user space mm_trysemaphore() is provided in
|
||||||
|
* user_map.h
|
||||||
|
* 3. The user-space mm_semaphore() is callable from kernel-space.
|
||||||
|
*
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
int kmm_trysemaphore(void)
|
||||||
|
{
|
||||||
|
return KTRYSEMAPHORE();
|
||||||
|
}
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* Function: kmm_givesemaphore
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* This is a simple redirection to the user-space mm_givesemaphore()
|
||||||
|
* function.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
* Return Value:
|
||||||
|
* OK on success; a negated errno on failure
|
||||||
|
*
|
||||||
|
* Assumptions:
|
||||||
|
* 1. mm_givesemaphore() resides in user-space
|
||||||
|
* 2. The address of the user space mm_givesemaphore() is provided in
|
||||||
|
* user_map.h
|
||||||
|
* 3. The user-space mm_semaphore() is callable from kernel-space.
|
||||||
|
*
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
void kmm_givesemaphore(void)
|
||||||
|
{
|
||||||
|
KGIVESEMAPHORE();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* CONFIG_NUTTX_KERNEL */
|
||||||
+6
-5
@@ -47,8 +47,9 @@
|
|||||||
#include <nuttx/fs.h>
|
#include <nuttx/fs.h>
|
||||||
#include <nuttx/net.h>
|
#include <nuttx/net.h>
|
||||||
#include <nuttx/lib.h>
|
#include <nuttx/lib.h>
|
||||||
#include <nuttx/mm.h>
|
#include <nuttx/kmalloc.h>
|
||||||
#include <nuttx/init.h>
|
#include <nuttx/init.h>
|
||||||
|
|
||||||
#include "os_internal.h"
|
#include "os_internal.h"
|
||||||
#include "sig_internal.h"
|
#include "sig_internal.h"
|
||||||
#include "wd_internal.h"
|
#include "wd_internal.h"
|
||||||
@@ -295,10 +296,10 @@ void os_start(void)
|
|||||||
FAR void *heap_start;
|
FAR void *heap_start;
|
||||||
size_t heap_size;
|
size_t heap_size;
|
||||||
up_allocate_heap(&heap_start, &heap_size);
|
up_allocate_heap(&heap_start, &heap_size);
|
||||||
mm_initialize(heap_start, heap_size);
|
kmm_initialize(heap_start, heap_size);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
mm_initialize((void*)CONFIG_HEAP_BASE, CONFIG_HEAP_SIZE);
|
kmm_initialize((void*)CONFIG_HEAP_BASE, CONFIG_HEAP_SIZE);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Initialize the interrupt handling subsystem (if included) */
|
/* Initialize the interrupt handling subsystem (if included) */
|
||||||
@@ -460,10 +461,10 @@ void os_start(void)
|
|||||||
* possible because if the IDLE thread is running, no other task is!
|
* possible because if the IDLE thread is running, no other task is!
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (mm_trysemaphore() == 0)
|
if (kmm_trysemaphore() == 0)
|
||||||
{
|
{
|
||||||
sched_garbagecollection();
|
sched_garbagecollection();
|
||||||
mm_givesemaphore();
|
kmm_givesemaphore();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
+2
-4
@@ -45,8 +45,6 @@
|
|||||||
#include <nuttx/kmalloc.h>
|
#include <nuttx/kmalloc.h>
|
||||||
#include <nuttx/arch.h>
|
#include <nuttx/arch.h>
|
||||||
#include <nuttx/wqueue.h>
|
#include <nuttx/wqueue.h>
|
||||||
#include <nuttx/mm.h>
|
|
||||||
|
|
||||||
#include "os_internal.h"
|
#include "os_internal.h"
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
@@ -92,7 +90,7 @@ void sched_free(FAR void *address)
|
|||||||
* manager to do this.
|
* manager to do this.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (up_interrupt_context() || mm_trysemaphore() != 0)
|
if (up_interrupt_context() || kmm_trysemaphore() != 0)
|
||||||
{
|
{
|
||||||
/* Yes.. Delay the deallocation until a more appropriate time. */
|
/* Yes.. Delay the deallocation until a more appropriate time. */
|
||||||
|
|
||||||
@@ -111,7 +109,7 @@ void sched_free(FAR void *address)
|
|||||||
/* No.. just deallocate the memory now. */
|
/* No.. just deallocate the memory now. */
|
||||||
|
|
||||||
kfree(address);
|
kfree(address);
|
||||||
mm_givesemaphore();
|
kmm_givesemaphore();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* sched/work_garbage.c
|
* sched/sched_garbage.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2009 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
|||||||
Reference in New Issue
Block a user