๐ง Memory โ
The Memory module defines allocation contracts and the runtime bridge to the active allocator implementation.
Role in system โ
- Provides the system allocation API (
allocate,deallocate,reallocate) with explicitLayoutsemantics. - Exposes capability-aware allocation requests (
Executable,DirectMemoryAccess). - Serves as the source for Rust global allocator integration through
GlobalAllocwrapper.
Responsibilities and boundaries โ
In scope
ManagerTraitcontract for allocation/backing allocator implementations.Managerwrapper adapting trait object to safe/unsafe call sites andGlobalAlloc.- Cache and page-size helper surface.
Out of scope
- Choosing one universal allocator strategy for all targets.
- Owning platform-specific heap region setup (performed by platform crates/linking symbols).
Internal architecture โ
- Core abstraction:
ManagerTrait(unsafe allocation primitives + usage stats + cache hooks). - Runtime wrapper:
memory::Manager<'a>(&'a dyn ManagerTrait). - Global accessor:
memory::get_instance()returns__XILA_MEMORY_MANAGERsymbol provided by final runtime. - Capability flags are bitflags (
Executable,DirectMemoryAccess) used as hints/requirements for backend allocators.
Contract vs implementation
- Contract:
ManagerTraitmethods and expected safety invariants. - Implementation: backend-specific allocation algorithms, region policies, and capability interpretation.
Lifecycle and execution model โ
- Platform/runtime defines concrete manager and exports
__XILA_MEMORY_MANAGER. - Consumers call memory APIs directly or through Rust allocation path.
- Optional cache/page helpers are invoked for architecture-specific coherency needs.
- ABI entrypoints may wrap operations with additional metadata and synchronization.
Data/control flow โ
- Direct path: caller ->
Manager-> trait object allocator backend. - Rust alloc path: allocator trait implementation -> same
Managerwrapper -> backend. - ABI path: C ABI wrappers -> memory manager + allocation metadata helpers.
Concurrency and synchronization model โ
- Thread-safety guarantee is part of
ManagerTrait: Send + Synccontract. - Synchronization strategy is backend-defined.
- ABI allocation wrappers currently serialize operations with a global mutex in their implementation layer.
Dependency model โ
- Core depends on trait-based allocator implementation supplied externally.
- Used by virtually all modules via Rust allocation flow; additionally consumed explicitly in VM/ABI flows.
Failure semantics and recovery behavior โ
- Allocation/reallocation returns null on failure at C-facing boundary and
Noneat trait level. - Deallocating null pointers is treated as no-op in wrapper behavior.
- Reallocate default implementation allocates-copy-deallocates, so failure can occur before ownership transfer.
Extension points โ
- Provide new
ManagerTraitimplementations (region allocators, platform allocators, debug allocators). - Extend capability semantics with additional flags when required by targets.
- Override cache/page methods for architecture-specific behavior.
Known limitations and trade-offs โ
- Fragmentation and allocation behavior are backend-specific.
- Cache and capability guarantees are only as strong as backend implementation support.
- Cross-platform consistency requires disciplined backend conformance to trait contracts.