github.com/goccy/go-jit@v0.0.0-20200514131505-ff78d45cf6af/internal/ccall/jit-memory.c (about) 1 /* 2 * jit-memory.c - Memory management. 3 * 4 * Copyright (C) 2012 Aleksey Demakov 5 * 6 * The libjit library is free software: you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public License 8 * as published by the Free Software Foundation, either version 2.1 of 9 * the License, or (at your option) any later version. 10 * 11 * The libjit library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with the libjit library. If not, see 18 * <http://www.gnu.org/licenses/>. 19 */ 20 21 #include "jit-internal.h" 22 23 void 24 _jit_memory_lock(jit_context_t context) 25 { 26 jit_mutex_lock(&context->memory_lock); 27 } 28 29 void 30 _jit_memory_unlock(jit_context_t context) 31 { 32 jit_mutex_unlock(&context->memory_lock); 33 } 34 35 int 36 _jit_memory_ensure(jit_context_t context) 37 { 38 if(!context->memory_context) 39 { 40 context->memory_context = context->memory_manager->create(context); 41 } 42 return (context->memory_context != 0); 43 } 44 45 void 46 _jit_memory_destroy(jit_context_t context) 47 { 48 if(!context->memory_context) 49 { 50 return; 51 } 52 context->memory_manager->destroy(context->memory_context); 53 } 54 55 jit_function_info_t 56 _jit_memory_find_function_info(jit_context_t context, void *pc) 57 { 58 if(!context->memory_context) 59 { 60 return 0; 61 } 62 /* TODO: read lock? */ 63 return context->memory_manager->find_function_info(context->memory_context, pc); 64 } 65 66 jit_function_t 67 _jit_memory_get_function(jit_context_t context, jit_function_info_t info) 68 { 69 /* TODO: read lock? */ 70 return context->memory_manager->get_function(context->memory_context, info); 71 } 72 73 void * 74 _jit_memory_get_function_start(jit_context_t context, jit_function_info_t info) 75 { 76 /* TODO: read lock? */ 77 return context->memory_manager->get_function_start(context->memory_context, info); 78 } 79 80 void * 81 _jit_memory_get_function_end(jit_context_t context, jit_function_info_t info) 82 { 83 /* TODO: read lock? */ 84 return context->memory_manager->get_function_end(context->memory_context, info); 85 } 86 87 jit_function_t 88 _jit_memory_alloc_function(jit_context_t context) 89 { 90 return context->memory_manager->alloc_function(context->memory_context); 91 } 92 93 void 94 _jit_memory_free_function(jit_context_t context, jit_function_t func) 95 { 96 context->memory_manager->free_function(context->memory_context, func); 97 } 98 99 int 100 _jit_memory_start_function(jit_context_t context, jit_function_t func) 101 { 102 return context->memory_manager->start_function(context->memory_context, func); 103 } 104 105 int 106 _jit_memory_end_function(jit_context_t context, int result) 107 { 108 return context->memory_manager->end_function(context->memory_context, result); 109 } 110 111 int 112 _jit_memory_extend_limit(jit_context_t context, int count) 113 { 114 return context->memory_manager->extend_limit(context->memory_context, count); 115 } 116 117 void * 118 _jit_memory_get_limit(jit_context_t context) 119 { 120 return context->memory_manager->get_limit(context->memory_context); 121 } 122 123 void * 124 _jit_memory_get_break(jit_context_t context) 125 { 126 return context->memory_manager->get_break(context->memory_context); 127 } 128 129 void 130 _jit_memory_set_break(jit_context_t context, void *brk) 131 { 132 context->memory_manager->set_break(context->memory_context, brk); 133 } 134 135 void * 136 _jit_memory_alloc_trampoline(jit_context_t context) 137 { 138 return context->memory_manager->alloc_trampoline(context->memory_context); 139 } 140 141 void 142 _jit_memory_free_trampoline(jit_context_t context, void *ptr) 143 { 144 context->memory_manager->free_trampoline(context->memory_context, ptr); 145 } 146 147 void * 148 _jit_memory_alloc_closure(jit_context_t context) 149 { 150 return context->memory_manager->alloc_closure(context->memory_context); 151 } 152 153 void 154 _jit_memory_free_closure(jit_context_t context, void *ptr) 155 { 156 context->memory_manager->free_closure(context->memory_context, ptr); 157 } 158 159 void * 160 _jit_memory_alloc_data(jit_context_t context, jit_size_t size, jit_size_t align) 161 { 162 return context->memory_manager->alloc_data(context->memory_context, size, align); 163 }