kelk_allocator/lib.rs
1//! Kelk-allocator providing memory allocator support for smart contracts in [Pactus](https://pactus.org/) blockchain.
2//!
3#![cfg_attr(no_std, feature(core_intrinsics, lang_items, alloc_error_handler))]
4// #![cfg_attr(no_std, feature(core_intrinsics, lang_items, alloc_error_handler))]
5
6// Use `wee_alloc` as the global allocator.
7// #[cfg(no_std)]
8#[global_allocator]
9static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
10
11/// Need to provide a tiny `panic` implementation for `#![no_std]`.
12/// This translates into an `unreachable` instruction that will
13/// raise a `trap` the WebAssembly execution if we panic at runtime.
14#[cfg(no_std)]
15#[panic_handler]
16#[no_mangle]
17pub fn panic(_info: &::core::panic::PanicInfo) -> ! {
18 ::core::intrinsics::abort();
19}
20
21/// Need to provide an allocation error handler which just aborts
22/// the execution with trap.
23#[cfg(no_std)]
24#[alloc_error_handler]
25#[no_mangle]
26fn oom(_: core::alloc::Layout) -> ! {
27 ::core::intrinsics::abort();
28}
29
30/// Needed for non-wasm targets.
31#[cfg(no_std)]
32#[lang = "eh_personality"]
33#[no_mangle]
34pub extern "C" fn eh_personality() {}