pub struct MemoryBinding { /* private fields */ }Expand description
One binding to a registered device/mechanism/context/authority tuple.
Clones preserve the same binding identity and pin. A new registry lookup receives a new binding id/generation even when it selects the same mechanism.
Implementations§
Source§impl MemoryBinding
impl MemoryBinding
pub const fn identity(&self) -> BindingIdentity
pub fn allocate( &self, bytes: usize, align: usize, ) -> Result<BoundAllocation, BindingError>
Sourcepub fn allocate_owning(
&self,
bytes: usize,
align: usize,
) -> Result<OwningAllocation, BindingError>
pub fn allocate_owning( &self, bytes: usize, align: usize, ) -> Result<OwningAllocation, BindingError>
Allocate and take owning responsibility for the result.
The returned OwningAllocation has exactly one consuming release and a
Drop that quarantines rather than frees, so a forgotten allocation is
accounted for instead of silently double-freed or leaked without trace.
Sourcepub unsafe fn adopt_allocation(
&self,
ptr: NonNull<u8>,
bytes: usize,
align: usize,
) -> Result<OwningAllocation, BindingError>
pub unsafe fn adopt_allocation( &self, ptr: NonNull<u8>, bytes: usize, align: usize, ) -> Result<OwningAllocation, BindingError>
Issue an allocation generation for memory this binding’s own mechanism produced through a specialized entry point this crate cannot express, and take owning responsibility for it.
This is the narrow adoption seam for a provider-specific allocation call
(the CUDA VMM arena’s mapped-capacity allocation is the motivating case:
it needs a governor capacity token that is deliberately not part of the
portable VirtualBacking capability). Adoption
registers the address under a fresh generation before it escapes, so
every later view, commit, and release is generation-validated exactly
like a binding-issued allocation. Nothing else about the lifecycle is
relaxed.
§Safety
The caller must guarantee all of:
ptris one live allocation of exactlybytesatalignproduced by this binding’s selected mechanism (the same coherent allocator that would serveallocate), not by another allocator or another device.- The allocation is not already recorded by this or any other binding, and no other owner exists for it. Adoption is the single point at which ownership enters the binding, and the returned owner is its sole owner.
- The allocation may be released by that mechanism’s canonical
DeviceAllocator::releasewith exactly thisptr/bytes/align.
Sourcepub fn prepare_release(
&self,
allocation: BoundAllocation,
) -> Result<PreparedAllocationRelease, ExplicitReleaseError>
pub fn prepare_release( &self, allocation: BoundAllocation, ) -> Result<PreparedAllocationRelease, ExplicitReleaseError>
Detach final ownership of allocation without calling the allocator.
This is the single preparation point for every release path. It matches the binding identity and the allocation generation and removes the live record exactly once under the per-mechanism lock, then returns an owned request that pins the allocator, authority, and provider context.
§Lock order
Only the mechanism lock is taken, and it is released before this method returns. Queue and allocator calls therefore always happen with no registry or mechanism lock held.
Sourcepub fn release(
&self,
allocation: BoundAllocation,
) -> Result<(), ExplicitReleaseError>
pub fn release( &self, allocation: BoundAllocation, ) -> Result<(), ExplicitReleaseError>
Explicitly release through this binding’s pinned original allocator.
This is the documented migration adapter for Phase-3 non-RAII
BoundAllocation metadata. It is routed through the same structured
prepared-release path as owning handles, so the generation is validated
and the live record is retired before the allocator is invoked. It
completes synchronously and never enqueues.
On pre-mutation failure (identity mismatch, stale generation, device
loss) the allocation is returned inside ExplicitReleaseError exactly
as before, so metadata and lifetime pins are not silently discarded.
§Limitations
The adapter cannot report the structured success outcome, because its
signature returns (). Callers that need the release accounting or that
need to defer release past a stream fence should migrate to
OwningAllocation or MemoryBinding::prepare_release.
When the allocator quarantines residual ownership the adapter reports
BindingError::ReleaseQuarantined and hands back the now-dead
metadata together with the structured outcome
(ExplicitReleaseError::outcome). That metadata can never be released
again: its record was already retired, so every later operation on it
fails with BindingError::StaleAllocation.
Sourcepub fn quarantined(&self) -> Result<Vec<QuarantinedAllocation>, BindingError>
pub fn quarantined(&self) -> Result<Vec<QuarantinedAllocation>, BindingError>
Ownership this binding’s mechanism retained instead of releasing.
Sourcepub fn mechanism_snapshot(&self) -> Result<MechanismSnapshot, BindingError>
pub fn mechanism_snapshot(&self) -> Result<MechanismSnapshot, BindingError>
Lifecycle and ownership counts for this binding’s mechanism.
pub fn virtual_backing( &self, ) -> Result<Option<BoundVirtualBacking>, BindingError>
Sourcepub fn with_view<R>(
&self,
view: &BoundMemoryView,
operation: impl FnOnce(ValidatedMemoryView) -> R,
) -> Result<R, BindingError>
pub fn with_view<R>( &self, view: &BoundMemoryView, operation: impl FnOnce(ValidatedMemoryView) -> R, ) -> Result<R, BindingError>
Validate a view, then invoke operation without a registry or mechanism
lock held. This is the binding boundary for kernel/copy callbacks.
Trait Implementations§
Source§impl Clone for MemoryBinding
impl Clone for MemoryBinding
Source§fn clone(&self) -> MemoryBinding
fn clone(&self) -> MemoryBinding
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more