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 indexcap_bitis what lets anOp::CheckCap { cap_bit }pass (the LLVM analogue of cranelift’s “non-null slot atcap_bit”). Built viaSelf::grant/Self::register_via_gate; consumed by the host as thecapsword it hands to the linked entry (or toLlvmAotEvaluator::with_caps).host_fns— theimport_idx-keyed dynamic callable registry (HostFnRegistry). A source-loweredOp::CallNative { cap_bit: NO_CAPABILITY_BIT }resolves through it viarelon_llvm_call_native. Keyed offimport_idx(a private namespace) so it never collides with thecap_bit-indexed mask — exactly cranelift’shost_fnssplit.
Implementations§
Source§impl CapabilityVtable
impl CapabilityVtable
Sourcepub fn with_capacity(_n: usize) -> Self
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.
Sourcepub fn grant(&mut self, cap_bit: u32)
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.
Sourcepub fn register_via_gate<G: CapabilityGate>(
&mut self,
gate: &G,
cap_bit: CapabilityBit,
) -> bool
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).
Sourcepub fn is_granted(&self, cap_bit: u32) -> bool
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().
Sourcepub fn caps_mask(&self) -> i64
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.
Sourcepub fn register_host_fn(
&mut self,
import_idx: u32,
func: Arc<dyn RelonFunction>,
)
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.
Sourcepub fn resolve_host_fn(
&self,
import_idx: u32,
) -> Option<&Arc<dyn RelonFunction>>
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.
Sourcepub fn host_fns(&self) -> &HostFnRegistry
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.
Sourcepub fn host_fn_count(&self) -> usize
pub fn host_fn_count(&self) -> usize
Number of registered dynamic host fns.
Trait Implementations§
Source§impl Clone for CapabilityVtable
impl Clone for CapabilityVtable
Source§fn clone(&self) -> CapabilityVtable
fn clone(&self) -> CapabilityVtable
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CapabilityVtable
impl Debug for CapabilityVtable
Source§impl Default for CapabilityVtable
impl Default for CapabilityVtable
Source§fn default() -> CapabilityVtable
fn default() -> CapabilityVtable
Auto Trait Implementations§
impl !RefUnwindSafe for CapabilityVtable
impl !UnwindSafe for CapabilityVtable
impl Freeze for CapabilityVtable
impl Send for CapabilityVtable
impl Sync for CapabilityVtable
impl Unpin for CapabilityVtable
impl UnsafeUnpin for CapabilityVtable
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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