Skip to content

Commit

Permalink
Make cargo clippy happy.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lichtso committed Jun 15, 2021
1 parent c6bbf70 commit 36a0de3
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 122 deletions.
188 changes: 94 additions & 94 deletions src/disassembler.rs

Large diffs are not rendered by default.

15 changes: 7 additions & 8 deletions src/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,7 @@ impl<E: UserDefinedError, I: InstructionMeter> Executable<E, I> for EBpfElf<E, I
fn get_text_bytes(&self) -> Result<(u64, &[u8]), EbpfError<E>> {
Ok((
self.text_section_info.vaddr,
&self
.elf_bytes
self.elf_bytes
.as_slice()
.get(self.text_section_info.offset_range.clone())
.ok_or(ElfError::OutOfBounds)?,
Expand Down Expand Up @@ -327,7 +326,7 @@ impl<E: UserDefinedError, I: InstructionMeter> Executable<E, I> for EBpfElf<E, I
continue;
}
let name = elf.dynstrtab.get(symbol.st_name).unwrap().unwrap();
let hash = ebpf::hash_symbol_name(&name.as_bytes());
let hash = ebpf::hash_symbol_name(name.as_bytes());
syscalls.insert(hash, name.to_string());
}
}
Expand Down Expand Up @@ -369,7 +368,7 @@ impl<'a, E: UserDefinedError, I: InstructionMeter> EBpfElf<E, I> {
let elf = Elf::parse(bytes)?;
let mut elf_bytes = AlignedMemory::new_with_data(bytes, ebpf::HOST_ALIGN);

Self::validate(&elf, &elf_bytes.as_slice())?;
Self::validate(&elf, elf_bytes.as_slice())?;

// calculate the text section info
let text_section = Self::get_section(&elf, ".text")?;
Expand Down Expand Up @@ -569,7 +568,7 @@ impl<'a, E: UserDefinedError, I: InstructionMeter> EBpfElf<E, I> {
let checked_slice = elf_bytes
.get(imm_offset..imm_offset.saturating_add(BYTE_LENGTH_IMMEIDATE))
.ok_or(ElfError::OutOfBounds)?;
let refd_va = LittleEndian::read_u32(&checked_slice) as u64;
let refd_va = LittleEndian::read_u32(checked_slice) as u64;

if refd_va == 0 {
return Err(ElfError::InvalidVirtualAddress(refd_va));
Expand Down Expand Up @@ -630,10 +629,10 @@ impl<'a, E: UserDefinedError, I: InstructionMeter> EBpfElf<E, I> {
}
let target_pc =
(sym.st_value - text_section.sh_addr) as usize / ebpf::INSN_SIZE;
register_bpf_function(bpf_functions, target_pc, &name)?
register_bpf_function(bpf_functions, target_pc, name)?
} else {
// syscall
ebpf::hash_symbol_name(&name.as_bytes())
ebpf::hash_symbol_name(name.as_bytes())
};
let mut checked_slice = elf_bytes
.get_mut(imm_offset..imm_offset.saturating_add(BYTE_LENGTH_IMMEIDATE))
Expand Down Expand Up @@ -661,7 +660,7 @@ impl<'a, E: UserDefinedError, I: InstructionMeter> EBpfElf<E, I> {
.get(symbol.st_name)
.ok_or(ElfError::UnknownSymbol(symbol.st_name))?
.map_err(|_| ElfError::UnknownSymbol(symbol.st_name))?;
register_bpf_function(bpf_functions, target_pc, &name)?;
register_bpf_function(bpf_functions, target_pc, name)?;
}

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions src/jit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1301,10 +1301,10 @@ impl JitCompiler {

fn resolve_jumps(&mut self) {
for jump in &self.pc_section_jumps {
self.result.pc_section[jump.location] = jump.get_target_offset(&self);
self.result.pc_section[jump.location] = jump.get_target_offset(self);
}
for jump in &self.text_section_jumps {
let offset_value = jump.get_target_offset(&self) as i32
let offset_value = jump.get_target_offset(self) as i32
- jump.location as i32 // Relative jump
- std::mem::size_of::<i32>() as i32; // Jump from end of instruction
unsafe {
Expand Down
2 changes: 1 addition & 1 deletion src/memory_region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl fmt::Debug for MemoryRegion {
}
impl std::cmp::PartialOrd for MemoryRegion {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(&other))
Some(self.cmp(other))
}
}
impl std::cmp::Ord for MemoryRegion {
Expand Down
14 changes: 7 additions & 7 deletions src/static_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl<'a, E: UserDefinedError, I: InstructionMeter> Analysis<'a, E, I> {
}
for destination in &destinations {
self.cfg_nodes
.get_mut(&destination)
.get_mut(destination)
.unwrap()
.sources
.push(source);
Expand Down Expand Up @@ -281,7 +281,7 @@ impl<'a, E: UserDefinedError, I: InstructionMeter> Analysis<'a, E, I> {
.filter(|(cfg_node_start, _cfg_node)| {
match self
.instructions
.binary_search_by(|insn| insn.ptr.cmp(&cfg_node_start))
.binary_search_by(|insn| insn.ptr.cmp(cfg_node_start))
{
Ok(_) => true,
Err(_index) => false,
Expand Down Expand Up @@ -381,7 +381,7 @@ impl<'a, E: UserDefinedError, I: InstructionMeter> Analysis<'a, E, I> {
/// Gives the basic blocks names
pub fn label_basic_blocks(&mut self) {
for (pc, cfg_node) in self.cfg_nodes.iter_mut() {
cfg_node.label = if let Some(function) = self.functions.get(&pc) {
cfg_node.label = if let Some(function) = self.functions.get(pc) {
demangle(&function.1).to_string()
} else {
format!("lbb_{}", pc)
Expand Down Expand Up @@ -425,7 +425,7 @@ impl<'a, E: UserDefinedError, I: InstructionMeter> Analysis<'a, E, I> {
insn.ptr,
&mut last_basic_block,
)?;
writeln!(output, " {}", disassemble_instruction(&insn, self))?;
writeln!(output, " {}", disassemble_instruction(insn, self))?;
}
Ok(())
}
Expand Down Expand Up @@ -477,7 +477,7 @@ impl<'a, E: UserDefinedError, I: InstructionMeter> Analysis<'a, E, I> {
cfg_node_start,
analysis.instructions[cfg_node.instructions.clone()].iter()
.map(|insn| {
let desc = disassemble_instruction(&insn, &analysis);
let desc = disassemble_instruction(insn, analysis);
if let Some(split_index) = desc.find(' ') {
let mut rest = desc[split_index+1..].to_string();
if rest.len() > MAX_CELL_CONTENT_LENGTH + 1 {
Expand Down Expand Up @@ -545,13 +545,13 @@ impl<'a, E: UserDefinedError, I: InstructionMeter> Analysis<'a, E, I> {
writeln!(
output,
" label={:?};",
html_escape(&self.cfg_nodes[&function_start].label)
html_escape(&self.cfg_nodes[function_start].label)
)?;
writeln!(output, " tooltip=lbb_{};", *function_start)?;
emit_cfg_node(
output,
dynamic_analysis,
&self,
self,
*function_start..function_end,
&mut alias_nodes,
*function_start,
Expand Down
16 changes: 8 additions & 8 deletions src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ impl Tracer {
index,
&entry[0..11],
pc + ebpf::ELF_INSN_DUMP_OFFSET,
disassemble_instruction(&insn, &analysis),
disassemble_instruction(insn, analysis),
)?;
}
Ok(())
Expand Down Expand Up @@ -421,7 +421,7 @@ pub const SYSCALL_CONTEXT_OBJECTS_OFFSET: usize = 6;
/// // Instantiate a VM.
/// let mut bpf_functions = std::collections::BTreeMap::new();
/// register_bpf_function(&mut bpf_functions, 0, "entrypoint").unwrap();
/// let mut executable = Executable::<UserError, DefaultInstructionMeter>::from_text_bytes(prog, bpf_functions, None, Config::default()).unwrap();
/// let mut executable = <dyn Executable::<UserError, DefaultInstructionMeter>>::from_text_bytes(prog, bpf_functions, None, Config::default()).unwrap();
/// let mut vm = EbpfVm::<UserError, DefaultInstructionMeter>::new(executable.as_ref(), mem, &[]).unwrap();
///
/// // Provide a reference to the packet data.
Expand Down Expand Up @@ -457,7 +457,7 @@ impl<'a, E: UserDefinedError, I: InstructionMeter> EbpfVm<'a, E, I> {
/// // Instantiate a VM.
/// let mut bpf_functions = std::collections::BTreeMap::new();
/// register_bpf_function(&mut bpf_functions, 0, "entrypoint").unwrap();
/// let mut executable = Executable::<UserError, DefaultInstructionMeter>::from_text_bytes(prog, bpf_functions, None, Config::default()).unwrap();
/// let mut executable = <dyn Executable::<UserError, DefaultInstructionMeter>>::from_text_bytes(prog, bpf_functions, None, Config::default()).unwrap();
/// let mut vm = EbpfVm::<UserError, DefaultInstructionMeter>::new(executable.as_ref(), &mut [], &[]).unwrap();
/// ```
pub fn new(
Expand All @@ -482,7 +482,7 @@ impl<'a, E: UserDefinedError, I: InstructionMeter> EbpfVm<'a, E, I> {
regions.push(frames.get_region().clone());
regions.extend(const_data_regions);
regions.push(MemoryRegion::new_from_slice(
&mem,
mem,
ebpf::MM_INPUT_START,
0,
true,
Expand All @@ -499,7 +499,7 @@ impl<'a, E: UserDefinedError, I: InstructionMeter> EbpfVm<'a, E, I> {
executable,
program,
program_vm_addr,
memory_mapping: MemoryMapping::new(regions, &config)?,
memory_mapping: MemoryMapping::new(regions, config)?,
tracer: Tracer::default(),
syscall_context_objects: vec![
std::ptr::null_mut();
Expand Down Expand Up @@ -527,7 +527,7 @@ impl<'a, E: UserDefinedError, I: InstructionMeter> EbpfVm<'a, E, I> {

/// Returns the program
pub fn get_program(&self) -> &[u8] {
&self.program
self.program
}

/// Returns the tracer
Expand Down Expand Up @@ -565,7 +565,7 @@ impl<'a, E: UserDefinedError, I: InstructionMeter> EbpfVm<'a, E, I> {
/// // Instantiate an Executable and VM
/// let mut bpf_functions = std::collections::BTreeMap::new();
/// register_bpf_function(&mut bpf_functions, 0, "entrypoint").unwrap();
/// let mut executable = Executable::<UserError, DefaultInstructionMeter>::from_text_bytes(prog, bpf_functions, None, Config::default()).unwrap();
/// let mut executable = <dyn Executable::<UserError, DefaultInstructionMeter>>::from_text_bytes(prog, bpf_functions, None, Config::default()).unwrap();
/// executable.set_syscall_registry(syscall_registry);
/// let mut vm = EbpfVm::<UserError, DefaultInstructionMeter>::new(executable.as_ref(), &mut [], &[]).unwrap();
/// // Bind a context object instance to the previously registered syscall
Expand Down Expand Up @@ -630,7 +630,7 @@ impl<'a, E: UserDefinedError, I: InstructionMeter> EbpfVm<'a, E, I> {
/// // Instantiate a VM.
/// let mut bpf_functions = std::collections::BTreeMap::new();
/// register_bpf_function(&mut bpf_functions, 0, "entrypoint").unwrap();
/// let mut executable = Executable::<UserError, DefaultInstructionMeter>::from_text_bytes(prog, bpf_functions, None, Config::default()).unwrap();
/// let mut executable = <dyn Executable::<UserError, DefaultInstructionMeter>>::from_text_bytes(prog, bpf_functions, None, Config::default()).unwrap();
/// let mut vm = EbpfVm::<UserError, DefaultInstructionMeter>::new(executable.as_ref(), mem, &[]).unwrap();
///
/// // Provide a reference to the packet data.
Expand Down
2 changes: 1 addition & 1 deletion tests/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ fn test_fuzz_execute() {
|bytes: &mut [u8]| {
if let Ok(mut executable) =
<dyn Executable<UserError, DefaultInstructionMeter>>::from_elf(
&bytes,
bytes,
Some(check),
Config::default(),
)
Expand Down
2 changes: 1 addition & 1 deletion tests/ubpf_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3275,7 +3275,7 @@ fn execute_generated_program(prog: &[u8]) -> bool {
let mut bpf_functions = BTreeMap::new();
register_bpf_function(&mut bpf_functions, 0, "entrypoint").unwrap();
let executable = <dyn Executable<UserError, TestInstructionMeter>>::from_text_bytes(
&prog,
prog,
bpf_functions,
Some(check),
Config {
Expand Down

0 comments on commit 36a0de3

Please sign in to comment.