Skip to main content

define_syscall

Macro define_syscall 

Source
macro_rules! define_syscall {
    (@reloc $(#[$attr:meta])* $vis:vis fn $name:ident($($arg:ident: $typ:ty),* $(,)?) -> $ret:ty) => { ... };
    (@reloc $(#[$attr:meta])* $vis:vis fn $name:ident($($arg:ident: $typ:ty),* $(,)?) -> $ret:ty; link_name = $sym:literal) => { ... };
    (@static $(#[$attr:meta])* $vis:vis fn $name:ident($($arg:ident: $typ:ty),* $(,)?) -> $ret:ty; hash = $sym:expr) => { ... };
    (#[link_name = $sym:literal] $(#[$attr:meta])* $vis:vis fn $name:ident($($arg:ident: $typ:ty),* $(,)?) -> $ret:ty) => { ... };
    (#[link_name = $sym:literal] $(#[$attr:meta])* $vis:vis fn $name:ident($($arg:ident: $typ:ty),* $(,)?)) => { ... };
    ($(#[$attr:meta])* $vis:vis fn $name:ident($($arg:ident: $typ:ty),* $(,)?) -> $ret:ty) => { ... };
    ($(#[$attr:meta])* $vis:vis fn $name:ident($($arg:ident: $typ:ty),* $(,)?)) => { ... };
}
Expand description

Declare a Solana syscall in a build-mode-agnostic way.

See the module docs for the two emitted forms. Two surface syntaxes are supported:

ⓘ
// 1. Rust name == the runtime symbol name (native decls).
define_syscall!(fn sol_log_(message: *const u8, len: u64));

// 2. Rust name differs from the symbol name; give the symbol explicitly
//    so the static-mode hash is taken over the real syscall name.
define_syscall!(fn syscall_sol_memcpy(dst: *mut u8, src: *const u8, n: u64);
    link_name = "sol_memcpy_");

Invocations are expected to be gated on #[cfg(target_os = "solana")] by the caller, exactly as the historical extern "C" blocks were. The macro itself does not add that gate, which lets host tests exercise both emitted forms.