1/* Copyright JS Foundation and other contributors, http://js.foundation 2 * 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16#ifndef JMEM_ALLOCATOR_INTERNAL_H 17#define JMEM_ALLOCATOR_INTERNAL_H 18 19#ifndef JMEM_ALLOCATOR_INTERNAL 20# error "The header is for internal routines of memory allocator component. Please, don't use the routines directly." 21#endif /* !JMEM_ALLOCATOR_INTERNAL */ 22 23/** \addtogroup mem Memory allocation 24 * @{ 25 */ 26 27/** 28 * @{ 29 * Valgrind-related options and headers 30 */ 31#if ENABLED (JERRY_VALGRIND) 32# include "memcheck.h" 33 34# define JMEM_VALGRIND_NOACCESS_SPACE(p, s) VALGRIND_MAKE_MEM_NOACCESS((p), (s)) 35# define JMEM_VALGRIND_UNDEFINED_SPACE(p, s) VALGRIND_MAKE_MEM_UNDEFINED((p), (s)) 36# define JMEM_VALGRIND_DEFINED_SPACE(p, s) VALGRIND_MAKE_MEM_DEFINED((p), (s)) 37# define JMEM_VALGRIND_MALLOCLIKE_SPACE(p, s) VALGRIND_MALLOCLIKE_BLOCK((p), (s), 0, 0) 38# define JMEM_VALGRIND_RESIZE_SPACE(p, o, n) VALGRIND_RESIZEINPLACE_BLOCK((p), (o), (n), 0) 39# define JMEM_VALGRIND_FREELIKE_SPACE(p) VALGRIND_FREELIKE_BLOCK((p), 0) 40#else /* !ENABLED (JERRY_VALGRIND) */ 41# define JMEM_VALGRIND_NOACCESS_SPACE(p, s) 42# define JMEM_VALGRIND_UNDEFINED_SPACE(p, s) 43# define JMEM_VALGRIND_DEFINED_SPACE(p, s) 44# define JMEM_VALGRIND_MALLOCLIKE_SPACE(p, s) 45# define JMEM_VALGRIND_RESIZE_SPACE(p, o, n) 46# define JMEM_VALGRIND_FREELIKE_SPACE(p) 47#endif /* ENABLED (JERRY_VALGRIND) */ 48/** @} */ 49 50void jmem_heap_init (void); 51void jmem_heap_finalize (void); 52bool jmem_is_heap_pointer (const void *pointer); 53void *jmem_heap_alloc_block_internal (const size_t size); 54void jmem_heap_free_block_internal (void *ptr, const size_t size); 55 56/** 57 * \addtogroup poolman Memory pool manager 58 * @{ 59 */ 60 61void jmem_pools_finalize (void); 62 63/** 64 * @} 65 * @} 66 */ 67 68/** 69 * @{ 70 * Jerry mem-stat definitions 71 */ 72#if ENABLED (JERRY_MEM_STATS) 73void jmem_heap_stat_init (void); 74void jmem_heap_stat_alloc (size_t num); 75void jmem_heap_stat_free (size_t num); 76 77#define JMEM_HEAP_STAT_INIT() jmem_heap_stat_init () 78#define JMEM_HEAP_STAT_ALLOC(v1) jmem_heap_stat_alloc (v1) 79#define JMEM_HEAP_STAT_FREE(v1) jmem_heap_stat_free (v1) 80#else /* !ENABLED (JERRY_MEM_STATS) */ 81#define JMEM_HEAP_STAT_INIT() 82#define JMEM_HEAP_STAT_ALLOC(v1) JERRY_UNUSED (v1) 83#define JMEM_HEAP_STAT_FREE(v1) JERRY_UNUSED (v1) 84#endif /* ENABLED (JERRY_MEM_STATS) */ 85 86/** @} */ 87 88#endif /* !JMEM_ALLOCATOR_INTERNAL_H */ 89