Skip to main content

Crate nub_rt_macro

Crate nub_rt_macro 

Source
Expand description

Procedural macros for declaring nub_rt guest endpoints.

The #[nub_rt::endpoint(N)] attribute marks a function as endpoint N of a PVM2 program. The macro emits three items into the guest crate:

  1. The function definition itself, unchanged.
  2. A per-endpoint trampoline __nub_rt_ep_N_trampoline in .text that calls the user function, then halts the VM via a bare ecall with no CSR marker, which the linker rewrites to custom-0 ecalli imm=0 — the clean-halt convention. The trampoline lives in regular code; the engine enters it at endpoints[N].entry_pc.
  3. A nub_rt::EndpointDescriptor static in the .nub.endpoints ELF section whose fn_ptr points at the trampoline (not the user fn). nub-linker reads the section at link time and resolves each fn_ptr to a PVM PC.
#[nub_rt::endpoint(0)]
fn process(args_len: u64) -> u64 { ... }

On host targets the macro emits only the function definition; the trampoline and descriptor are gated behind cfg(all(target_os = "none", target_arch = "riscv64")).

Attribute Macros§

endpoint
Mark a function as endpoint N of a PVM2 program.