pub struct Insn {
pub ptr: usize,
pub opc: u8,
pub dst: u8,
pub src: u8,
pub off: i16,
pub imm: i64,
}
Expand description
An eBPF instruction.
See https://www.kernel.org/doc/Documentation/networking/filter.txt for the Linux kernel documentation about eBPF, or https://github.com/iovisor/bpf-docs/blob/master/eBPF.md for a more concise version.
Fields§
§ptr: usize
Instruction pointer.
opc: u8
Operation code.
dst: u8
Destination register operand.
src: u8
Source register operand.
off: i16
Offset operand.
imm: i64
Immediate value operand.
Implementations§
Source§impl Insn
impl Insn
Sourcepub fn to_array(&self) -> [u8; 8]
pub fn to_array(&self) -> [u8; 8]
Turn an Insn
back into an array of bytes.
§Examples
use solana_sbpf::ebpf;
let prog: &[u8] = &[
0xb7, 0x12, 0x56, 0x34, 0xde, 0xbc, 0x9a, 0x78,
];
let insn = ebpf::Insn {
ptr: 0x00,
opc: 0xb7,
dst: 2,
src: 1,
off: 0x3456,
imm: 0x789abcde
};
assert_eq!(insn.to_array(), prog);
Sourcepub fn to_vec(&self) -> Vec<u8> ⓘ
pub fn to_vec(&self) -> Vec<u8> ⓘ
Turn an Insn
into an vector of bytes.
§Examples
use solana_sbpf::ebpf;
let prog: Vec<u8> = vec![
0xb7, 0x12, 0x56, 0x34, 0xde, 0xbc, 0x9a, 0x78,
];
let insn = ebpf::Insn {
ptr: 0x00,
opc: 0xb7,
dst: 2,
src: 1,
off: 0x3456,
imm: 0x789abcde
};
assert_eq!(insn.to_vec(), prog);
Trait Implementations§
impl Eq for Insn
impl StructuralPartialEq for Insn
Auto Trait Implementations§
impl Freeze for Insn
impl RefUnwindSafe for Insn
impl Send for Insn
impl Sync for Insn
impl Unpin for Insn
impl UnwindSafe for Insn
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more