[][src]Function solana_rbpf::ebpf::get_insn

pub fn get_insn(prog: &[u8], idx: usize) -> Insn

Get the instruction at idx of an eBPF program. idx is the index (number) of the instruction (not a byte offset). The first instruction has index 0.

Panics

Panics if it is not possible to get the instruction (if idx is too high, or last instruction is incomplete).

Examples

use solana_rbpf::ebpf;

let prog = &[
    0xb7, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x95, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
    ];
let insn = ebpf::get_insn(prog, 1);
assert_eq!(insn.opc, 0x95);

The example below will panic, since the last instruction is not complete and cannot be loaded.

use solana_rbpf::ebpf;

let prog = &[
    0xb7, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x95, 0x00, 0x00, 0x00, 0x00, 0x00              // two bytes missing
    ];
let insn = ebpf::get_insn(prog, 1);