From 19fa0bdcc2946fea57857ec8e16191f8ab037c18 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 22 Sep 2014 10:42:26 -0600 Subject: Move the kernel heap allocator front-end from mm/. to mm/kmm_heap/. --- nuttx/mm/Makefile | 19 +----- nuttx/mm/kmm_addregion.c | 86 ------------------------- nuttx/mm/kmm_brkaddr.c | 69 -------------------- nuttx/mm/kmm_calloc.c | 67 ------------------- nuttx/mm/kmm_extend.c | 68 -------------------- nuttx/mm/kmm_free.c | 82 ------------------------ nuttx/mm/kmm_heap/kmm_addregion.c | 86 +++++++++++++++++++++++++ nuttx/mm/kmm_heap/kmm_brkaddr.c | 69 ++++++++++++++++++++ nuttx/mm/kmm_heap/kmm_calloc.c | 67 +++++++++++++++++++ nuttx/mm/kmm_heap/kmm_extend.c | 68 ++++++++++++++++++++ nuttx/mm/kmm_heap/kmm_free.c | 82 ++++++++++++++++++++++++ nuttx/mm/kmm_heap/kmm_heapmember.c | 124 ++++++++++++++++++++++++++++++++++++ nuttx/mm/kmm_heap/kmm_initialize.c | 91 ++++++++++++++++++++++++++ nuttx/mm/kmm_heap/kmm_kernel.c | 127 +++++++++++++++++++++++++++++++++++++ nuttx/mm/kmm_heap/kmm_mallinfo.c | 90 ++++++++++++++++++++++++++ nuttx/mm/kmm_heap/kmm_malloc.c | 89 ++++++++++++++++++++++++++ nuttx/mm/kmm_heap/kmm_memalign.c | 80 +++++++++++++++++++++++ nuttx/mm/kmm_heap/kmm_realloc.c | 78 +++++++++++++++++++++++ nuttx/mm/kmm_heap/kmm_sbrk.c | 91 ++++++++++++++++++++++++++ nuttx/mm/kmm_heap/kmm_sem.c | 104 ++++++++++++++++++++++++++++++ nuttx/mm/kmm_heap/kmm_zalloc.c | 73 +++++++++++++++++++++ nuttx/mm/kmm_heapmember.c | 124 ------------------------------------ nuttx/mm/kmm_initialize.c | 91 -------------------------- nuttx/mm/kmm_kernel.c | 127 ------------------------------------- nuttx/mm/kmm_mallinfo.c | 90 -------------------------- nuttx/mm/kmm_malloc.c | 89 -------------------------- nuttx/mm/kmm_memalign.c | 80 ----------------------- nuttx/mm/kmm_realloc.c | 78 ----------------------- nuttx/mm/kmm_sbrk.c | 91 -------------------------- nuttx/mm/kmm_sem.c | 104 ------------------------------ nuttx/mm/kmm_zalloc.c | 73 --------------------- 31 files changed, 1320 insertions(+), 1337 deletions(-) delete mode 100644 nuttx/mm/kmm_addregion.c delete mode 100644 nuttx/mm/kmm_brkaddr.c delete mode 100644 nuttx/mm/kmm_calloc.c delete mode 100644 nuttx/mm/kmm_extend.c delete mode 100644 nuttx/mm/kmm_free.c create mode 100644 nuttx/mm/kmm_heap/kmm_addregion.c create mode 100644 nuttx/mm/kmm_heap/kmm_brkaddr.c create mode 100644 nuttx/mm/kmm_heap/kmm_calloc.c create mode 100644 nuttx/mm/kmm_heap/kmm_extend.c create mode 100644 nuttx/mm/kmm_heap/kmm_free.c create mode 100644 nuttx/mm/kmm_heap/kmm_heapmember.c create mode 100644 nuttx/mm/kmm_heap/kmm_initialize.c create mode 100644 nuttx/mm/kmm_heap/kmm_kernel.c create mode 100644 nuttx/mm/kmm_heap/kmm_mallinfo.c create mode 100644 nuttx/mm/kmm_heap/kmm_malloc.c create mode 100644 nuttx/mm/kmm_heap/kmm_memalign.c create mode 100644 nuttx/mm/kmm_heap/kmm_realloc.c create mode 100755 nuttx/mm/kmm_heap/kmm_sbrk.c create mode 100644 nuttx/mm/kmm_heap/kmm_sem.c create mode 100644 nuttx/mm/kmm_heap/kmm_zalloc.c delete mode 100644 nuttx/mm/kmm_heapmember.c delete mode 100644 nuttx/mm/kmm_initialize.c delete mode 100644 nuttx/mm/kmm_kernel.c delete mode 100644 nuttx/mm/kmm_mallinfo.c delete mode 100644 nuttx/mm/kmm_malloc.c delete mode 100644 nuttx/mm/kmm_memalign.c delete mode 100644 nuttx/mm/kmm_realloc.c delete mode 100755 nuttx/mm/kmm_sbrk.c delete mode 100644 nuttx/mm/kmm_sem.c delete mode 100644 nuttx/mm/kmm_zalloc.c (limited to 'nuttx/mm') diff --git a/nuttx/mm/Makefile b/nuttx/mm/Makefile index 2aa90e5e4..65c061c2e 100644 --- a/nuttx/mm/Makefile +++ b/nuttx/mm/Makefile @@ -77,24 +77,7 @@ ifeq ($(CONFIG_BUILD_KERNEL),y) CSRCS += umm_sbrk.c endif -# Kernel allocator - -ifeq ($(CONFIG_MM_KERNEL_HEAP),y) -CSRCS += kmm_initialize.c kmm_addregion.c kmm_sem.c -CSRCS += kmm_brkaddr.c kmm_calloc.c kmm_extend.c kmm_free.c kmm_mallinfo.c -CSRCS += kmm_malloc.c kmm_memalign.c kmm_realloc.c kmm_zalloc.c - -ifeq ($(CONFIG_BUILD_KERNEL),y) -CSRCS += kmm_sbrk.c -endif - -ifeq ($(CONFIG_DEBUG),y) -CSRCS += kmm_heapmember.c -endif -endif - -# An optional granule allocator - +include kmm_heap/Make.defs include mm_gran/Make.defs BINDIR ?= bin diff --git a/nuttx/mm/kmm_addregion.c b/nuttx/mm/kmm_addregion.c deleted file mode 100644 index 574a983f6..000000000 --- a/nuttx/mm/kmm_addregion.c +++ /dev/null @@ -1,86 +0,0 @@ -/************************************************************************ - * mm/kmm_addregion.c - * - * Copyright (C) 2014 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include - -#ifdef CONFIG_MM_KERNEL_HEAP - -/************************************************************************ - * Pre-processor definition - ************************************************************************/ - -/************************************************************************ - * Private Types - ************************************************************************/ - -/************************************************************************ - * Public Data - ************************************************************************/ - -/************************************************************************ - * Private Functions - ************************************************************************/ - -/************************************************************************ - * Public Functions - ************************************************************************/ - -/************************************************************************ - * Name: kmm_addregion - * - * Description: - * This function adds a region of contiguous memory to the kernel heap. - * - * Parameters: - * heap_start - Address of the beginning of the memory region - * heap_size - The size (in bytes) if the memory region. - * - * Return Value: - * None - * - ************************************************************************/ - -void kmm_addregion(FAR void *heap_start, size_t heap_size) -{ - return mm_addregion(&g_kmmheap, heap_start, heap_size); -} - -#endif /* CONFIG_MM_KERNEL_HEAP */ diff --git a/nuttx/mm/kmm_brkaddr.c b/nuttx/mm/kmm_brkaddr.c deleted file mode 100644 index 463744a2a..000000000 --- a/nuttx/mm/kmm_brkaddr.c +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** - * mm/kmm_breakaddr.c - * - * Copyright (C) 2014 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include - -#include - -#ifdef CONFIG_MM_KERNEL_HEAP - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: kmm_brkaddr - * - * Description: - * Return the break address of a region in the user heap - * - ****************************************************************************/ - -FAR void *kmm_brkaddr(int region) -{ - return mm_brkaddr(&g_kmmheap, region); -} - -#endif /* CONFIG_MM_KERNEL_HEAP */ diff --git a/nuttx/mm/kmm_calloc.c b/nuttx/mm/kmm_calloc.c deleted file mode 100644 index db8ac185f..000000000 --- a/nuttx/mm/kmm_calloc.c +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** - * mm/kmm_calloc.c - * - * Copyright (C) 2014 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include - -#ifdef CONFIG_MM_KERNEL_HEAP - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: kmm_calloc - * - * Description: - * kmm_calloc is a thin wrapper for mm_calloc() - * - ****************************************************************************/ - -FAR void *kmm_calloc(size_t n, size_t elem_size) -{ - return mm_calloc(&g_kmmheap, n, elem_size); -} - -#endif /* CONFIG_MM_KERNEL_HEAP */ diff --git a/nuttx/mm/kmm_extend.c b/nuttx/mm/kmm_extend.c deleted file mode 100644 index 1ae1e2865..000000000 --- a/nuttx/mm/kmm_extend.c +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** - * mm/kmm_extend.c - * - * Copyright (C) 2014 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include - -#ifdef CONFIG_MM_KERNEL_HEAP - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: kmm_extend - * - * Description: - * Extend a region in the kernel heap by add a block of (virtually) - * contiguous memory to the end of the heap. - * - ****************************************************************************/ - -void kmm_extend(FAR void *mem, size_t size, int region) -{ - mm_extend(&g_kmmheap, mem, size, region); -} - -#endif /* CONFIG_MM_KERNEL_HEAP */ diff --git a/nuttx/mm/kmm_free.c b/nuttx/mm/kmm_free.c deleted file mode 100644 index 92b0059ba..000000000 --- a/nuttx/mm/kmm_free.c +++ /dev/null @@ -1,82 +0,0 @@ -/**************************************************************************** - * mm/kmm_free.c - * - * Copyright (C) 2007, 2009, 2013-2014 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include - -#include - -#ifdef CONFIG_MM_KERNEL_HEAP - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/************************************************************************ - * Name: kmm_free - * - * Description: - * Returns a chunk of kernel memory to the list of free nodes, merging - * with adjacent free chunks if possible. - * - * Parameters: - * None - * - * Return Value: - * None - * - ************************************************************************/ - -void kmm_free(FAR void *mem) -{ - DEBUGASSERT(kmm_heapmember(mem)); - mm_free(&g_kmmheap, mem); -} - -#endif /* CONFIG_MM_KERNEL_HEAP */ diff --git a/nuttx/mm/kmm_heap/kmm_addregion.c b/nuttx/mm/kmm_heap/kmm_addregion.c new file mode 100644 index 000000000..da1068cee --- /dev/null +++ b/nuttx/mm/kmm_heap/kmm_addregion.c @@ -0,0 +1,86 @@ +/************************************************************************ + * mm/kmm_heap/kmm_addregion.c + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include + +#ifdef CONFIG_MM_KERNEL_HEAP + +/************************************************************************ + * Pre-processor definition + ************************************************************************/ + +/************************************************************************ + * Private Types + ************************************************************************/ + +/************************************************************************ + * Public Data + ************************************************************************/ + +/************************************************************************ + * Private Functions + ************************************************************************/ + +/************************************************************************ + * Public Functions + ************************************************************************/ + +/************************************************************************ + * Name: kmm_addregion + * + * Description: + * This function adds a region of contiguous memory to the kernel heap. + * + * Parameters: + * heap_start - Address of the beginning of the memory region + * heap_size - The size (in bytes) if the memory region. + * + * Return Value: + * None + * + ************************************************************************/ + +void kmm_addregion(FAR void *heap_start, size_t heap_size) +{ + return mm_addregion(&g_kmmheap, heap_start, heap_size); +} + +#endif /* CONFIG_MM_KERNEL_HEAP */ diff --git a/nuttx/mm/kmm_heap/kmm_brkaddr.c b/nuttx/mm/kmm_heap/kmm_brkaddr.c new file mode 100644 index 000000000..34c8855df --- /dev/null +++ b/nuttx/mm/kmm_heap/kmm_brkaddr.c @@ -0,0 +1,69 @@ +/**************************************************************************** + * mm/kmm_heap/kmm_breakaddr.c + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include + +#include + +#ifdef CONFIG_MM_KERNEL_HEAP + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: kmm_brkaddr + * + * Description: + * Return the break address of a region in the user heap + * + ****************************************************************************/ + +FAR void *kmm_brkaddr(int region) +{ + return mm_brkaddr(&g_kmmheap, region); +} + +#endif /* CONFIG_MM_KERNEL_HEAP */ diff --git a/nuttx/mm/kmm_heap/kmm_calloc.c b/nuttx/mm/kmm_heap/kmm_calloc.c new file mode 100644 index 000000000..070ed568c --- /dev/null +++ b/nuttx/mm/kmm_heap/kmm_calloc.c @@ -0,0 +1,67 @@ +/**************************************************************************** + * mm/kmm_heap/kmm_calloc.c + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include + +#ifdef CONFIG_MM_KERNEL_HEAP + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: kmm_calloc + * + * Description: + * kmm_calloc is a thin wrapper for mm_calloc() + * + ****************************************************************************/ + +FAR void *kmm_calloc(size_t n, size_t elem_size) +{ + return mm_calloc(&g_kmmheap, n, elem_size); +} + +#endif /* CONFIG_MM_KERNEL_HEAP */ diff --git a/nuttx/mm/kmm_heap/kmm_extend.c b/nuttx/mm/kmm_heap/kmm_extend.c new file mode 100644 index 000000000..e0a6c701f --- /dev/null +++ b/nuttx/mm/kmm_heap/kmm_extend.c @@ -0,0 +1,68 @@ +/**************************************************************************** + * mm/kmm_heap/kmm_extend.c + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include + +#ifdef CONFIG_MM_KERNEL_HEAP + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: kmm_extend + * + * Description: + * Extend a region in the kernel heap by add a block of (virtually) + * contiguous memory to the end of the heap. + * + ****************************************************************************/ + +void kmm_extend(FAR void *mem, size_t size, int region) +{ + mm_extend(&g_kmmheap, mem, size, region); +} + +#endif /* CONFIG_MM_KERNEL_HEAP */ diff --git a/nuttx/mm/kmm_heap/kmm_free.c b/nuttx/mm/kmm_heap/kmm_free.c new file mode 100644 index 000000000..15b9f8ac4 --- /dev/null +++ b/nuttx/mm/kmm_heap/kmm_free.c @@ -0,0 +1,82 @@ +/**************************************************************************** + * mm/kmm_heap/kmm_free.c + * + * Copyright (C) 2007, 2009, 2013-2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include + +#include + +#ifdef CONFIG_MM_KERNEL_HEAP + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/************************************************************************ + * Name: kmm_free + * + * Description: + * Returns a chunk of kernel memory to the list of free nodes, merging + * with adjacent free chunks if possible. + * + * Parameters: + * None + * + * Return Value: + * None + * + ************************************************************************/ + +void kmm_free(FAR void *mem) +{ + DEBUGASSERT(kmm_heapmember(mem)); + mm_free(&g_kmmheap, mem); +} + +#endif /* CONFIG_MM_KERNEL_HEAP */ diff --git a/nuttx/mm/kmm_heap/kmm_heapmember.c b/nuttx/mm/kmm_heap/kmm_heapmember.c new file mode 100644 index 000000000..2a1ca7c00 --- /dev/null +++ b/nuttx/mm/kmm_heap/kmm_heapmember.c @@ -0,0 +1,124 @@ +/************************************************************************ + * mm/kmm_heap/kmm_heapmember.c + * + * Copyright (C) 2013-2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include + +#include + +#if defined(CONFIG_MM_KERNEL_HEAP) && defined(CONFIG_DEBUG) + +/************************************************************************ + * Pre-processor definition + ************************************************************************/ + +/************************************************************************ + * Private Types + ************************************************************************/ + +/************************************************************************ + * Public Data + ************************************************************************/ + +/************************************************************************ + * Private Functions + ************************************************************************/ + +/************************************************************************ + * Public Functions + ************************************************************************/ + +/************************************************************************ + * Name: kmm_heapmember + * + * Description: + * Check if an address lies in the kernel heap. + * + * Parameters: + * mem - The address to check + * + * Return Value: + * true if the address is a member of the kernel heap. false if not + * not. If the address is not a member of the kernel heap, then it + * must be a member of the user-space heap (unchecked) + * + ************************************************************************/ + +bool kmm_heapmember(FAR void *mem) +{ +#if CONFIG_MM_REGIONS > 1 + int i; + + /* A valid address from the kernel heap for this region would have to lie + * between the region's two guard nodes. + */ + + for (i = 0; i < g_kmmheap.mm_nregions; i++) + { + if (mem > (FAR void *)g_kmmheap.mm_heapstart[i] && + mem < (FAR void *)g_kmmheap.mm_heapend[i]) + { + return true; + } + } + + /* The address does not like any any region assigned to kernel heap */ + + return false; + +#else + /* A valid address from the kernel heap would have to lie between the + * two guard nodes. + */ + + if (mem > (FAR void *)g_kmmheap.mm_heapstart[0] && + mem < (FAR void *)g_kmmheap.mm_heapend[0]) + { + return true; + } + + /* Otherwise, the address does not lie in the kernel heap */ + + return false; + +#endif +} + +#endif /* CONFIG_MM_KERNEL_HEAP && CONFIG_DEBUG */ diff --git a/nuttx/mm/kmm_heap/kmm_initialize.c b/nuttx/mm/kmm_heap/kmm_initialize.c new file mode 100644 index 000000000..deeb0e25f --- /dev/null +++ b/nuttx/mm/kmm_heap/kmm_initialize.c @@ -0,0 +1,91 @@ +/************************************************************************ + * mm/kmm_heap/kmm_initialize.c + * + * Copyright (C) 2013-2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include + +#ifdef CONFIG_MM_KERNEL_HEAP + +/************************************************************************ + * Pre-processor definition + ************************************************************************/ + +/************************************************************************ + * Private Types + ************************************************************************/ + +/************************************************************************ + * Public Data + ************************************************************************/ + +/* This is the kernel heap */ + +struct mm_heap_s g_kmmheap; + +/************************************************************************ + * Private Functions + ************************************************************************/ + +/************************************************************************ + * Public Functions + ************************************************************************/ + +/************************************************************************ + * Name: kmm_initialize + * + * Description: + * Initialize the kernel heap data structures, providing the initial + * heap region. + * + * 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 + * + ************************************************************************/ + +void kmm_initialize(FAR void *heap_start, size_t heap_size) +{ + return mm_initialize(&g_kmmheap, heap_start, heap_size); +} + +#endif /* CONFIG_MM_KERNEL_HEAP */ diff --git a/nuttx/mm/kmm_heap/kmm_kernel.c b/nuttx/mm/kmm_heap/kmm_kernel.c new file mode 100644 index 000000000..4ab8e1b2b --- /dev/null +++ b/nuttx/mm/kmm_heap/kmm_kernel.c @@ -0,0 +1,127 @@ +/************************************************************************ + * mm/kmm_heap/kmm_kernel.c + * + * Copyright (C) 2013-2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include + +#include + +#if ((defined(CONFIG_BUILD_PROTECTED) && defined(__KERNEL__)) || \ + defined(CONFIG_BUILD_KERNEL)) && defined(CONFIG_MM_KERNEL_HEAP) + +/************************************************************************ + * Pre-processor definition + ************************************************************************/ + +/************************************************************************ + * Private Types + ************************************************************************/ + +/************************************************************************ + * Public Data + ************************************************************************/ + +/************************************************************************ + * Private Functions + ************************************************************************/ + +/************************************************************************ + * Public Functions + ************************************************************************/ + +/************************************************************************ + * Name: kmm_heapmember + * + * Description: + * Check if an address lies in the kernel heap. + * + * Parameters: + * mem - The address to check + * + * Return Value: + * true if the address is a member of the kernel heap. false if not + * not. If the address is not a member of the kernel heap, then it + * must be a member of the user-space heap (unchecked) + * + ************************************************************************/ + +#ifdef CONFIG_DEBUG +bool kmm_heapmember(FAR void *mem) +{ +#if CONFIG_MM_REGIONS > 1 + int i; + + /* A valid address from the kernel heap for this region would have to lie + * between the region's two guard nodes. + */ + + for (i = 0; i < g_kmmheap.mm_nregions; i++) + { + if (mem > (FAR void *)g_kmmheap.mm_heapstart[i] && + mem < (FAR void *)g_kmmheap.mm_heapend[i]) + { + return true; + } + } + + /* The address does not like any any region assigned to kernel heap */ + + return false; + +#else + /* A valid address from the kernel heap would have to lie between the + * two guard nodes. + */ + + if (mem > (FAR void *)g_kmmheap.mm_heapstart[0] && + mem < (FAR void *)g_kmmheap.mm_heapend[0]) + { + return true; + } + + /* Otherwise, the address does not lie in the kernel heap */ + + return false; + +#endif +} +#endif + +#endif /* ((CONFIG_BUILD_PROTECTED && __KERNEL__) || CONFIG_BUILD_KERNEL) && CONFIG_MM_KERNEL_HEAP*/ diff --git a/nuttx/mm/kmm_heap/kmm_mallinfo.c b/nuttx/mm/kmm_heap/kmm_mallinfo.c new file mode 100644 index 000000000..8a0ddf0e8 --- /dev/null +++ b/nuttx/mm/kmm_heap/kmm_mallinfo.c @@ -0,0 +1,90 @@ +/**************************************************************************** + * mm/kmm_heap/kmm_mallinfo.c + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include + +#include + +#ifdef CONFIG_MM_KERNEL_HEAP + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: kmm_mallinfo + * + * Description: + * kmm_mallinfo returns a copy of updated current heap information for the + * kernel heap + * + ****************************************************************************/ + +#ifdef CONFIG_CAN_PASS_STRUCTS + +struct mallinfo kmm_mallinfo(void) +{ + struct mallinfo info; + mm_mallinfo(&g_kmmheap, &info); + return info; +} + +#else + +int kmm_mallinfo(struct mallinfo *info) +{ + return mm_mallinfo(&g_kmmheap, info); +} + +#endif /* CONFIG_CAN_PASS_STRUCTS */ +#endif /* CONFIG_MM_KERNEL_HEAP */ diff --git a/nuttx/mm/kmm_heap/kmm_malloc.c b/nuttx/mm/kmm_heap/kmm_malloc.c new file mode 100644 index 000000000..22b5d4894 --- /dev/null +++ b/nuttx/mm/kmm_heap/kmm_malloc.c @@ -0,0 +1,89 @@ +/**************************************************************************** + * mm/kmm_heap/kmm_malloc.c + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include + +#ifdef CONFIG_MM_KERNEL_HEAP + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Type Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/************************************************************************ + * Name: kmm_malloc + * + * Description: + * Allocate memory from the kernel heap. + * + * Parameters: + * size - Size (in bytes) of the memory region to be allocated. + * + * Return Value: + * The address of the allocated memory (NULL on failure to allocate) + * + ************************************************************************/ + +FAR void *kmm_malloc(size_t size) +{ + return mm_malloc(&g_kmmheap, size); +} + +#endif /* CONFIG_MM_KERNEL_HEAP */ diff --git a/nuttx/mm/kmm_heap/kmm_memalign.c b/nuttx/mm/kmm_heap/kmm_memalign.c new file mode 100644 index 000000000..b74c40866 --- /dev/null +++ b/nuttx/mm/kmm_heap/kmm_memalign.c @@ -0,0 +1,80 @@ +/**************************************************************************** + * mm/kmm_heap/kmm_memalign.c + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include + +#include + +#ifdef CONFIG_MM_KERNEL_HEAP + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/************************************************************************ + * Name: kmm_memalign + * + * Description: + * Allocate aligned memory in the kernel heap. + * + * Parameters: + * alignment - Log2 byte alignment + * size - Size (in bytes) of the new memory region to be allocated. + * + * Return Value: + * The address of the re-allocated memory (NULL on failure to allocate) + * + ************************************************************************/ + +FAR void *kmm_memalign(size_t alignment, size_t size) +{ + return mm_memalign(&g_kmmheap, alignment, size); +} + +#endif /* CONFIG_MM_KERNEL_HEAP */ diff --git a/nuttx/mm/kmm_heap/kmm_realloc.c b/nuttx/mm/kmm_heap/kmm_realloc.c new file mode 100644 index 000000000..f41e69182 --- /dev/null +++ b/nuttx/mm/kmm_heap/kmm_realloc.c @@ -0,0 +1,78 @@ +/**************************************************************************** + * mm/kmm_heap/kmm_realloc.c + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include + +#ifdef CONFIG_MM_KERNEL_HEAP + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: kmm_realloc + * + * Description: + * Re-allocate memory in the kernel heap. + * + * Parameters: + * oldmem - The old memory allocated + * newsize - Size (in bytes) of the new memory region to be re-allocated. + * + * Return Value: + * The address of the re-allocated memory (NULL on failure to re-allocate) + * + ****************************************************************************/ + +FAR void *kmm_realloc(FAR void *oldmem, size_t newsize) +{ + return mm_realloc(&g_kmmheap, oldmem, newsize); +} + +#endif /* CONFIG_MM_KERNEL_HEAP */ diff --git a/nuttx/mm/kmm_heap/kmm_sbrk.c b/nuttx/mm/kmm_heap/kmm_sbrk.c new file mode 100755 index 000000000..59dd810e9 --- /dev/null +++ b/nuttx/mm/kmm_heap/kmm_sbrk.c @@ -0,0 +1,91 @@ +/**************************************************************************** + * mm/kmm_heap/kmm_sbrk.c + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include + +#if defined(CONFIG_BUILD_KERNEL) && defined(__KERNEL__) + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: kmm_sbrk + * + * Description: + * The sbrk() function is used to change the amount of space allocated + * for the calling process. The change is made by resetting the process' + * break value and allocating the appropriate amount of space. The amount + * of allocated space increases as the break value increases. + * + * The sbrk() function adds 'incr' bytes to the break value and changes + * the allocated space accordingly. If incr is negative, the amount of + * allocated space is decreased by incr bytes. The current value of the + * program break is returned by sbrk(0). + * + * Input Parameters: + * incr - Specifies the number of bytes to add or to remove from the + * space allocated for the process. + * + * Returned Value: + * Upon successful completion, sbrk() returns the prior break value. + * Otherwise, it returns (void *)-1 and sets errno to indicate the + * error: + * + * ENOMEM - The requested change would allocate more space than + * allowed under system limits. + * EAGAIN - The total amount of system memory available for allocation + * to this process is temporarily insufficient. This may occur even + * though the space requested was less than the maximum data segment + * size. + * + ****************************************************************************/ + +FAR void *kmm_sbrk(intptr_t incr) +{ + return mm_sbrk(&g_kmmheap, incr, UINTPTR_MAX); +} + +#endif /* CONFIG_BUILD_KERNEL && __KERNEL__ */ diff --git a/nuttx/mm/kmm_heap/kmm_sem.c b/nuttx/mm/kmm_heap/kmm_sem.c new file mode 100644 index 000000000..3a274bc04 --- /dev/null +++ b/nuttx/mm/kmm_heap/kmm_sem.c @@ -0,0 +1,104 @@ +/************************************************************************ + * mm/kmm_heap/kmm_sem.c + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include + +#ifdef CONFIG_MM_KERNEL_HEAP + +/************************************************************************ + * Pre-processor definition + ************************************************************************/ + +/************************************************************************ + * Private Types + ************************************************************************/ + +/************************************************************************ + * Public Data + ************************************************************************/ + +/************************************************************************ + * Private Functions + ************************************************************************/ + +/************************************************************************ + * Public Functions + ************************************************************************/ + +/************************************************************************ + * Name: kmm_trysemaphore + * + * Description: + * Try to take the kernel heap semaphore. + * + * Parameters: + * None + * + * Return Value: + * OK on success; a negated errno on failure + * + ************************************************************************/ + +int kmm_trysemaphore(void) +{ + return mm_trysemaphore(&g_kmmheap); +} + +/************************************************************************ + * Name: kmm_givesemaphore + * + * Description: + * Give the kernel heap semaphore. + * + * Parameters: + * None + * + * Return Value: + * OK on success; a negated errno on failure + * + ************************************************************************/ + +void kmm_givesemaphore(void) +{ + return mm_givesemaphore(&g_kmmheap); +} + +#endif /* CONFIG_MM_KERNEL_HEAP */ diff --git a/nuttx/mm/kmm_heap/kmm_zalloc.c b/nuttx/mm/kmm_heap/kmm_zalloc.c new file mode 100644 index 000000000..af70afe9c --- /dev/null +++ b/nuttx/mm/kmm_heap/kmm_zalloc.c @@ -0,0 +1,73 @@ +/**************************************************************************** + * mm/kmm_heap/kmm_zalloc.c + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include + +#ifdef CONFIG_MM_KERNEL_HEAP + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/************************************************************************ + * Name: kmm_zalloc + * + * Description: + * Allocate and zero memory from the kernel heap. + * + * Parameters: + * size - Size (in bytes) of the memory region to be allocated. + * + * Return Value: + * The address of the allocated memory (NULL on failure to allocate) + * + ************************************************************************/ + +FAR void *kmm_zalloc(size_t size) +{ + return mm_zalloc(&g_kmmheap, size); +} + +#endif /* CONFIG_MM_KERNEL_HEAP */ diff --git a/nuttx/mm/kmm_heapmember.c b/nuttx/mm/kmm_heapmember.c deleted file mode 100644 index a91a6a667..000000000 --- a/nuttx/mm/kmm_heapmember.c +++ /dev/null @@ -1,124 +0,0 @@ -/************************************************************************ - * mm/kmm_heapmember.c - * - * Copyright (C) 2013-2014 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include - -#include - -#if defined(CONFIG_MM_KERNEL_HEAP) && defined(CONFIG_DEBUG) - -/************************************************************************ - * Pre-processor definition - ************************************************************************/ - -/************************************************************************ - * Private Types - ************************************************************************/ - -/************************************************************************ - * Public Data - ************************************************************************/ - -/************************************************************************ - * Private Functions - ************************************************************************/ - -/************************************************************************ - * Public Functions - ************************************************************************/ - -/************************************************************************ - * Name: kmm_heapmember - * - * Description: - * Check if an address lies in the kernel heap. - * - * Parameters: - * mem - The address to check - * - * Return Value: - * true if the address is a member of the kernel heap. false if not - * not. If the address is not a member of the kernel heap, then it - * must be a member of the user-space heap (unchecked) - * - ************************************************************************/ - -bool kmm_heapmember(FAR void *mem) -{ -#if CONFIG_MM_REGIONS > 1 - int i; - - /* A valid address from the kernel heap for this region would have to lie - * between the region's two guard nodes. - */ - - for (i = 0; i < g_kmmheap.mm_nregions; i++) - { - if (mem > (FAR void *)g_kmmheap.mm_heapstart[i] && - mem < (FAR void *)g_kmmheap.mm_heapend[i]) - { - return true; - } - } - - /* The address does not like any any region assigned to kernel heap */ - - return false; - -#else - /* A valid address from the kernel heap would have to lie between the - * two guard nodes. - */ - - if (mem > (FAR void *)g_kmmheap.mm_heapstart[0] && - mem < (FAR void *)g_kmmheap.mm_heapend[0]) - { - return true; - } - - /* Otherwise, the address does not lie in the kernel heap */ - - return false; - -#endif -} - -#endif /* CONFIG_MM_KERNEL_HEAP && CONFIG_DEBUG */ diff --git a/nuttx/mm/kmm_initialize.c b/nuttx/mm/kmm_initialize.c deleted file mode 100644 index 591c76715..000000000 --- a/nuttx/mm/kmm_initialize.c +++ /dev/null @@ -1,91 +0,0 @@ -/************************************************************************ - * mm/kmm_initialize.c - * - * Copyright (C) 2013-2014 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include - -#ifdef CONFIG_MM_KERNEL_HEAP - -/************************************************************************ - * Pre-processor definition - ************************************************************************/ - -/************************************************************************ - * Private Types - ************************************************************************/ - -/************************************************************************ - * Public Data - ************************************************************************/ - -/* This is the kernel heap */ - -struct mm_heap_s g_kmmheap; - -/************************************************************************ - * Private Functions - ************************************************************************/ - -/************************************************************************ - * Public Functions - ************************************************************************/ - -/************************************************************************ - * Name: kmm_initialize - * - * Description: - * Initialize the kernel heap data structures, providing the initial - * heap region. - * - * 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 - * - ************************************************************************/ - -void kmm_initialize(FAR void *heap_start, size_t heap_size) -{ - return mm_initialize(&g_kmmheap, heap_start, heap_size); -} - -#endif /* CONFIG_MM_KERNEL_HEAP */ diff --git a/nuttx/mm/kmm_kernel.c b/nuttx/mm/kmm_kernel.c deleted file mode 100644 index 646cafa6c..000000000 --- a/nuttx/mm/kmm_kernel.c +++ /dev/null @@ -1,127 +0,0 @@ -/************************************************************************ - * mm/kmm_kernel.c - * - * Copyright (C) 2013-2014 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include - -#include - -#if ((defined(CONFIG_BUILD_PROTECTED) && defined(__KERNEL__)) || \ - defined(CONFIG_BUILD_KERNEL)) && defined(CONFIG_MM_KERNEL_HEAP) - -/************************************************************************ - * Pre-processor definition - ************************************************************************/ - -/************************************************************************ - * Private Types - ************************************************************************/ - -/************************************************************************ - * Public Data - ************************************************************************/ - -/************************************************************************ - * Private Functions - ************************************************************************/ - -/************************************************************************ - * Public Functions - ************************************************************************/ - -/************************************************************************ - * Name: kmm_heapmember - * - * Description: - * Check if an address lies in the kernel heap. - * - * Parameters: - * mem - The address to check - * - * Return Value: - * true if the address is a member of the kernel heap. false if not - * not. If the address is not a member of the kernel heap, then it - * must be a member of the user-space heap (unchecked) - * - ************************************************************************/ - -#ifdef CONFIG_DEBUG -bool kmm_heapmember(FAR void *mem) -{ -#if CONFIG_MM_REGIONS > 1 - int i; - - /* A valid address from the kernel heap for this region would have to lie - * between the region's two guard nodes. - */ - - for (i = 0; i < g_kmmheap.mm_nregions; i++) - { - if (mem > (FAR void *)g_kmmheap.mm_heapstart[i] && - mem < (FAR void *)g_kmmheap.mm_heapend[i]) - { - return true; - } - } - - /* The address does not like any any region assigned to kernel heap */ - - return false; - -#else - /* A valid address from the kernel heap would have to lie between the - * two guard nodes. - */ - - if (mem > (FAR void *)g_kmmheap.mm_heapstart[0] && - mem < (FAR void *)g_kmmheap.mm_heapend[0]) - { - return true; - } - - /* Otherwise, the address does not lie in the kernel heap */ - - return false; - -#endif -} -#endif - -#endif /* ((CONFIG_BUILD_PROTECTED && __KERNEL__) || CONFIG_BUILD_KERNEL) && CONFIG_MM_KERNEL_HEAP*/ diff --git a/nuttx/mm/kmm_mallinfo.c b/nuttx/mm/kmm_mallinfo.c deleted file mode 100644 index d7c3ab475..000000000 --- a/nuttx/mm/kmm_mallinfo.c +++ /dev/null @@ -1,90 +0,0 @@ -/**************************************************************************** - * mm/kmm_mallinfo.c - * - * Copyright (C) 2014 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include - -#include - -#ifdef CONFIG_MM_KERNEL_HEAP - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: kmm_mallinfo - * - * Description: - * kmm_mallinfo returns a copy of updated current heap information for the - * kernel heap - * - ****************************************************************************/ - -#ifdef CONFIG_CAN_PASS_STRUCTS - -struct mallinfo kmm_mallinfo(void) -{ - struct mallinfo info; - mm_mallinfo(&g_kmmheap, &info); - return info; -} - -#else - -int kmm_mallinfo(struct mallinfo *info) -{ - return mm_mallinfo(&g_kmmheap, info); -} - -#endif /* CONFIG_CAN_PASS_STRUCTS */ -#endif /* CONFIG_MM_KERNEL_HEAP */ diff --git a/nuttx/mm/kmm_malloc.c b/nuttx/mm/kmm_malloc.c deleted file mode 100644 index 65d1a5f4e..000000000 --- a/nuttx/mm/kmm_malloc.c +++ /dev/null @@ -1,89 +0,0 @@ -/**************************************************************************** - * mm/kmm_malloc.c - * - * Copyright (C) 2014 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include - -#ifdef CONFIG_MM_KERNEL_HEAP - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Type Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/************************************************************************ - * Name: kmm_malloc - * - * Description: - * Allocate memory from the kernel heap. - * - * Parameters: - * size - Size (in bytes) of the memory region to be allocated. - * - * Return Value: - * The address of the allocated memory (NULL on failure to allocate) - * - ************************************************************************/ - -FAR void *kmm_malloc(size_t size) -{ - return mm_malloc(&g_kmmheap, size); -} - -#endif /* CONFIG_MM_KERNEL_HEAP */ diff --git a/nuttx/mm/kmm_memalign.c b/nuttx/mm/kmm_memalign.c deleted file mode 100644 index 783ea9ff4..000000000 --- a/nuttx/mm/kmm_memalign.c +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** - * mm/kmm_memalign.c - * - * Copyright (C) 2014 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include - -#include - -#ifdef CONFIG_MM_KERNEL_HEAP - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/************************************************************************ - * Name: kmm_memalign - * - * Description: - * Allocate aligned memory in the kernel heap. - * - * Parameters: - * alignment - Log2 byte alignment - * size - Size (in bytes) of the new memory region to be allocated. - * - * Return Value: - * The address of the re-allocated memory (NULL on failure to allocate) - * - ************************************************************************/ - -FAR void *kmm_memalign(size_t alignment, size_t size) -{ - return mm_memalign(&g_kmmheap, alignment, size); -} - -#endif /* CONFIG_MM_KERNEL_HEAP */ diff --git a/nuttx/mm/kmm_realloc.c b/nuttx/mm/kmm_realloc.c deleted file mode 100644 index fdb77da3f..000000000 --- a/nuttx/mm/kmm_realloc.c +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** - * mm/kmm_realloc.c - * - * Copyright (C) 2014 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include - -#ifdef CONFIG_MM_KERNEL_HEAP - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: kmm_realloc - * - * Description: - * Re-allocate memory in the kernel heap. - * - * Parameters: - * oldmem - The old memory allocated - * newsize - Size (in bytes) of the new memory region to be re-allocated. - * - * Return Value: - * The address of the re-allocated memory (NULL on failure to re-allocate) - * - ****************************************************************************/ - -FAR void *kmm_realloc(FAR void *oldmem, size_t newsize) -{ - return mm_realloc(&g_kmmheap, oldmem, newsize); -} - -#endif /* CONFIG_MM_KERNEL_HEAP */ diff --git a/nuttx/mm/kmm_sbrk.c b/nuttx/mm/kmm_sbrk.c deleted file mode 100755 index 90c9b6627..000000000 --- a/nuttx/mm/kmm_sbrk.c +++ /dev/null @@ -1,91 +0,0 @@ -/**************************************************************************** - * mm/kmm_sbrk.c - * - * Copyright (C) 2014 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include - -#if defined(CONFIG_BUILD_KERNEL) && defined(__KERNEL__) - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: kmm_sbrk - * - * Description: - * The sbrk() function is used to change the amount of space allocated - * for the calling process. The change is made by resetting the process' - * break value and allocating the appropriate amount of space. The amount - * of allocated space increases as the break value increases. - * - * The sbrk() function adds 'incr' bytes to the break value and changes - * the allocated space accordingly. If incr is negative, the amount of - * allocated space is decreased by incr bytes. The current value of the - * program break is returned by sbrk(0). - * - * Input Parameters: - * incr - Specifies the number of bytes to add or to remove from the - * space allocated for the process. - * - * Returned Value: - * Upon successful completion, sbrk() returns the prior break value. - * Otherwise, it returns (void *)-1 and sets errno to indicate the - * error: - * - * ENOMEM - The requested change would allocate more space than - * allowed under system limits. - * EAGAIN - The total amount of system memory available for allocation - * to this process is temporarily insufficient. This may occur even - * though the space requested was less than the maximum data segment - * size. - * - ****************************************************************************/ - -FAR void *kmm_sbrk(intptr_t incr) -{ - return mm_sbrk(&g_kmmheap, incr, UINTPTR_MAX); -} - -#endif /* CONFIG_BUILD_KERNEL && __KERNEL__ */ diff --git a/nuttx/mm/kmm_sem.c b/nuttx/mm/kmm_sem.c deleted file mode 100644 index 7883a6e56..000000000 --- a/nuttx/mm/kmm_sem.c +++ /dev/null @@ -1,104 +0,0 @@ -/************************************************************************ - * mm/kmm_sem.c - * - * Copyright (C) 2014 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include - -#ifdef CONFIG_MM_KERNEL_HEAP - -/************************************************************************ - * Pre-processor definition - ************************************************************************/ - -/************************************************************************ - * Private Types - ************************************************************************/ - -/************************************************************************ - * Public Data - ************************************************************************/ - -/************************************************************************ - * Private Functions - ************************************************************************/ - -/************************************************************************ - * Public Functions - ************************************************************************/ - -/************************************************************************ - * Name: kmm_trysemaphore - * - * Description: - * Try to take the kernel heap semaphore. - * - * Parameters: - * None - * - * Return Value: - * OK on success; a negated errno on failure - * - ************************************************************************/ - -int kmm_trysemaphore(void) -{ - return mm_trysemaphore(&g_kmmheap); -} - -/************************************************************************ - * Name: kmm_givesemaphore - * - * Description: - * Give the kernel heap semaphore. - * - * Parameters: - * None - * - * Return Value: - * OK on success; a negated errno on failure - * - ************************************************************************/ - -void kmm_givesemaphore(void) -{ - return mm_givesemaphore(&g_kmmheap); -} - -#endif /* CONFIG_MM_KERNEL_HEAP */ diff --git a/nuttx/mm/kmm_zalloc.c b/nuttx/mm/kmm_zalloc.c deleted file mode 100644 index 9cbc5081a..000000000 --- a/nuttx/mm/kmm_zalloc.c +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** - * mm/kmm_zalloc.c - * - * Copyright (C) 2014 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include - -#ifdef CONFIG_MM_KERNEL_HEAP - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/************************************************************************ - * Name: kmm_zalloc - * - * Description: - * Allocate and zero memory from the kernel heap. - * - * Parameters: - * size - Size (in bytes) of the memory region to be allocated. - * - * Return Value: - * The address of the allocated memory (NULL on failure to allocate) - * - ************************************************************************/ - -FAR void *kmm_zalloc(size_t size) -{ - return mm_zalloc(&g_kmmheap, size); -} - -#endif /* CONFIG_MM_KERNEL_HEAP */ -- cgit v1.2.3