7 releases
0.3.2 | Feb 14, 2023 |
---|---|
0.3.1 | Feb 16, 2022 |
0.2.0 | Aug 23, 2021 |
0.1.2 | Feb 10, 2021 |
#461 in Embedded development
23 downloads per month
62KB
761 lines
umm-malloc-rs
Provides a global allocator using the umm_malloc library.
umm_malloc
is a small and simple memory allocator designed for embedded systems.
It is able to allocate and free quickly with limited memory fragmentation.
Limitations
All allocations from this allocator are aligned by 8 bytes. Requesting a larger alignment is not implemented and will panic.
Features
-
first-fit
Use the first available block for allocation, rather than search for a better fit. -
init-if-uninitialized
Adds checks to every malloc function which tries to initialize the heap (using the extern symbols for heap location) if it is not initialized. -
hang-if-uninitialized
Adds checks to every malloc function which enters an infinite loop if the heap is not initialized. -
enable-pie
Compiles the umm_malloc C code position independent (-fPIE
). You'll likely want to enable it for rustc also e.g.-C relocation-model=pie
.
Global Allocator Critical Sections
Concurrent access to the global allocator is Undefined Behavior. Enable one of the following cargo features to configure how access to the global allocator is controlled.
cortex-m-interrupt-critical-section
: interrupt-disabled critical section for ARM Cortex-M processors.extern-critical-section
: Uses the extern functionsvoid _umm_critical_entry(uint32_t*)
andvoid _umm_critical_exit(uint32_t*)
to implement the global allocator critical sections. You MUST supply those functions via some other means. Note that critical sections may nest.unsafe-no-critical-section
: no critical sections around the global allocator. You MUST prevent concurrent use of the global allcator to avoid Undefined Behavior.
Future Work
umm_malloc
has features for collecting metrics and detecting heap corruption,
which could be exposed conveniently with cargo features.
An implementation of memalign could be added to umm_malloc
.
Dependencies
~0–280KB