From b05f29dbfe070385a2e09760d0d1928f54d12640 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 3 Sep 2014 11:43:23 -0600 Subject: [PATCH] I love/hate conditional compilation --- arch/arm/src/armv7-a/arm_pgalloc.c | 6 +++--- include/nuttx/mm.h | 14 ++++++++++---- mm/kmm_heapmember.c | 4 ++++ mm/mm_brkaddr.c | 4 ++++ mm/mm_extend.c | 4 ++++ mm/umm_addregion.c | 4 ++-- mm/umm_brkaddr.c | 4 ++++ mm/umm_calloc.c | 4 ++++ mm/umm_extend.c | 4 ++++ mm/umm_free.c | 4 ++++ mm/umm_initialize.c | 4 ++-- mm/umm_mallinfo.c | 3 +++ mm/umm_malloc.c | 4 ++++ mm/umm_memalign.c | 4 ++++ mm/umm_realloc.c | 4 ++++ mm/umm_sbrk.c | 5 +++-- mm/umm_sem.c | 4 ++++ mm/umm_zalloc.c | 4 ++++ 18 files changed, 71 insertions(+), 13 deletions(-) diff --git a/arch/arm/src/armv7-a/arm_pgalloc.c b/arch/arm/src/armv7-a/arm_pgalloc.c index e58c20cd08..4dc2020f3c 100644 --- a/arch/arm/src/armv7-a/arm_pgalloc.c +++ b/arch/arm/src/armv7-a/arm_pgalloc.c @@ -133,7 +133,7 @@ static int get_pgtable(FAR group_addrenv_t *addrenv, uintptr_t vaddr) * region as part of the implementation of user sbrk(). */ - DEBUGASSERT(vadddr >= CONFIG_ARCH_HEAP_VBASE && vaddr < ARCH_HEAP_VEND); + DEBUGASSERT(vaddr >= CONFIG_ARCH_HEAP_VBASE && vaddr < ARCH_HEAP_VEND); /* Get the current level 1 entry corresponding to this vaddr */ @@ -222,7 +222,7 @@ uintptr_t pgalloc(uintptr_t brkaddr, unsigned int npages) * space and (2) extending the kernel memory regions as well. */ - DEBUGASSERT((group->flags & GROUP_FLAG_ADDRENV) != 0); + DEBUGASSERT((group->tg_flags & GROUP_FLAG_ADDRENV) != 0); /* brkaddr = 0 means that no heap has yet been allocated */ @@ -231,7 +231,7 @@ uintptr_t pgalloc(uintptr_t brkaddr, unsigned int npages) brkaddr = CONFIG_ARCH_HEAP_VBASE; } - DEBUGASSERT(vadddr >= CONFIG_ARCH_HEAP_VBASE && brkaddr < ARCH_HEAP_VEND); + DEBUGASSERT(brkaddr >= CONFIG_ARCH_HEAP_VBASE && brkaddr < ARCH_HEAP_VEND); DEBUGASSERT(MM_ISALIGNED(brkaddr)); for (; npages > 0; npages--) diff --git a/include/nuttx/mm.h b/include/nuttx/mm.h index 2dc6e1961a..3330b2bfcb 100644 --- a/include/nuttx/mm.h +++ b/include/nuttx/mm.h @@ -43,6 +43,7 @@ #include #include +#include #include /**************************************************************************** @@ -262,8 +263,7 @@ extern "C" #define EXTERN extern #endif -#if (!defined(CONFIG_BUILD_PROTECTED) && !defined(CONFIG_BUILD_KERNEL)) || \ - (defined(CONFIG_BUILD_PROTECTED) && !defined(__KERNEL__)) +#if !defined(CONFIG_BUILD_PROTECTED) || !defined(__KERNEL__) /* User heap structure: * * - Flat build: In the FLAT build, the user heap structure is a globally @@ -297,7 +297,7 @@ void mm_addregion(FAR struct mm_heap_s *heap, FAR void *heapstart, /* Functions contained in umm_initialize.c **********************************/ -#ifdef MM_KERNEL_USRHEAP_INIT +#if !defined(CONFIG_BUILD_PROTECTED) || !defined(__KERNEL__) void umm_initialize(FAR void *heap_start, size_t heap_size); #endif @@ -309,7 +309,7 @@ void kmm_initialize(FAR void *heap_start, size_t heap_size); /* Functions contained in umm_addregion.c ***********************************/ -#ifdef MM_KERNEL_USRHEAP_INIT +#if !defined(CONFIG_BUILD_PROTECTED) || !defined(__KERNEL__) void umm_addregion(FAR void *heapstart, size_t heapsize); #endif @@ -328,8 +328,10 @@ void mm_givesemaphore(FAR struct mm_heap_s *heap); /* Functions contained in umm_sem.c ****************************************/ +#if !defined(CONFIG_BUILD_PROTECTED) || !defined(__KERNEL__) int umm_trysemaphore(void); void umm_givesemaphore(void); +#endif /* Functions contained in kmm_sem.c ****************************************/ @@ -412,7 +414,9 @@ FAR void *mm_brkaddr(FAR struct mm_heap_s *heap, int region); /* Functions contained in umm_brkaddr.c *************************************/ +#if !defined(CONFIG_BUILD_PROTECTED) || !defined(__KERNEL__) FAR void *umm_brkaddr(int region); +#endif /* Functions contained in kmm_brkaddr.c *************************************/ @@ -442,7 +446,9 @@ void mm_extend(FAR struct mm_heap_s *heap, FAR void *mem, size_t size, /* Functions contained in umm_extend.c **************************************/ +#if !defined(CONFIG_BUILD_PROTECTED) || !defined(__KERNEL__) void umm_extend(FAR void *mem, size_t size, int region); +#endif /* Functions contained in kmm_extend.c **************************************/ diff --git a/mm/kmm_heapmember.c b/mm/kmm_heapmember.c index 01fa8b53c0..a91a6a6678 100644 --- a/mm/kmm_heapmember.c +++ b/mm/kmm_heapmember.c @@ -39,6 +39,10 @@ #include +#include + +#include + #if defined(CONFIG_MM_KERNEL_HEAP) && defined(CONFIG_DEBUG) /************************************************************************ diff --git a/mm/mm_brkaddr.c b/mm/mm_brkaddr.c index 693b810867..8476050c4e 100644 --- a/mm/mm_brkaddr.c +++ b/mm/mm_brkaddr.c @@ -63,7 +63,11 @@ FAR void *mm_brkaddr(FAR struct mm_heap_s *heap, int region) { uintptr_t brkaddr; +#if CONFIG_MM_REGIONS > 1 DEBUGASSERT(heap && region < heap->mm_nregions); +#else + DEBUGASSERT(heap && region == 0); +#endif brkaddr = (uintptr_t)heap->mm_heapend[region]; return brkaddr ? (FAR void *)(brkaddr + SIZEOF_MM_ALLOCNODE) : 0; diff --git a/mm/mm_extend.c b/mm/mm_extend.c index 3aa3f37d75..8343607605 100644 --- a/mm/mm_extend.c +++ b/mm/mm_extend.c @@ -73,7 +73,11 @@ void mm_extend(FAR struct mm_heap_s *heap, FAR void *mem, size_t size, /* Make sure that we were passed valid parameters */ DEBUGASSERT(heap && mem); +#if CONFIG_MM_REGIONS > 1 DEBUGASSERT(size >= MIN_EXTEND && (unsigned)region < heap->mm_nregions); +#else + DEBUGASSERT(size >= MIN_EXTEND && (unsigned)region == 0); +#endif /* Make sure that the memory region are properly aligned */ diff --git a/mm/umm_addregion.c b/mm/umm_addregion.c index 22a03cb8a0..5cef04b016 100644 --- a/mm/umm_addregion.c +++ b/mm/umm_addregion.c @@ -41,7 +41,7 @@ #include -#ifdef MM_KERNEL_USRHEAP_INIT +#if !defined(CONFIG_BUILD_PROTECTED) || !defined(__KERNEL__) /************************************************************************ * Pre-processor definition @@ -102,4 +102,4 @@ void umm_addregion(FAR void *heap_start, size_t heap_size) mm_addregion(USR_HEAP, heap_start, heap_size); } -#endif /* MM_KERNEL_USRHEAP_INIT */ +#endif /* !CONFIG_BUILD_PROTECTED || !__KERNEL__ */ diff --git a/mm/umm_brkaddr.c b/mm/umm_brkaddr.c index 6381d368bc..25e399542f 100644 --- a/mm/umm_brkaddr.c +++ b/mm/umm_brkaddr.c @@ -43,6 +43,8 @@ #include +#if !defined(CONFIG_BUILD_PROTECTED) || !defined(__KERNEL__) + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -80,3 +82,5 @@ FAR void *umm_brkaddr(int region) { return mm_brkaddr(USR_HEAP, region); } + +#endif /* !CONFIG_BUILD_PROTECTED || !__KERNEL__ */ diff --git a/mm/umm_calloc.c b/mm/umm_calloc.c index 0009b5a1fd..ed1a2d606b 100644 --- a/mm/umm_calloc.c +++ b/mm/umm_calloc.c @@ -43,6 +43,8 @@ #include +#if !defined(CONFIG_BUILD_PROTECTED) || !defined(__KERNEL__) + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -80,3 +82,5 @@ FAR void *calloc(size_t n, size_t elem_size) { return mm_calloc(USR_HEAP, n, elem_size); } + +#endif /* !CONFIG_BUILD_PROTECTED || !__KERNEL__ */ diff --git a/mm/umm_extend.c b/mm/umm_extend.c index f8edc9ef62..af1bb18d35 100644 --- a/mm/umm_extend.c +++ b/mm/umm_extend.c @@ -41,6 +41,8 @@ #include +#if !defined(CONFIG_BUILD_PROTECTED) || !defined(__KERNEL__) + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -79,3 +81,5 @@ void umm_extend(FAR void *mem, size_t size, int region) { mm_extend(USR_HEAP, mem, size, region); } + +#endif /* !CONFIG_BUILD_PROTECTED || !__KERNEL__ */ diff --git a/mm/umm_free.c b/mm/umm_free.c index d26d7ba11a..6c6d59be76 100644 --- a/mm/umm_free.c +++ b/mm/umm_free.c @@ -43,6 +43,8 @@ #include +#if !defined(CONFIG_BUILD_PROTECTED) || !defined(__KERNEL__) + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -85,3 +87,5 @@ void free(FAR void *mem) { mm_free(USR_HEAP, mem); } + +#endif /* !CONFIG_BUILD_PROTECTED || !__KERNEL__ */ diff --git a/mm/umm_initialize.c b/mm/umm_initialize.c index 5b926504d5..d7288e4744 100644 --- a/mm/umm_initialize.c +++ b/mm/umm_initialize.c @@ -43,7 +43,7 @@ #include -#ifdef MM_KERNEL_USRHEAP_INIT +#if !defined(CONFIG_BUILD_PROTECTED) || !defined(__KERNEL__) /************************************************************************ * Pre-processor definition @@ -109,4 +109,4 @@ void umm_initialize(FAR void *heap_start, size_t heap_size) mm_initialize(USR_HEAP, heap_start, heap_size); } -#endif /* MM_KERNEL_USRHEAP_INIT */ +#endif /* !CONFIG_BUILD_PROTECTED || !__KERNEL__ */ diff --git a/mm/umm_mallinfo.c b/mm/umm_mallinfo.c index 447269f006..c7ea241c07 100644 --- a/mm/umm_mallinfo.c +++ b/mm/umm_mallinfo.c @@ -43,6 +43,8 @@ #include +#if !defined(CONFIG_BUILD_PROTECTED) || !defined(__KERNEL__) + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -102,3 +104,4 @@ int mallinfo(struct mallinfo *info) } #endif /* CONFIG_CAN_PASS_STRUCTS */ +#endif /* !CONFIG_BUILD_PROTECTED || !__KERNEL__ */ diff --git a/mm/umm_malloc.c b/mm/umm_malloc.c index fd4fe9608d..31511b82f8 100644 --- a/mm/umm_malloc.c +++ b/mm/umm_malloc.c @@ -44,6 +44,8 @@ #include +#if !defined(CONFIG_BUILD_PROTECTED) || !defined(__KERNEL__) + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -135,3 +137,5 @@ FAR void *malloc(size_t size) return mm_malloc(USR_HEAP, size); #endif } + +#endif /* !CONFIG_BUILD_PROTECTED || !__KERNEL__ */ diff --git a/mm/umm_memalign.c b/mm/umm_memalign.c index 51b0f923ca..3659606f30 100644 --- a/mm/umm_memalign.c +++ b/mm/umm_memalign.c @@ -43,6 +43,8 @@ #include +#if !defined(CONFIG_BUILD_PROTECTED) || !defined(__KERNEL__) + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -89,3 +91,5 @@ FAR void *memalign(size_t alignment, size_t size) { return mm_memalign(USR_HEAP, alignment, size); } + +#endif /* !CONFIG_BUILD_PROTECTED || !__KERNEL__ */ diff --git a/mm/umm_realloc.c b/mm/umm_realloc.c index 344d24d687..45da6e7ec0 100644 --- a/mm/umm_realloc.c +++ b/mm/umm_realloc.c @@ -43,6 +43,8 @@ #include +#if !defined(CONFIG_BUILD_PROTECTED) || !defined(__KERNEL__) + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -91,3 +93,5 @@ FAR void *realloc(FAR void *oldmem, size_t size) { return mm_realloc(USR_HEAP, oldmem, size); } + +#endif /* !CONFIG_BUILD_PROTECTED || !__KERNEL__ */ diff --git a/mm/umm_sbrk.c b/mm/umm_sbrk.c index 349c61b866..19b945d3c7 100644 --- a/mm/umm_sbrk.c +++ b/mm/umm_sbrk.c @@ -45,7 +45,8 @@ #include #if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_MM_PGALLOC) && \ - defined(CONFIG_ARCH_USE_MMU) + defined(CONFIG_ARCH_USE_MMU) && (!defined(CONFIG_BUILD_PROTECTED) || \ + !defined(__KERNEL__)) /**************************************************************************** * Pre-processor Definitions @@ -109,4 +110,4 @@ FAR void *sbrk(intptr_t incr) return mm_sbrk(USR_HEAP, incr, CONFIG_ARCH_STACK_NPAGES << MM_PGSHIFT); } -#endif /* CONFIG_ARCH_ADDRENV && CONFIG_MM_PGALLOC && CONFIG_ARCH_USE_MMU */ +#endif /* CONFIG_ARCH_ADDRENV && CONFIG_MM_PGALLOC && ... */ diff --git a/mm/umm_sem.c b/mm/umm_sem.c index 8e899994b6..baa992ebb3 100644 --- a/mm/umm_sem.c +++ b/mm/umm_sem.c @@ -41,6 +41,8 @@ #include +#if !defined(CONFIG_BUILD_PROTECTED) || !defined(__KERNEL__) + /************************************************************************ * Pre-processor definition ************************************************************************/ @@ -119,3 +121,5 @@ void umm_givesemaphore(void) { mm_givesemaphore(USR_HEAP); } + +#endif /* !CONFIG_BUILD_PROTECTED || !__KERNEL__ */ diff --git a/mm/umm_zalloc.c b/mm/umm_zalloc.c index 20a37c2e21..06d9d10475 100644 --- a/mm/umm_zalloc.c +++ b/mm/umm_zalloc.c @@ -44,6 +44,8 @@ #include +#if !defined(CONFIG_BUILD_PROTECTED) || !defined(__KERNEL__) + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -102,3 +104,5 @@ FAR void *zalloc(size_t size) return mm_zalloc(USR_HEAP, size); #endif } + +#endif /* !CONFIG_BUILD_PROTECTED || !__KERNEL__ */