#![deny(unsafe_code)]
#![cfg_attr(docsrs, feature(doc_cfg))]
pub mod attest;
pub mod bytecode;
pub mod entropy;
pub mod log;
pub mod memory;
pub mod natives;
pub mod output;
pub mod prng;
pub mod samples;
pub mod scheduler;
pub mod transport;
pub mod vm;
#[cfg(feature = "jit")]
#[cfg_attr(docsrs, doc(cfg(feature = "jit")))]
pub mod jit;
pub mod docs {
#[doc = include_str!("../docs/atomic-hop.md")]
pub mod atomic_hop {}
#[doc = include_str!("../docs/beam-mapping.md")]
pub mod beam_mapping {}
#[doc = include_str!("../docs/lifecycle.md")]
pub mod lifecycle {}
#[doc = include_str!("../docs/security.md")]
pub mod security {}
#[doc = include_str!("../docs/error-model.md")]
pub mod error_model {}
#[doc = include_str!("../docs/vm-safety.md")]
pub mod vm_safety {}
#[doc = include_str!("../docs/mailbox.md")]
pub mod mailbox {}
#[doc = include_str!("../docs/properties.md")]
pub mod properties {}
#[doc = include_str!("../docs/host-await.md")]
pub mod host_await {}
#[doc = include_str!("../docs/remote-transport.md")]
pub mod remote_transport {}
#[doc = include_str!("../docs/production-embedding.md")]
pub mod production_embedding {}
#[doc = include_str!("../docs/audit-checklist.md")]
pub mod audit_checklist {}
#[doc = include_str!("../docs/untrusted.md")]
pub mod untrusted {}
}
pub use attest::{decode_attested, fingerprint_bf, AttestError};
pub use bytecode::{
assemble, decode, decode_with, disassemble, encode, verify, verify_with, AssembleError, Cap,
CapId, CapIdError, CapRights, CapTarget, Chunk, ConstantKind, Fn, FormatError, FuncId,
FunctionDef, Instruction, IntCmp, Label, MapKey, Message, NativeIdx, NativeMask, Opcode,
Program, Reg, RegWindow, RestartPolicy, RevocationCell, TrustLevel, Value, VerifyConfig,
VerifyError, ABI_VERSION, ABI_VERSION_LISTS, ABI_VERSION_MAPS, ABI_VERSION_RECORDS, MAGIC,
MAX_LIST_LEN, MAX_MAP_LEN, MAX_RECORD_LEN, TAG_SYS_AWAIT, TAG_SYS_DOWN, TAG_SYS_EXIT,
};
pub use log::LogSink;
pub use memory::{HeapBytes, HeapStr, MemoryBudget, MemoryError, MemorySnapshot};
pub use natives::{
std_native, std_native_map, std_native_table, std_native_table_with, std_natives,
};
pub use output::{NullSink, OutputSink, StdoutSink};
#[cfg(feature = "jit")]
pub use scheduler::JitConfig;
pub use scheduler::{
check_admin, check_link, check_monitor, decode_frame, encode_frame, exec_delegate, fault_count,
finish_host_await, flow_id_from_u64, next_flow_id, report_fault, AdminError, CapError,
Capability, ChildSpec, DelegateError, Delivery, DistributionBridge, DownEvent, Flow,
FlowExitReason, FlowHandle, FlowId, FlowMetrics, FlowOutcome, FlowQuota, HostAwaitBridge,
HostAwaitCompleter, HostAwaitError, HostAwaitOp, HostAwaitRequest, JoinError, LifecycleError,
LinkError, LinkId, Mailbox, MailboxBytes, MailboxCapacity, MailboxConfig, MailboxFull,
MailboxFullReason, MailboxStats, MonitorRef, OutboundHop, OverflowPolicy, QuotaConfig,
QuotaError, RegistryName, RemoteFrameDedup, RemoteFrameError, RestartStrategy, Runtime,
RuntimeConfig, RuntimeError, RuntimeMetrics, RuntimeMetricsSnapshot, RuntimeSnapshot,
RuntimeSpawner, SendError, SpawnError, Supervisor, SupervisorConfig, ThreadedHostAwait,
WaitEpoch, DEFAULT_QUANTUM,
};
pub use transport::{
read_wire_frame, recv_wire_frame_udp, send_wire_frame_udp, spawn_tcp_inbound,
spawn_tcp_outbound, wait_bridge_drained, write_wire_frame, NodeRouter, StaticNodeRouter,
TcpInboundConfig, TcpInboundHandle, TcpOutboundConfig, TcpOutboundHandle, TransportError,
DEFAULT_MAX_WIRE_BYTES,
};
pub use vm::{
check_native_call, check_native_gate, expect_arg, expect_bool, expect_int, expect_message,
expect_u64, Fault, NativeCallError, NativeFn, NativeGate, NativeResult, NativeTable,
NativeTableBuilder, NativeTableError, Vm, VmResult, MAX_CALL_DEPTH,
};
#[cfg(feature = "jit")]
pub use jit::{
apply_exit_to_vm, force_compile, hot_threshold, run_compiled_trace, run_compiled_trace_ref,
run_vm_with_jit, run_vm_with_jit_runtime, sync_slots_from_vm, try_run_hot, try_run_hot_runtime,
CompileError, CompiledTrace, ExitReason, HotCounter, JitContext, JitEntry, JitFrame, JitReturn,
JitRuntime, SyncSlotsResult, TraceCache, TraceCompiler, TraceKey, TraceSpan, HOT_THRESHOLD,
JIT_BUDGET, JIT_CONTINUE, JIT_DEOPT, JIT_EFFECT, JIT_RETURN, JIT_TRAP, MAX_TRACE_LENGTH,
};
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn std_native_map_has_stable_indices() {
let map = std_native_map();
assert_eq!(map.get("print"), Some(&0));
assert_eq!(map.get("now_ms"), Some(&1));
assert_eq!(map.get("make_msg"), Some(&2));
assert_eq!(map.get("msg_payload"), Some(&6));
assert_eq!(map.get("msg_reply_cap"), Some(&7));
}
#[test]
fn std_native_chunk_runs() -> Result<(), Box<dyn std::error::Error>> {
let mut program = Program::new("std-natives-demo");
program.function("main", 0, |f| {
let n = f.load_i32(42);
f.native1_on(n, 0);
let ms = f.call_native0(1);
f.return_(ms);
});
let chunk = program.build();
verify(&chunk)?;
let rt = Runtime::with_natives(chunk, std_native_table())?;
let outcome = rt.spawn(0, &[])?.join();
rt.shutdown();
match outcome {
FlowOutcome::Completed(Value::Int(ms)) => {
assert!(ms >= 0);
Ok(())
}
other => Err(format!("expected Completed(Value::Int(_)), got {other:?}").into()),
}
}
}