Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,75 +139,75 @@ pub fn execute_program(
// BPF_LDX class
ebpf::LD_B_REG => reg[_dst] = unsafe {
#[allow(clippy::cast_ptr_alignment)]
let x = (reg[_src] as *const u8).offset(insn.off as isize) as *const u8;
let x = (reg[_src] as *const u8).wrapping_offset(insn.off as isize) as *const u8;
check_mem_load(x as u64, 1, insn_ptr)?;
x.read_unaligned() as u64
},
ebpf::LD_H_REG => reg[_dst] = unsafe {
#[allow(clippy::cast_ptr_alignment)]
let x = (reg[_src] as *const u8).offset(insn.off as isize) as *const u16;
let x = (reg[_src] as *const u8).wrapping_offset(insn.off as isize) as *const u16;
check_mem_load(x as u64, 2, insn_ptr)?;
x.read_unaligned() as u64
},
ebpf::LD_W_REG => reg[_dst] = unsafe {
#[allow(clippy::cast_ptr_alignment)]
let x = (reg[_src] as *const u8).offset(insn.off as isize) as *const u32;
let x = (reg[_src] as *const u8).wrapping_offset(insn.off as isize) as *const u32;
check_mem_load(x as u64, 4, insn_ptr)?;
x.read_unaligned() as u64
},
ebpf::LD_DW_REG => reg[_dst] = unsafe {
#[allow(clippy::cast_ptr_alignment)]
let x = (reg[_src] as *const u8).offset(insn.off as isize) as *const u64;
let x = (reg[_src] as *const u8).wrapping_offset(insn.off as isize) as *const u64;
check_mem_load(x as u64, 8, insn_ptr)?;
x.read_unaligned()
},

// BPF_ST class
ebpf::ST_B_IMM => unsafe {
let x = (reg[_dst] as *const u8).offset(insn.off as isize) as *mut u8;
let x = (reg[_dst] as *const u8).wrapping_offset(insn.off as isize) as *mut u8;
check_mem_store(x as u64, 1, insn_ptr)?;
x.write_unaligned(insn.imm as u8);
},
ebpf::ST_H_IMM => unsafe {
#[allow(clippy::cast_ptr_alignment)]
let x = (reg[_dst] as *const u8).offset(insn.off as isize) as *mut u16;
let x = (reg[_dst] as *const u8).wrapping_offset(insn.off as isize) as *mut u16;
check_mem_store(x as u64, 2, insn_ptr)?;
x.write_unaligned(insn.imm as u16);
},
ebpf::ST_W_IMM => unsafe {
#[allow(clippy::cast_ptr_alignment)]
let x = (reg[_dst] as *const u8).offset(insn.off as isize) as *mut u32;
let x = (reg[_dst] as *const u8).wrapping_offset(insn.off as isize) as *mut u32;
check_mem_store(x as u64, 4, insn_ptr)?;
x.write_unaligned(insn.imm as u32);
},
ebpf::ST_DW_IMM => unsafe {
#[allow(clippy::cast_ptr_alignment)]
let x = (reg[_dst] as *const u8).offset(insn.off as isize) as *mut u64;
let x = (reg[_dst] as *const u8).wrapping_offset(insn.off as isize) as *mut u64;
check_mem_store(x as u64, 8, insn_ptr)?;
x.write_unaligned(insn.imm as u64);
},

// BPF_STX class
ebpf::ST_B_REG => unsafe {
let x = (reg[_dst] as *const u8).offset(insn.off as isize) as *mut u8;
let x = (reg[_dst] as *const u8).wrapping_offset(insn.off as isize) as *mut u8;
check_mem_store(x as u64, 1, insn_ptr)?;
x.write_unaligned(reg[_src] as u8);
},
ebpf::ST_H_REG => unsafe {
#[allow(clippy::cast_ptr_alignment)]
let x = (reg[_dst] as *const u8).offset(insn.off as isize) as *mut u16;
let x = (reg[_dst] as *const u8).wrapping_offset(insn.off as isize) as *mut u16;
check_mem_store(x as u64, 2, insn_ptr)?;
x.write_unaligned(reg[_src] as u16);
},
ebpf::ST_W_REG => unsafe {
#[allow(clippy::cast_ptr_alignment)]
let x = (reg[_dst] as *const u8).offset(insn.off as isize) as *mut u32;
let x = (reg[_dst] as *const u8).wrapping_offset(insn.off as isize) as *mut u32;
check_mem_store(x as u64, 4, insn_ptr)?;
x.write_unaligned(reg[_src] as u32);
},
ebpf::ST_DW_REG => unsafe {
#[allow(clippy::cast_ptr_alignment)]
let x = (reg[_dst] as *const u8).offset(insn.off as isize) as *mut u64;
let x = (reg[_dst] as *const u8).wrapping_offset(insn.off as isize) as *mut u64;
check_mem_store(x as u64, 8, insn_ptr)?;
x.write_unaligned(reg[_src]);
},
Expand Down
Loading