Skip to content

Commit

Permalink
Fix LDDW Related Bugs (#140)
Browse files Browse the repository at this point in the history
* Fixes placing the entrypoint in the middle of a "lddw" instruction

* Fixes traces of jumps into the middle of "lddw" instructions.

* Fixes jumps close to the end of the program landing in exception handlers if lddw instructions are present (in JIT compiler).
Also updates test_large_program() accordingly.
  • Loading branch information
Lichtso committed Feb 12, 2021
1 parent 575506c commit a278fbb
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 154 deletions.
4 changes: 2 additions & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use clap::{App, Arg};
use rustc_demangle::demangle;
use solana_rbpf::{
assembler::assemble,
disassembler::{to_insn_vec, HLInsn},
disassembler::{to_insn_vec, HlInsn},
ebpf,
memory_region::{MemoryMapping, MemoryRegion},
user_error::UserError,
Expand Down Expand Up @@ -63,7 +63,7 @@ macro_rules! resolve_label {
}

struct AnalysisResult {
instructions: Vec<HLInsn>,
instructions: Vec<HlInsn>,
destinations: BTreeMap<usize, Label>,
sources: BTreeMap<usize, Vec<usize>>,
}
Expand Down
12 changes: 6 additions & 6 deletions src/disassembler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fn jmp_reg_str(name: &str, insn: &ebpf::Insn) -> String {
/// documentation about eBPF, or <https://github.com/iovisor/bpf-docs/blob/master/eBPF.md> for a
/// more concise version.
#[derive(Debug, PartialEq)]
pub struct HLInsn {
pub struct HlInsn {
/// Instruction pointer.
pub ptr: usize,
/// Operation code.
Expand All @@ -102,7 +102,7 @@ pub struct HLInsn {
pub imm: i64,
}

/// Return a vector of `struct HLInsn` built from an eBPF program.
/// Return a vector of `struct HlInsn` built from an eBPF program.
///
/// This is made public to provide a way to manipulate a program as a vector of instructions, in a
/// high-level format, for example for dumping the program instruction after instruction with a
Expand Down Expand Up @@ -133,7 +133,7 @@ pub struct HLInsn {
///
/// let v = disassembler::to_insn_vec(prog);
/// assert_eq!(v, vec![
/// disassembler::HLInsn {
/// disassembler::HlInsn {
/// ptr: 0,
/// opc: 0x18,
/// name: "lddw".to_string(),
Expand All @@ -143,7 +143,7 @@ pub struct HLInsn {
/// off: 0,
/// imm: 0x1122334455667788
/// },
/// disassembler::HLInsn {
/// disassembler::HlInsn {
/// ptr: 2,
/// opc: 0x95,
/// name: "exit".to_string(),
Expand All @@ -156,7 +156,7 @@ pub struct HLInsn {
/// ]);
/// ```
#[rustfmt::skip]
pub fn to_insn_vec(prog: &[u8]) -> Vec<HLInsn> {
pub fn to_insn_vec(prog: &[u8]) -> Vec<HlInsn> {
debug_assert!(prog.len() % ebpf::INSN_SIZE == 0, "eBPF program length must be a multiple of {:?} octets is {:?}", ebpf::INSN_SIZE, prog.len());

if prog.is_empty() {
Expand Down Expand Up @@ -301,7 +301,7 @@ pub fn to_insn_vec(prog: &[u8]) -> Vec<HLInsn> {
},
};

res.push(HLInsn {
res.push(HlInsn {
ptr,
opc: insn.opc,
name: name.to_string(),
Expand Down

0 comments on commit a278fbb

Please sign in to comment.