|
4 | 4 |
|
5 | 5 | #include <cstddef> |
6 | 6 |
|
| 7 | +#include "runtime-common/core/allocator/script-malloc-interface.h" |
| 8 | +#include "runtime-light/allocator/allocator-state.h" |
7 | 9 | #include "runtime-light/utils/logs.h" |
8 | 10 |
|
9 | | -extern "C" void* __wrap_malloc([[maybe_unused]] size_t size) noexcept { |
10 | | - kphp::log::error("unexpected use of malloc"); |
| 11 | +extern "C" void* __wrap_malloc(size_t size) noexcept { |
| 12 | + if (!AllocatorState::get().libc_alloc_allowed()) [[unlikely]] { |
| 13 | + kphp::log::error("unexpected use of malloc"); |
| 14 | + } |
| 15 | + return kphp::memory::script::alloc(size); |
11 | 16 | } |
12 | 17 |
|
13 | | -extern "C" void __wrap_free([[maybe_unused]] void* ptr) noexcept { |
14 | | - kphp::log::error("unexpected use of free"); |
| 18 | +extern "C" void __wrap_free(void* ptr) noexcept { |
| 19 | + if (!AllocatorState::get().libc_alloc_allowed()) [[unlikely]] { |
| 20 | + kphp::log::error("unexpected use of free"); |
| 21 | + } |
| 22 | + kphp::memory::script::free(ptr); |
15 | 23 | } |
16 | 24 |
|
17 | | -extern "C" void* __wrap_calloc([[maybe_unused]] size_t nmemb, [[maybe_unused]] size_t size) noexcept { |
18 | | - kphp::log::error("unexpected use of calloc"); |
| 25 | +extern "C" void* __wrap_calloc(size_t nmemb, size_t size) noexcept { |
| 26 | + if (!AllocatorState::get().libc_alloc_allowed()) [[unlikely]] { |
| 27 | + kphp::log::error("unexpected use of calloc"); |
| 28 | + } |
| 29 | + return kphp::memory::script::calloc(nmemb, size); |
19 | 30 | } |
20 | 31 |
|
21 | 32 | extern "C" void* __wrap_realloc([[maybe_unused]] void* ptr, [[maybe_unused]] size_t size) noexcept { |
22 | | - kphp::log::error("unexpected use of realloc"); |
| 33 | + if (!AllocatorState::get().libc_alloc_allowed()) [[unlikely]] { |
| 34 | + kphp::log::error("unexpected use of realloc"); |
| 35 | + } |
| 36 | + return kphp::memory::script::realloc(ptr, size); |
23 | 37 | } |
0 commit comments