Showing the changes to src/vm/vm_memory.cpp (1 of 6 files). Show all
Unified · Split
| @@ -20,9 +20,13 @@ · 19 unmodified lines | |||
| 20 | using namespace disvm; | 20 | using namespace disvm; |
| 21 | using namespace disvm::runtime; | 21 | using namespace disvm::runtime; |
| 22 | 22 | ||
| 23 | // Defined in vm.cpp | ||
| 24 | extern thread_local vm_memory_alloc_t vm_memory_alloc; | ||
| 25 | extern thread_local vm_memory_free_t vm_memory_free; | ||
| 26 | |||
| 23 | void *disvm::runtime::alloc_memory(std::size_t amount_in_bytes) | 27 | void *disvm::runtime::alloc_memory(std::size_t amount_in_bytes) |
| 24 | { | 28 | { |
| 25 | auto memory = std::calloc(amount_in_bytes, sizeof(byte_t)); | 29 | auto memory = vm_memory_alloc(amount_in_bytes, sizeof(byte_t)); |
| 26 | if (memory == nullptr) | 30 | if (memory == nullptr) |
| 27 | throw vm_system_exception{ "Out of memory" }; | 31 | throw vm_system_exception{ "Out of memory" }; |
| 28 | 32 | ||
| @@ -34,13 +38,10 @@ void *disvm::runtime::alloc_memory(std::size_t amount_in_bytes) · 5 unmodified lines | |||
| 34 | 38 | ||
| 35 | void disvm::runtime::free_memory(void *memory) | 39 | void disvm::runtime::free_memory(void *memory) |
| 36 | { | 40 | { |
| 37 | if (memory == nullptr) | 41 | vm_memory_free(memory); |
| 38 | return; | ||
| 39 | 42 | ||
| 40 | if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>()) | 43 | if (memory != nullptr && debug::is_component_tracing_enabled<debug::component_trace_t::memory>()) |
| 41 | debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "free: %#" PRIxPTR, memory); | 44 | debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "free: %#" PRIxPTR, memory); |
| 42 | |||
| 43 | std::free(memory); | ||
| 44 | } | 45 | } |
| 45 | 46 | ||
| 46 | void disvm::runtime::init_memory(const type_descriptor_t &type_desc, void *data) | 47 | void disvm::runtime::init_memory(const type_descriptor_t &type_desc, void *data) |