From 796e0370635fd80443b0f689ed49fa9fbe4bd2d5 Mon Sep 17 00:00:00 2001 From: Lucas Steuernagel Date: Fri, 18 Oct 2024 08:40:01 -0300 Subject: [PATCH] Rename get function --- src/disassembler.rs | 2 +- src/elf.rs | 7 +++++-- src/interpreter.rs | 2 +- src/jit.rs | 2 +- src/program.rs | 10 +++++++--- src/static_analysis.rs | 2 +- 6 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/disassembler.rs b/src/disassembler.rs index b500b0a5..3248ffc2 100644 --- a/src/disassembler.rs +++ b/src/disassembler.rs @@ -271,7 +271,7 @@ pub fn disassemble_instruction( function_name } else { name = "syscall"; - loader.get_function_registry().lookup_by_key(insn.imm as u32).map(|(function_name, _)| String::from_utf8_lossy(function_name).to_string()).unwrap_or_else(|| "[invalid]".to_string()) + loader.get_sparse_function_registry().lookup_by_key(insn.imm as u32).map(|(function_name, _)| String::from_utf8_lossy(function_name).to_string()).unwrap_or_else(|| "[invalid]".to_string()) }; desc = format!("{name} {function_name}"); }, diff --git a/src/elf.rs b/src/elf.rs index 62cdc575..eeefb7cf 100644 --- a/src/elf.rs +++ b/src/elf.rs @@ -318,7 +318,7 @@ impl Executable { self.get_config(), self.get_sbpf_version(), self.get_function_registry(), - self.loader.get_function_registry(), + self.loader.get_sparse_function_registry(), )?; Ok(()) } @@ -1074,7 +1074,10 @@ impl Executable { .entry(symbol.st_name) .or_insert_with(|| ebpf::hash_symbol_name(name)); if config.reject_broken_elfs - && loader.get_function_registry().lookup_by_key(hash).is_none() + && loader + .get_sparse_function_registry() + .lookup_by_key(hash) + .is_none() { return Err(ElfError::UnresolvedSymbol( String::from_utf8_lossy(name).to_string(), diff --git a/src/interpreter.rs b/src/interpreter.rs index 34ea6dd8..26e8c800 100644 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -536,7 +536,7 @@ impl<'a, 'b, C: ContextObject> Interpreter<'a, 'b, C> { }; if external { - if let Some((_function_name, function)) = self.executable.get_loader().get_function_registry().lookup_by_key(insn.imm as u32) { + if let Some((_function_name, function)) = self.executable.get_loader().get_sparse_function_registry().lookup_by_key(insn.imm as u32) { resolved = true; self.vm.due_insn_count = self.vm.previous_instruction_meter - self.vm.due_insn_count; diff --git a/src/jit.rs b/src/jit.rs index 1f48034e..c961828f 100644 --- a/src/jit.rs +++ b/src/jit.rs @@ -717,7 +717,7 @@ impl<'a, C: ContextObject> JitCompiler<'a, C> { }; if external { - if let Some((_function_name, function)) = self.executable.get_loader().get_function_registry().lookup_by_key(insn.imm as u32) { + if let Some((_function_name, function)) = self.executable.get_loader().get_sparse_function_registry().lookup_by_key(insn.imm as u32) { self.emit_validate_and_profile_instruction_count(false, Some(0)); self.emit_ins(X86Instruction::load_immediate(OperandSize::S64, REGISTER_SCRATCH, function as usize as i64)); self.emit_ins(X86Instruction::call_immediate(self.relative_to_anchor(ANCHOR_EXTERNAL_FUNCTION_CALL, 5))); diff --git a/src/program.rs b/src/program.rs index 9221c862..0612b773 100644 --- a/src/program.rs +++ b/src/program.rs @@ -184,7 +184,11 @@ impl FunctionRegistry { } else { ebpf::hash_symbol_name(&usize::from(value).to_le_bytes()) }; - if loader.get_function_registry().lookup_by_key(hash).is_some() { + if loader + .get_sparse_function_registry() + .lookup_by_key(hash) + .is_some() + { return Err(ElfError::SymbolHashCollision(hash)); } hash @@ -315,8 +319,8 @@ impl BuiltinProgram { self.config.as_ref().unwrap() } - /// Get the function registry - pub fn get_function_registry(&self) -> &FunctionRegistry> { + /// Get the sparse function registry + pub fn get_sparse_function_registry(&self) -> &FunctionRegistry> { &self.sparse_registry } diff --git a/src/static_analysis.rs b/src/static_analysis.rs index aa5d0ae3..ab73c6cc 100644 --- a/src/static_analysis.rs +++ b/src/static_analysis.rs @@ -236,7 +236,7 @@ impl<'a> Analysis<'a> { if let Some((function_name, _function)) = self .executable .get_loader() - .get_function_registry() + .get_sparse_function_registry() .lookup_by_key(insn.imm as u32) { if function_name == b"abort" {