pub struct BpfCodec(pub BpfVariant);Expand description
One codec per BPF variant.
Tuple Fields§
§0: BpfVariantImplementations§
Trait Implementations§
Source§impl ArchCodec for BpfCodec
impl ArchCodec for BpfCodec
Source§fn encode_call(
&self,
source_ip: u64,
target: u64,
hints: EncodeHints,
) -> Result<Vec<u8>, ArchError>
fn encode_call( &self, source_ip: u64, target: u64, hints: EncodeHints, ) -> Result<Vec<u8>, ArchError>
Encode an intra-program call. The choice between
call_local (opcode 0x8d, Linux eBPF convention) and
call_internal (opcode 0x85 src=1, Solana sBPF
convention) is hinted by EncodeHints::bpf_call_local:
Some(true) → call_local, Some(false) → call_internal,
None → default to call_internal (Solana sBPF, the
dominant convention in practice; Solana programs
often carry e_machine = EM_BPF (247) despite using
the sBPF call form, so the EM marker alone can’t
disambiguate). The imm is the slot delta from the
next slot to the target, signed.
Syscalls (opcode 0x85 src=0, imm = a name hash or -1)
don’t go through this method — they remain pinned in
Stmt::Call.bytes because the imm depends on
relocation context the codec doesn’t carry.
Source§fn direct_call_bytes_contain_call(&self) -> bool
fn direct_call_bytes_contain_call(&self) -> bool
BPF calls are single 8-byte instructions — pinned
Stmt::Call.bytes (when present) is the complete call.
Source§fn encode_move(&self, dst: &str, src: &str) -> Result<Vec<u8>, ArchError>
fn encode_move(&self, dst: &str, src: &str) -> Result<Vec<u8>, ArchError>
Encode dst = src as one BPF instruction.
Supported shapes:
("rN", "rM")→mov64 rN, rM(8 bytes)("rN", "0xN")→mov64 rN, imm32(8 bytes)("rN", "[rM ± off]")(optional:uNNsuffix) →ldxdw / ldxw / ldxh / ldxb rN, [rM ± off](8 bytes)("[rN ± off]", "rM")(optional:uNNsuffix on dst) →stxdw / stxw / stxh / stxb [rN ± off], rM(8 bytes)("rN", "0x<imm>:u64")→lddw rN, 0x<imm>(16 bytes, two BPF slots — the second being a zero-opcode continuation slot carrying the high 32 bits)
The :u<bits> size suffix on a memory operand picks the
access width (:u8 / :u16 / :u32 / :u64); the bare
[rN ± off] form defaults to :u64 (BPF dw).
Source§fn encode_return(&self, _value: Option<u64>) -> Result<Vec<u8>, ArchError>
fn encode_return(&self, _value: Option<u64>) -> Result<Vec<u8>, ArchError>
Encode a function return. BPF returns r0 implicitly via
the exit instruction; the value field is ignored.
Source§fn encode_arith(
&self,
dst: &str,
op: &str,
src: &str,
) -> Result<Vec<u8>, ArchError>
fn encode_arith( &self, dst: &str, op: &str, src: &str, ) -> Result<Vec<u8>, ArchError>
Encode dst op src as a single 64-bit BPF ALU
instruction. The op string maps to the corresponding
BPF mnemonic; the src may be a register (r0..r10)
or an immediate (0x<hex> / decimal).
Returns Unsupported for operators outside the lifted
set (arsh, neg, 32-bit forms keep their @asm
rendering for now).
Source§fn name(&self) -> &'static str
fn name(&self) -> &'static str
ArchError::Unsupported.arch. Recommended forms:
"x86-64", "x86-32", "bpf-linux", "bpf-sbf-v1",
"bpf-sbf-v2", "aarch64", "6502".Source§fn assemble_one(&self, text: &str, _addr: u64) -> Result<Vec<u8>, ArchError>
fn assemble_one(&self, text: &str, _addr: u64) -> Result<Vec<u8>, ArchError>
addr. Read moreSource§fn desymbolize(&self, text: &str, addr: u64) -> String
fn desymbolize(&self, text: &str, addr: u64) -> String
text against addr. The
default is identity — arches with named-target operands
(BPF’s label_<hex> / sub_<hex>) override to substitute
numeric forms the assembler accepts.Source§fn encode_jump(
&self,
source_ip: u64,
target: u64,
_hints: EncodeHints,
) -> Result<Vec<u8>, ArchError>
fn encode_jump( &self, source_ip: u64, target: u64, _hints: EncodeHints, ) -> Result<Vec<u8>, ArchError>
source_ip to target.Source§fn encode_cond_jump(
&self,
cond_text: &str,
source_ip: u64,
target: u64,
_hints: EncodeHints,
) -> Result<Vec<u8>, ArchError>
fn encode_cond_jump( &self, cond_text: &str, source_ip: u64, target: u64, _hints: EncodeHints, ) -> Result<Vec<u8>, ArchError>
Source§fn encode_switch_dispatch(
&self,
_spec: &SwitchSpec<'_>,
) -> Result<Vec<u8>, ArchError>
fn encode_switch_dispatch( &self, _spec: &SwitchSpec<'_>, ) -> Result<Vec<u8>, ArchError>
Unsupported.Source§fn encoded_jump_size(
&self,
_source_ip: u64,
_target: u64,
_hints: EncodeHints,
) -> usize
fn encoded_jump_size( &self, _source_ip: u64, _target: u64, _hints: EncodeHints, ) -> usize
encode_jump’s output.Source§fn encoded_cond_jump_size(
&self,
_source_ip: u64,
_target: u64,
_hints: EncodeHints,
) -> usize
fn encoded_cond_jump_size( &self, _source_ip: u64, _target: u64, _hints: EncodeHints, ) -> usize
encode_cond_jump (text-driven).Source§fn encoded_call_size(
&self,
_source_ip: u64,
_target: u64,
_hints: EncodeHints,
) -> usize
fn encoded_call_size( &self, _source_ip: u64, _target: u64, _hints: EncodeHints, ) -> usize
encode_call’s output.