multiversx_sc_wasm_adapter/wasm_alloc/
fail_allocator.rs

1use core::alloc::{GlobalAlloc, Layout};
2
3fn signal_allocation_not_allowed() -> ! {
4    crate::error_hook::signal_error(&b"memory allocation forbidden"[..])
5}
6
7/// Allocator that fails (with signal error) whenever an allocation is attempted.
8pub struct FailAllocator;
9
10unsafe impl GlobalAlloc for FailAllocator {
11    unsafe fn alloc(&self, _layout: Layout) -> *mut u8 {
12        signal_allocation_not_allowed()
13    }
14
15    unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {
16        signal_allocation_not_allowed()
17    }
18}