1 /**************************************************************************** 2 * 3 * Copyright (C) 2015 Gregory Nutt. All rights reserved. 4 * Author: Gregory Nutt <gnutt@nuttx.org> 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in 14 * the documentation and/or other materials provided with the 15 * distribution. 16 * 3. Neither the name NuttX nor the names of its contributors may be 17 * used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 * POSSIBILITY OF SUCH DAMAGE. 32 * 33 ****************************************************************************/ 34 35 #ifndef __MM_UMM_HEAP_UMM_HEAP_H 36 #define __MM_UMM_HEAP_UMM_HEAP_H 37 38 /**************************************************************************** 39 * Included Files 40 ****************************************************************************/ 41 #include <stdint.h> 42 #include "mm.h" 43 44 #ifdef __cplusplus 45 extern "C" { 46 #endif 47 48 /**************************************************************************** 49 * Pre-processor Definitions 50 ****************************************************************************/ 51 52 #if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL) 53 /* In the kernel build, there a multiple user heaps; one for each task 54 * group. In this build configuration, the user heap structure lies 55 * in a reserved region at the beginning of the .bss/.data address 56 * space (CONFIG_ARCH_DATA_VBASE). The size of that region is given by 57 * ARCH_DATA_RESERVE_SIZE 58 */ 59 60 # include <nuttx/addrenv.h> 61 # define USR_HEAP (&ARCH_DATA_RESERVE->ar_usrheap) 62 63 #elif defined(CONFIG_BUILD_PROTECTED) && defined(__KERNEL__) 64 /* In the protected mode, there are two heaps: A kernel heap and a single 65 * user heap. Kernel code must obtain the address of the user heap data 66 * structure from the userspace interface. 67 */ 68 69 # include <nuttx/userspace.h> 70 # define USR_HEAP (USERSPACE->us_heap) 71 72 #else 73 /* Otherwise, the user heap data structures are in common .bss */ 74 75 # define USR_HEAP &g_mmheap 76 #endif 77 78 /**************************************************************************** 79 * Public Functions 80 ****************************************************************************/ 81 void mm_heap_initialize(void); 82 int32_t mm_get_mallinfo(int32_t *total, int32_t *used, int32_t *free, int32_t *peak); 83 void mm_leak_dump(void); 84 85 #ifdef __cplusplus 86 } 87 #endif 88 89 #endif /* __MM_UMM_HEAP_UMM_HEAP_H */ 90