-
Notifications
You must be signed in to change notification settings - Fork 164
Open
Description
background
as described in #126, svm runtime gives the user heap to use anyways with or without defining a heap allocator.
default BumpAllocator will store two usize on bss section, one indicating the free pointer and the other max len.
default BumpAllocator stores heap free pointer at 0x300000000.
NoAllocator now does not allow alloc generated heap allocation, and #126 adds a manual allocation for NoAllocator.
a few thoughts
NoAllocator's name is confusing. it is able to let user to claim heap memory, but it cannot letalloccrate to get memory.NoAllocatoris very dev-unfriendly (maybe we can introduce some static check to avoid overlap?)- using allocating functions in crate
alloclikeBox::newwill introduces some rust runtime check, like null ptr check. subsequently it emits panic stuff like in useget_uncheckedover [] to preventfmtcode emission #85 . allocate_uncheckedneeds the annoying#![cfg_attr(target_os = "solana", feature(const_mut_refs))]
some easy todo improvements:
- remove
lenfield ofBumpAllocator - remove
constforallocate_unchecked(or we wait for toolchain updating to 1.83.0) - add same interface (
allocate_unchecked) forBumpAllocator -
allocate_uncheckedshould return&'static mut MaybeUninit<T> - introduce static_assertions for
allocate_uncheckedto through compile-time error for assertion (e.g. heap oob)
some challenging ones:
- compile time overlap check (not sure if it's possible without touching the compiler)
- bypass
allocruntime check (i.e. lightweight panic if allocation fails). i tried but failed. compiler change needed for this one
Metadata
Metadata
Assignees
Labels
No labels