Skip to main content

MemoryBinding

Struct MemoryBinding 

Source
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

Source

pub const fn identity(&self) -> BindingIdentity

Source

pub fn allocate( &self, bytes: usize, align: usize, ) -> Result<BoundAllocation, BindingError>

Source

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.

Source

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:

  • ptr is one live allocation of exactly bytes at align produced by this binding’s selected mechanism (the same coherent allocator that would serve allocate), 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::release with exactly this ptr/bytes/align.
Source

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.

Source

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.

Source

pub fn quarantined(&self) -> Result<Vec<QuarantinedAllocation>, BindingError>

Ownership this binding’s mechanism retained instead of releasing.

Source

pub fn mechanism_snapshot(&self) -> Result<MechanismSnapshot, BindingError>

Lifecycle and ownership counts for this binding’s mechanism.

Source

pub fn virtual_backing( &self, ) -> Result<Option<BoundVirtualBacking>, BindingError>

Source

pub fn shared_mapping(&self) -> Result<Option<BoundSharedMapping>, BindingError>

Source

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

Source§

fn clone(&self) -> MemoryBinding

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MemoryBinding

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> BindingResource for T
where T: Send + Sync + Debug,

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.