Skip to main content

CapabilityVtable

Struct CapabilityVtable 

Source
pub struct CapabilityVtable { /* private fields */ }
Expand description

The LLVM backend’s capability grant surface.

On the cranelift side the equivalent CapabilityVtable is a heap array of extern "C" host-fn pointers whose non-null-ness at slots[cap_bit] is what lets an Op::CheckCap { cap_bit } pass. On the LLVM side the granted set is carried as an i64 bitmask the buffer-protocol entry receives as its trailing caps param, so this type is a thin builder around that mask plus the dynamic host-fn registry the import_idx-keyed Op::CallNative dispatch resolves against.

§Two halves (same split as cranelift)

  • caps_mask — the granted-capability bitmask. A set bit at index cap_bit is what lets an Op::CheckCap { cap_bit } pass (the LLVM analogue of cranelift’s “non-null slot at cap_bit”). Built via Self::grant / Self::register_via_gate; consumed by the host as the caps word it hands to the linked entry (or to LlvmAotEvaluator::with_caps).
  • host_fns — the import_idx-keyed dynamic callable registry (HostFnRegistry). A source-lowered Op::CallNative { cap_bit: NO_CAPABILITY_BIT } resolves through it via relon_llvm_call_native. Keyed off import_idx (a private namespace) so it never collides with the cap_bit-indexed mask — exactly cranelift’s host_fns split.

Implementations§

Source§

impl CapabilityVtable

Source

pub fn with_capacity(_n: usize) -> Self

Build an empty vtable: no capabilities granted, no host fns registered. The n argument is accepted for source-shape parity with cranelift’s with_capacity(n); the LLVM mask is fixed at 64 bits so the value is only used to assert the caller does not ask for more bits than the i64 mask can hold.

Source

pub fn grant(&mut self, cap_bit: u32)

Grant a capability bit by setting it in the caps mask. An Op::CheckCap { cap_bit } only tests the bit, so a set bit is enough to let the guard pass; the actual call dispatches through the import_idx-keyed host_fns registry. Mirrors cranelift’s CapabilityVtable::grant (which parks a non-null sentinel).

Bits >= 64 are silently ignored (the i64 mask cannot carry them); the matching Op::CheckCap lowering rejects an out-of- range bit at compile time, so a too-large grant can never satisfy a gate either way.

Source

pub fn register_via_gate<G: CapabilityGate>( &mut self, gate: &G, cap_bit: CapabilityBit, ) -> bool

Capability-gated grant. Consults gate for cap_bit via the shared relon_eval_api::CapabilityGate trait; if the gate denies the bit, the mask bit stays clear so the IR-level Op::CheckCap traps with SandboxTrapKind::CapabilityDenied. This is the LLVM backend’s half of the unified-enforcement design: the same policy the tree-walker consults at dispatch time and the cranelift backend consults at vtable-build time is consulted here when folding the bit into the caps mask, so denying a bit on the host side produces the same outcome class (RuntimeError::CapabilityDenied) on all three backends.

Returns true if the bit was granted; false if the gate denied it (mask bit left clear).

Source

pub fn is_granted(&self, cap_bit: u32) -> bool

true when cap_bit is granted in the mask. The LLVM analogue of cranelift’s lookup(cap_bit).is_some().

Source

pub fn caps_mask(&self) -> i64

The granted-capability bitmask, ready to hand to the linked entry as its trailing caps param (or to LlvmAotEvaluator::with_caps). This is the runtime carrier the Op::CheckCap gate baked into the emitted object reads.

Source

pub fn register_host_fn( &mut self, import_idx: u32, func: Arc<dyn RelonFunction>, )

Register a dynamic Arc<dyn RelonFunction> host fn at the given import_idx. Mirrors cranelift’s CapabilityVtable::register_host_fn; delegates to the existing HostFnRegistry so the JIT-side relon_llvm_call_native dispatch resolves against the same map.

Source

pub fn resolve_host_fn( &self, import_idx: u32, ) -> Option<&Arc<dyn RelonFunction>>

Resolve the dynamic host fn registered at import_idx. Mirrors cranelift’s CapabilityVtable::resolve_host_fn.

Source

pub fn host_fns(&self) -> &HostFnRegistry

Borrow the underlying HostFnRegistry so the evaluator can install it on a per-call [crate::state::ArenaState] via ArenaState::install_host_fns.

Source

pub fn host_fn_count(&self) -> usize

Number of registered dynamic host fns.

Trait Implementations§

Source§

impl Clone for CapabilityVtable

Source§

fn clone(&self) -> CapabilityVtable

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 CapabilityVtable

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for CapabilityVtable

Source§

fn default() -> CapabilityVtable

Returns the “default value” for a type. 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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.