From a3b5faeac4bccfc5337f2db16f5132b959deb197 Mon Sep 17 00:00:00 2001 From: Lucas Steuernagel Date: Thu, 17 Oct 2024 11:17:53 -0300 Subject: [PATCH 1/2] New data structure --- benches/elf_loader.rs | 3 +- benches/vm_execution.rs | 2 +- cli/src/main.rs | 2 +- examples/disassemble.rs | 2 +- examples/to_json.rs | 2 +- fuzz/fuzz_targets/dumb.rs | 6 +- fuzz/fuzz_targets/smart.rs | 6 +- fuzz/fuzz_targets/smart_jit_diff.rs | 6 +- fuzz/fuzz_targets/smarter_jit_diff.rs | 6 +- fuzz/fuzz_targets/verify_semantic_aware.rs | 4 +- src/assembler.rs | 2 +- src/elf.rs | 9 +- src/jit.rs | 4 +- src/program.rs | 197 ++++++++++++++++----- src/vm.rs | 2 +- tests/assembler.rs | 4 +- tests/disassembler.rs | 2 +- tests/execution.rs | 25 +-- tests/exercise_instructions.rs | 2 +- tests/verifier.rs | 33 ++-- 20 files changed, 215 insertions(+), 104 deletions(-) diff --git a/benches/elf_loader.rs b/benches/elf_loader.rs index 323be403..8dc72ab4 100644 --- a/benches/elf_loader.rs +++ b/benches/elf_loader.rs @@ -20,7 +20,8 @@ use std::{fs::File, io::Read, sync::Arc}; use test::Bencher; fn loader() -> Arc> { - let mut function_registry = FunctionRegistry::>::default(); + let mut function_registry = + FunctionRegistry::>::default_sparse(); function_registry .register_function_hashed(*b"log", syscalls::SyscallString::vm) .unwrap(); diff --git a/benches/vm_execution.rs b/benches/vm_execution.rs index 4404c927..e59057e3 100644 --- a/benches/vm_execution.rs +++ b/benches/vm_execution.rs @@ -87,7 +87,7 @@ fn bench_jit_vs_interpreter( assembly, Arc::new(BuiltinProgram::new_loader( config, - FunctionRegistry::default(), + FunctionRegistry::default_sparse(), )), ) .unwrap(); diff --git a/cli/src/main.rs b/cli/src/main.rs index cded744a..daa3a9a7 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -100,7 +100,7 @@ fn main() { enable_symbol_and_section_labels: true, ..Config::default() }, - FunctionRegistry::default(), + FunctionRegistry::default_dense(), )); #[allow(unused_mut)] let mut executable = match matches.value_of("assembler") { diff --git a/examples/disassemble.rs b/examples/disassemble.rs index 454fec2e..53bf80e8 100644 --- a/examples/disassemble.rs +++ b/examples/disassemble.rs @@ -36,7 +36,7 @@ fn main() { program, loader, SBPFVersion::V2, - FunctionRegistry::default(), + FunctionRegistry::default_sparse(), ) .unwrap(); let analysis = Analysis::from_executable(&executable).unwrap(); diff --git a/examples/to_json.rs b/examples/to_json.rs index 0e2950aa..18cf4e5e 100644 --- a/examples/to_json.rs +++ b/examples/to_json.rs @@ -32,7 +32,7 @@ fn to_json(program: &[u8]) -> String { program, Arc::new(BuiltinProgram::new_mock()), SBPFVersion::V2, - FunctionRegistry::default(), + FunctionRegistry::default_sparse(), ) .unwrap(); let analysis = Analysis::from_executable(&executable).unwrap(); diff --git a/fuzz/fuzz_targets/dumb.rs b/fuzz/fuzz_targets/dumb.rs index c1b1743d..fc2edf2b 100644 --- a/fuzz/fuzz_targets/dumb.rs +++ b/fuzz/fuzz_targets/dumb.rs @@ -28,8 +28,8 @@ struct DumbFuzzData { fuzz_target!(|data: DumbFuzzData| { let prog = data.prog; let config = data.template.into(); - let function_registry = FunctionRegistry::default(); - let syscall_registry = FunctionRegistry::>::default(); + let function_registry = FunctionRegistry::default_sparse(); + let syscall_registry = FunctionRegistry::>::default_sparse(); if RequisiteVerifier::verify(&prog, &config, &SBPFVersion::V2, &function_registry, &syscall_registry).is_err() { // verify please @@ -40,7 +40,7 @@ fuzz_target!(|data: DumbFuzzData| { &prog, std::sync::Arc::new(BuiltinProgram::new_loader( config, - FunctionRegistry::default(), + FunctionRegistry::default_sparse(), )), SBPFVersion::V2, function_registry, diff --git a/fuzz/fuzz_targets/smart.rs b/fuzz/fuzz_targets/smart.rs index 0ecb535b..a32f4cba 100644 --- a/fuzz/fuzz_targets/smart.rs +++ b/fuzz/fuzz_targets/smart.rs @@ -32,8 +32,8 @@ struct FuzzData { fuzz_target!(|data: FuzzData| { let prog = make_program(&data.prog, data.arch); let config = data.template.into(); - let function_registry = FunctionRegistry::default(); - let syscall_registry = FunctionRegistry::>::default(); + let function_registry = FunctionRegistry::default_sparse(); + let syscall_registry = FunctionRegistry::>::default_sparse(); if RequisiteVerifier::verify( prog.into_bytes(), @@ -52,7 +52,7 @@ fuzz_target!(|data: FuzzData| { prog.into_bytes(), std::sync::Arc::new(BuiltinProgram::new_loader( config, - FunctionRegistry::default(), + FunctionRegistry::default_sparse(), )), SBPFVersion::V2, function_registry, diff --git a/fuzz/fuzz_targets/smart_jit_diff.rs b/fuzz/fuzz_targets/smart_jit_diff.rs index 87203ca2..12f1b4cc 100644 --- a/fuzz/fuzz_targets/smart_jit_diff.rs +++ b/fuzz/fuzz_targets/smart_jit_diff.rs @@ -39,8 +39,8 @@ fuzz_target!(|data: FuzzData| { .set_imm(data.exit_imm) .push(); let config = data.template.into(); - let function_registry = FunctionRegistry::default(); - let syscall_registry = FunctionRegistry::>::default(); + let function_registry = FunctionRegistry::default_sparse(); + let syscall_registry = FunctionRegistry::>::default_sparse(); if RequisiteVerifier::verify( prog.into_bytes(), @@ -60,7 +60,7 @@ fuzz_target!(|data: FuzzData| { prog.into_bytes(), std::sync::Arc::new(BuiltinProgram::new_loader( config, - FunctionRegistry::default(), + FunctionRegistry::default_sparse(), )), SBPFVersion::V2, function_registry, diff --git a/fuzz/fuzz_targets/smarter_jit_diff.rs b/fuzz/fuzz_targets/smarter_jit_diff.rs index 6d77df41..739d7afe 100644 --- a/fuzz/fuzz_targets/smarter_jit_diff.rs +++ b/fuzz/fuzz_targets/smarter_jit_diff.rs @@ -29,8 +29,8 @@ struct FuzzData { fuzz_target!(|data: FuzzData| { let prog = make_program(&data.prog); let config = data.template.into(); - let function_registry = FunctionRegistry::default(); - let syscall_registry = FunctionRegistry::>::default(); + let function_registry = FunctionRegistry::default_sparse(); + let syscall_registry = FunctionRegistry::>::default_sparse(); if RequisiteVerifier::verify( prog.into_bytes(), @@ -50,7 +50,7 @@ fuzz_target!(|data: FuzzData| { prog.into_bytes(), std::sync::Arc::new(BuiltinProgram::new_loader( config, - FunctionRegistry::default(), + FunctionRegistry::default_sparse(), )), SBPFVersion::V2, function_registry, diff --git a/fuzz/fuzz_targets/verify_semantic_aware.rs b/fuzz/fuzz_targets/verify_semantic_aware.rs index 0c2cc09f..918b5783 100644 --- a/fuzz/fuzz_targets/verify_semantic_aware.rs +++ b/fuzz/fuzz_targets/verify_semantic_aware.rs @@ -24,8 +24,8 @@ struct FuzzData { fuzz_target!(|data: FuzzData| { let prog = make_program(&data.prog); let config = data.template.into(); - let function_registry = FunctionRegistry::default(); - let syscall_registry = FunctionRegistry::>::default(); + let function_registry = FunctionRegistry::default_sparse(); + let syscall_registry = FunctionRegistry::>::default_sparse(); RequisiteVerifier::verify( prog.into_bytes(), diff --git a/src/assembler.rs b/src/assembler.rs index ffdb3508..28e8f6b8 100644 --- a/src/assembler.rs +++ b/src/assembler.rs @@ -333,7 +333,7 @@ pub fn assemble( let statements = parse(src)?; let instruction_map = make_instruction_map(sbpf_version); let mut insn_ptr = 0; - let mut function_registry = FunctionRegistry::default(); + let mut function_registry = FunctionRegistry::default_sparse(); let mut labels = HashMap::new(); labels.insert("entrypoint", 0); for statement in statements.iter() { diff --git a/src/elf.rs b/src/elf.rs index f907705c..79da05c3 100644 --- a/src/elf.rs +++ b/src/elf.rs @@ -107,6 +107,9 @@ pub enum ElfError { /// Invalid program header #[error("Invalid ELF program header")] InvalidProgramHeader, + /// Invalid syscall code + #[error("Invalid function index")] + InvalidDenseFunctionIndex, } impl From for ElfError { @@ -419,7 +422,7 @@ impl Executable { } // relocate symbols - let mut function_registry = FunctionRegistry::default(); + let mut function_registry = FunctionRegistry::default_sparse(); Self::relocate( &mut function_registry, &loader, @@ -1164,7 +1167,7 @@ mod test { fn loader() -> Arc> { let mut function_registry = - FunctionRegistry::>::default(); + FunctionRegistry::>::default_sparse(); function_registry .register_function_hashed(*b"log", syscalls::SyscallString::vm) .unwrap(); @@ -1928,7 +1931,7 @@ mod test { reject_broken_elfs: true, ..Config::default() }, - FunctionRegistry::default(), + FunctionRegistry::default_sparse(), ); let elf_bytes = std::fs::read("tests/elfs/syscall_reloc_64_32_sbpfv1.so") .expect("failed to read elf file"); diff --git a/src/jit.rs b/src/jit.rs index 1f48034e..08b15078 100644 --- a/src/jit.rs +++ b/src/jit.rs @@ -1744,12 +1744,12 @@ mod tests { fn create_mockup_executable(config: Config, program: &[u8]) -> Executable { let sbpf_version = *config.enabled_sbpf_versions.end(); let mut function_registry = - FunctionRegistry::>::default(); + FunctionRegistry::>::default_sparse(); function_registry .register_function_hashed(*b"gather_bytes", syscalls::SyscallGatherBytes::vm) .unwrap(); let loader = BuiltinProgram::new_loader(config, function_registry); - let mut function_registry = FunctionRegistry::default(); + let mut function_registry = FunctionRegistry::default_sparse(); function_registry .register_function(8, *b"function_foo", 8) .unwrap(); diff --git a/src/program.rs b/src/program.rs index 1f817c02..f2230667 100644 --- a/src/program.rs +++ b/src/program.rs @@ -3,7 +3,8 @@ use { crate::{ ebpf, elf::ElfError, - vm::{Config, ContextObject, EbpfVm}, + error::{EbpfError, ProgramResult}, + vm::{get_runtime_environment_key, Config, ContextObject, EbpfVm}, }, std::collections::{btree_map::Entry, BTreeMap}, }; @@ -85,14 +86,45 @@ impl SBPFVersion { /// Holds the function symbols of an Executable #[derive(Debug, PartialEq, Eq)] -pub struct FunctionRegistry { - pub(crate) map: BTreeMap, T)>, +pub enum FunctionRegistry { + /// Sparse allows the registration of hashed symbols + Sparse(BTreeMap, T)>), + /// Dense allows the registration of symbols indexed by integers only + Dense(Vec<(Vec, T)>), } -impl Default for FunctionRegistry { - fn default() -> Self { - Self { - map: BTreeMap::new(), +impl FunctionRegistry { + /// Create an empty sparse function registry + pub fn default_sparse() -> Self { + FunctionRegistry::Sparse(BTreeMap::new()) + } + + /// Create and empty dense function registry + pub fn default_dense() -> Self { + FunctionRegistry::Dense(Vec::new()) + } +} + +impl FunctionRegistry> { + /// Create a dense function registry with pre-allocated spaces. + pub fn new_dense(size: usize) -> Self { + FunctionRegistry::Dense(vec![(b"tombstone".to_vec(), SyscallTombstone::vm); size]) + } +} + +impl FunctionRegistry { + /// Unregister a symbol again + pub fn unregister_function(&mut self, key: u32) { + match self { + FunctionRegistry::Sparse(map) => { + map.remove(&key); + } + FunctionRegistry::Dense(vec) => { + if key == 0 || key > vec.len() as u32 { + return; + } + vec[key.saturating_sub(1) as usize] = (b"tombstone".to_vec(), T::default()); + } } } } @@ -105,16 +137,25 @@ impl FunctionRegistry { name: impl Into>, value: T, ) -> Result<(), ElfError> { - match self.map.entry(key) { - Entry::Vacant(entry) => { - entry.insert((name.into(), value)); - } - Entry::Occupied(entry) => { - if entry.get().1 != value { - return Err(ElfError::SymbolHashCollision(key)); + match self { + FunctionRegistry::Sparse(map) => match map.entry(key) { + Entry::Vacant(entry) => { + entry.insert((name.into(), value)); } + Entry::Occupied(entry) => { + if entry.get().1 != value { + return Err(ElfError::SymbolHashCollision(key)); + } + } + }, + FunctionRegistry::Dense(vec) => { + if key == 0 || key > vec.len() as u32 { + return Err(ElfError::InvalidDenseFunctionIndex); + } + vec[key.saturating_sub(1) as usize] = (name.into(), value); } } + Ok(()) } @@ -168,51 +209,80 @@ impl FunctionRegistry { Ok(key) } - /// Unregister a symbol again - pub fn unregister_function(&mut self, key: u32) { - self.map.remove(&key); - } - /// Iterate over all keys - pub fn keys(&self) -> impl Iterator + '_ { - self.map.keys().copied() + pub fn keys(&self) -> Box + '_> { + match self { + FunctionRegistry::Sparse(map) => Box::new(map.keys().copied()), + FunctionRegistry::Dense(vec) => Box::new(1..=(vec.len() as u32)), + } } /// Iterate over all entries - pub fn iter(&self) -> impl Iterator + '_ { - self.map - .iter() - .map(|(key, (name, value))| (*key, (name.as_slice(), *value))) + #[allow(clippy::type_complexity)] + pub fn iter(&self) -> Box + '_> { + match self { + FunctionRegistry::Sparse(map) => Box::new( + map.iter() + .map(|(key, (name, value))| (*key, (name.as_slice(), *value))), + ), + FunctionRegistry::Dense(vec) => { + Box::new(vec.iter().enumerate().map(|(idx, value)| { + (idx.saturating_add(1) as u32, (value.0.as_slice(), value.1)) + })) + } + } } /// Get a function by its key pub fn lookup_by_key(&self, key: u32) -> Option<(&[u8], T)> { - // String::from_utf8_lossy(function_name).as_str() - self.map - .get(&key) - .map(|(function_name, value)| (function_name.as_slice(), *value)) + match self { + FunctionRegistry::Sparse(map) => map + .get(&key) + .map(|(function_name, value)| (function_name.as_slice(), *value)), + FunctionRegistry::Dense(vec) => { + if key == 0 { + return None; + } + vec.get(key.saturating_sub(1) as usize) + .map(|(function_name, value)| (function_name.as_slice(), *value)) + } + } } /// Get a function by its name pub fn lookup_by_name(&self, name: &[u8]) -> Option<(&[u8], T)> { - self.map - .values() - .find(|(function_name, _value)| function_name == name) - .map(|(function_name, value)| (function_name.as_slice(), *value)) + match self { + FunctionRegistry::Sparse(map) => map + .values() + .find(|(function_name, _value)| function_name == name) + .map(|(function_name, value)| (function_name.as_slice(), *value)), + FunctionRegistry::Dense(vec) => vec + .iter() + .find(|(funtion_name, _)| funtion_name == name) + .map(|(function_name, value)| (function_name.as_slice(), *value)), + } } /// Calculate memory size pub fn mem_size(&self) -> usize { - std::mem::size_of::().saturating_add(self.map.iter().fold( - 0, - |state: usize, (_, (name, value))| { - state.saturating_add( - std::mem::size_of_val(value).saturating_add( + let self_size = std::mem::size_of::(); + let content_size = + match &self { + FunctionRegistry::Sparse(map) => { + map.iter().fold(0, |state: usize, (_, (name, value))| { + state.saturating_add(std::mem::size_of_val(value).saturating_add( + std::mem::size_of_val(name).saturating_add(name.capacity()), + )) + }) + } + FunctionRegistry::Dense(vec) => vec.iter().fold(0, |acc: usize, (name, value)| { + acc.saturating_add(std::mem::size_of_val(value).saturating_add( std::mem::size_of_val(name).saturating_add(name.capacity()), - ), - ) - }, - )) + )) + }), + }; + + self_size.saturating_add(content_size) } } @@ -255,7 +325,7 @@ impl BuiltinProgram { pub fn new_mock() -> Self { Self { config: Some(Box::default()), - functions: FunctionRegistry::default(), + functions: FunctionRegistry::default_sparse(), } } @@ -350,6 +420,41 @@ macro_rules! declare_builtin_function { }; } +/// Tombstone function for when we call an invalid syscall (e.g. a syscall deactivated through a +/// feature gate +#[derive(Clone, PartialEq)] +pub struct SyscallTombstone {} +impl SyscallTombstone { + /// Tombstone function entrypoint + #[allow(clippy::arithmetic_side_effects)] + pub fn vm( + ctx: *mut EbpfVm, + _arg1: u64, + _arg2: u64, + _arg3: u64, + _arg4: u64, + _arg5: u64, + ) { + let vm = unsafe { + &mut *(ctx + .cast::() + .offset(-(get_runtime_environment_key() as isize)) + .cast::>()) + }; + let config = vm.loader.get_config(); + if config.enable_instruction_meter { + vm.context_object_pointer + .consume(vm.previous_instruction_meter - vm.due_insn_count); + } + vm.program_result = ProgramResult::Err(EbpfError::SyscallError(Box::new( + ElfError::InvalidDenseFunctionIndex, + ))); + if config.enable_instruction_meter { + vm.previous_instruction_meter = vm.context_object_pointer.get_remaining(); + } + } +} + #[cfg(test)] mod tests { use super::*; @@ -358,7 +463,7 @@ mod tests { #[test] fn test_builtin_program_eq() { let mut function_registry_a = - FunctionRegistry::>::default(); + FunctionRegistry::>::default_sparse(); function_registry_a .register_function_hashed(*b"log", syscalls::SyscallString::vm) .unwrap(); @@ -366,7 +471,7 @@ mod tests { .register_function_hashed(*b"log_64", syscalls::SyscallU64::vm) .unwrap(); let mut function_registry_b = - FunctionRegistry::>::default(); + FunctionRegistry::>::default_sparse(); function_registry_b .register_function_hashed(*b"log_64", syscalls::SyscallU64::vm) .unwrap(); @@ -374,7 +479,7 @@ mod tests { .register_function_hashed(*b"log", syscalls::SyscallString::vm) .unwrap(); let mut function_registry_c = - FunctionRegistry::>::default(); + FunctionRegistry::>::default_sparse(); function_registry_c .register_function_hashed(*b"log_64", syscalls::SyscallU64::vm) .unwrap(); diff --git a/src/vm.rs b/src/vm.rs index 7bff55c4..15df1e79 100644 --- a/src/vm.rs +++ b/src/vm.rs @@ -250,7 +250,7 @@ pub struct CallFrame { /// ]; /// /// let loader = std::sync::Arc::new(BuiltinProgram::new_mock()); -/// let function_registry = FunctionRegistry::default(); +/// let function_registry = FunctionRegistry::default_sparse(); /// let mut executable = Executable::::from_text_bytes(prog, loader.clone(), SBPFVersion::V2, function_registry).unwrap(); /// executable.verify::().unwrap(); /// let mut context_object = TestContextObject::new(1); diff --git a/tests/assembler.rs b/tests/assembler.rs index 66df864d..7493c179 100644 --- a/tests/assembler.rs +++ b/tests/assembler.rs @@ -19,7 +19,7 @@ fn asm(src: &str) -> Result, String> { } fn asm_with_config(src: &str, config: Config) -> Result, String> { - let loader = BuiltinProgram::new_loader(config, FunctionRegistry::default()); + let loader = BuiltinProgram::new_loader(config, FunctionRegistry::default_sparse()); let executable = assemble::(src, Arc::new(loader))?; let (_program_vm_addr, program) = executable.get_text_bytes(); Ok((0..program.len() / ebpf::INSN_SIZE) @@ -526,7 +526,7 @@ fn test_tcp_sack() { TCP_SACK_ASM, Arc::new(BuiltinProgram::new_loader( config, - FunctionRegistry::default(), + FunctionRegistry::default_sparse(), )), ) .unwrap(); diff --git a/tests/disassembler.rs b/tests/disassembler.rs index e77d274f..2f1fbea6 100644 --- a/tests/disassembler.rs +++ b/tests/disassembler.rs @@ -27,7 +27,7 @@ macro_rules! disasm { }}; ($src:expr, $config:expr) => {{ let src = $src; - let loader = BuiltinProgram::new_loader($config, FunctionRegistry::default()); + let loader = BuiltinProgram::new_loader($config, FunctionRegistry::default_sparse()); let executable = assemble::(src, Arc::new(loader)).unwrap(); let analysis = Analysis::from_executable(&executable).unwrap(); let mut reasm = Vec::new(); diff --git a/tests/execution.rs b/tests/execution.rs index cf63966b..ca9fc8d5 100644 --- a/tests/execution.rs +++ b/tests/execution.rs @@ -148,7 +148,7 @@ macro_rules! test_interpreter_and_jit_asm { { let mut config = $config; config.enable_instruction_tracing = true; - let mut function_registry = FunctionRegistry::>::default(); + let mut function_registry = FunctionRegistry::>::default_sparse(); $(test_interpreter_and_jit!(register, function_registry, $location => $syscall_function);)* let loader = Arc::new(BuiltinProgram::new_loader(config, function_registry)); let mut executable = assemble($source, loader).unwrap(); @@ -170,7 +170,7 @@ macro_rules! test_interpreter_and_jit_elf { file.read_to_end(&mut elf).unwrap(); #[allow(unused_mut)] { - let mut function_registry = FunctionRegistry::>::default(); + let mut function_registry = FunctionRegistry::>::default_sparse(); $(test_interpreter_and_jit!(register, function_registry, $location => $syscall_function);)* let loader = Arc::new(BuiltinProgram::new_loader($config, function_registry)); let mut executable = Executable::::from_elf(&elf, loader).unwrap(); @@ -810,7 +810,7 @@ fn test_pqr() { &prog, loader.clone(), SBPFVersion::V2, - FunctionRegistry::default(), + FunctionRegistry::default_sparse(), ) .unwrap(); test_interpreter_and_jit!( @@ -825,7 +825,7 @@ fn test_pqr() { &prog, loader.clone(), SBPFVersion::V2, - FunctionRegistry::default(), + FunctionRegistry::default_sparse(), ) .unwrap(); test_interpreter_and_jit!( @@ -859,7 +859,7 @@ fn test_err_divide_by_zero() { &prog, loader.clone(), SBPFVersion::V2, - FunctionRegistry::default(), + FunctionRegistry::default_sparse(), ) .unwrap(); test_interpreter_and_jit!( @@ -901,7 +901,7 @@ fn test_err_divide_overflow() { &prog, loader.clone(), SBPFVersion::V2, - FunctionRegistry::default(), + FunctionRegistry::default_sparse(), ) .unwrap(); test_interpreter_and_jit!( @@ -2303,7 +2303,7 @@ fn test_err_mem_access_out_of_bound() { &prog, loader.clone(), SBPFVersion::V2, - FunctionRegistry::default(), + FunctionRegistry::default_sparse(), ) .unwrap(); test_interpreter_and_jit!( @@ -2681,7 +2681,7 @@ declare_builtin_function!( #[allow(unused_mut)] if depth > 0 { let mut function_registry = - FunctionRegistry::>::default(); + FunctionRegistry::>::default_sparse(); function_registry .register_function_hashed(*b"nested_vm_syscall", SyscallNestedVm::vm) .unwrap(); @@ -3383,10 +3383,10 @@ fn execute_generated_program(prog: &[u8]) -> bool { enable_instruction_tracing: true, ..Config::default() }, - FunctionRegistry::default(), + FunctionRegistry::default_sparse(), )), SBPFVersion::V2, - FunctionRegistry::default(), + FunctionRegistry::default_sparse(), ); let mut executable = if let Ok(executable) = executable { executable @@ -4094,13 +4094,14 @@ fn test_invalid_exit_or_return() { enable_instruction_tracing: true, ..Config::default() }; - let function_registry = FunctionRegistry::>::default(); + let function_registry = + FunctionRegistry::>::default_sparse(); let loader = Arc::new(BuiltinProgram::new_loader(config, function_registry)); let mut executable = Executable::::from_text_bytes( prog, loader, sbpf_version, - FunctionRegistry::default(), + FunctionRegistry::default_sparse(), ) .unwrap(); diff --git a/tests/exercise_instructions.rs b/tests/exercise_instructions.rs index 659c5770..7a5772d1 100644 --- a/tests/exercise_instructions.rs +++ b/tests/exercise_instructions.rs @@ -122,7 +122,7 @@ macro_rules! test_interpreter_and_jit_asm { { let mut config = $config; config.enable_instruction_tracing = true; - let mut function_registry = FunctionRegistry::>::default(); + let mut function_registry = FunctionRegistry::>::default_sparse(); $(test_interpreter_and_jit!(register, function_registry, $location => $syscall_function);)* let loader = Arc::new(BuiltinProgram::new_loader(config, function_registry)); let mut executable = assemble($source, loader).unwrap(); diff --git a/tests/verifier.rs b/tests/verifier.rs index 24df55d1..7f0b609e 100644 --- a/tests/verifier.rs +++ b/tests/verifier.rs @@ -128,7 +128,7 @@ fn test_verifier_err_endian_size() { prog, Arc::new(BuiltinProgram::new_mock()), SBPFVersion::V2, - FunctionRegistry::default(), + FunctionRegistry::default_sparse(), ) .unwrap(); executable.verify::().unwrap(); @@ -147,7 +147,7 @@ fn test_verifier_err_incomplete_lddw() { prog, Arc::new(BuiltinProgram::new_mock()), SBPFVersion::V1, - FunctionRegistry::default(), + FunctionRegistry::default_sparse(), ) .unwrap(); executable.verify::().unwrap(); @@ -165,10 +165,10 @@ fn test_verifier_err_lddw_cannot_be_last() { enabled_sbpf_versions: SBPFVersion::V1..=highest_sbpf_version, ..Config::default() }, - FunctionRegistry::default(), + FunctionRegistry::default_sparse(), )), highest_sbpf_version, - FunctionRegistry::default(), + FunctionRegistry::default_sparse(), ) .unwrap(); executable.verify::().unwrap(); @@ -189,7 +189,7 @@ fn test_verifier_err_invalid_reg_dst() { enabled_sbpf_versions: SBPFVersion::V1..=highest_sbpf_version, ..Config::default() }, - FunctionRegistry::default(), + FunctionRegistry::default_sparse(), )), ) .unwrap(); @@ -212,7 +212,7 @@ fn test_verifier_err_invalid_reg_src() { enabled_sbpf_versions: SBPFVersion::V1..=highest_sbpf_version, ..Config::default() }, - FunctionRegistry::default(), + FunctionRegistry::default_sparse(), )), ) .unwrap(); @@ -233,7 +233,7 @@ fn test_verifier_resize_stack_ptr_success() { enable_stack_frame_gaps: false, ..Config::default() }, - FunctionRegistry::default(), + FunctionRegistry::default_sparse(), )), ) .unwrap(); @@ -282,7 +282,7 @@ fn test_verifier_err_callx_cannot_use_r10() { enabled_sbpf_versions: SBPFVersion::V1..=highest_sbpf_version, ..Config::default() }, - FunctionRegistry::default(), + FunctionRegistry::default_sparse(), )), ) .unwrap(); @@ -341,7 +341,7 @@ fn test_verifier_err_unknown_opcode() { prog, Arc::new(BuiltinProgram::new_mock()), SBPFVersion::V2, - FunctionRegistry::default(), + FunctionRegistry::default_sparse(), ) .unwrap(); executable.verify::().unwrap(); @@ -358,7 +358,7 @@ fn test_verifier_unknown_sycall() { prog, Arc::new(BuiltinProgram::new_mock()), SBPFVersion::V2, - FunctionRegistry::default(), + FunctionRegistry::default_sparse(), ) .unwrap(); executable.verify::().unwrap(); @@ -370,7 +370,8 @@ fn test_verifier_known_syscall() { 0x85, 0x00, 0x00, 0x00, 0xfe, 0xc3, 0xf5, 0x6b, // call 0x6bf5c3fe 0x9d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // return ]; - let mut function_registry = FunctionRegistry::>::default(); + let mut function_registry = + FunctionRegistry::>::default_sparse(); function_registry .register_function(0x6bf5c3fe, b"my_syscall", syscalls::SyscallString::vm) .unwrap(); @@ -381,7 +382,7 @@ fn test_verifier_known_syscall() { function_registry, )), SBPFVersion::V2, - FunctionRegistry::default(), + FunctionRegistry::default_sparse(), ) .unwrap(); executable.verify::().unwrap(); @@ -457,7 +458,7 @@ fn test_sdiv_disabled() { enabled_sbpf_versions: SBPFVersion::V1..=highest_sbpf_version, ..Config::default() }, - FunctionRegistry::default(), + FunctionRegistry::default_sparse(), )), ) .unwrap(); @@ -484,7 +485,7 @@ fn return_instr() { prog, Arc::new(BuiltinProgram::new_mock()), sbpf_version, - FunctionRegistry::default(), + FunctionRegistry::default_sparse(), ) .unwrap(); let result = executable.verify::(); @@ -506,7 +507,7 @@ fn return_in_v2() { enabled_sbpf_versions: SBPFVersion::V2..=SBPFVersion::V2, ..Config::default() }, - FunctionRegistry::default(), + FunctionRegistry::default_sparse(), )), ) .unwrap(); @@ -524,7 +525,7 @@ fn function_without_return() { enabled_sbpf_versions: SBPFVersion::V2..=SBPFVersion::V2, ..Config::default() }, - FunctionRegistry::default(), + FunctionRegistry::default_sparse(), )), ) .unwrap(); From 1c847bb5908b4a7b8e8d571d004b57ffdb4497c0 Mon Sep 17 00:00:00 2001 From: Lucas Steuernagel Date: Thu, 17 Oct 2024 14:08:32 -0300 Subject: [PATCH 2/2] Rename new_sparse to default --- benches/elf_loader.rs | 3 +- benches/vm_execution.rs | 2 +- cli/src/main.rs | 2 +- examples/disassemble.rs | 2 +- examples/to_json.rs | 2 +- fuzz/fuzz_targets/dumb.rs | 6 ++-- fuzz/fuzz_targets/smart.rs | 6 ++-- fuzz/fuzz_targets/smart_jit_diff.rs | 6 ++-- fuzz/fuzz_targets/smarter_jit_diff.rs | 6 ++-- fuzz/fuzz_targets/verify_semantic_aware.rs | 4 +-- src/assembler.rs | 2 +- src/elf.rs | 6 ++-- src/jit.rs | 4 +-- src/program.rs | 19 +++++-------- src/vm.rs | 2 +- tests/assembler.rs | 4 +-- tests/disassembler.rs | 2 +- tests/execution.rs | 25 ++++++++-------- tests/exercise_instructions.rs | 2 +- tests/verifier.rs | 33 +++++++++++----------- 20 files changed, 65 insertions(+), 73 deletions(-) diff --git a/benches/elf_loader.rs b/benches/elf_loader.rs index 8dc72ab4..323be403 100644 --- a/benches/elf_loader.rs +++ b/benches/elf_loader.rs @@ -20,8 +20,7 @@ use std::{fs::File, io::Read, sync::Arc}; use test::Bencher; fn loader() -> Arc> { - let mut function_registry = - FunctionRegistry::>::default_sparse(); + let mut function_registry = FunctionRegistry::>::default(); function_registry .register_function_hashed(*b"log", syscalls::SyscallString::vm) .unwrap(); diff --git a/benches/vm_execution.rs b/benches/vm_execution.rs index e59057e3..4404c927 100644 --- a/benches/vm_execution.rs +++ b/benches/vm_execution.rs @@ -87,7 +87,7 @@ fn bench_jit_vs_interpreter( assembly, Arc::new(BuiltinProgram::new_loader( config, - FunctionRegistry::default_sparse(), + FunctionRegistry::default(), )), ) .unwrap(); diff --git a/cli/src/main.rs b/cli/src/main.rs index daa3a9a7..cded744a 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -100,7 +100,7 @@ fn main() { enable_symbol_and_section_labels: true, ..Config::default() }, - FunctionRegistry::default_dense(), + FunctionRegistry::default(), )); #[allow(unused_mut)] let mut executable = match matches.value_of("assembler") { diff --git a/examples/disassemble.rs b/examples/disassemble.rs index 53bf80e8..454fec2e 100644 --- a/examples/disassemble.rs +++ b/examples/disassemble.rs @@ -36,7 +36,7 @@ fn main() { program, loader, SBPFVersion::V2, - FunctionRegistry::default_sparse(), + FunctionRegistry::default(), ) .unwrap(); let analysis = Analysis::from_executable(&executable).unwrap(); diff --git a/examples/to_json.rs b/examples/to_json.rs index 18cf4e5e..0e2950aa 100644 --- a/examples/to_json.rs +++ b/examples/to_json.rs @@ -32,7 +32,7 @@ fn to_json(program: &[u8]) -> String { program, Arc::new(BuiltinProgram::new_mock()), SBPFVersion::V2, - FunctionRegistry::default_sparse(), + FunctionRegistry::default(), ) .unwrap(); let analysis = Analysis::from_executable(&executable).unwrap(); diff --git a/fuzz/fuzz_targets/dumb.rs b/fuzz/fuzz_targets/dumb.rs index fc2edf2b..c1b1743d 100644 --- a/fuzz/fuzz_targets/dumb.rs +++ b/fuzz/fuzz_targets/dumb.rs @@ -28,8 +28,8 @@ struct DumbFuzzData { fuzz_target!(|data: DumbFuzzData| { let prog = data.prog; let config = data.template.into(); - let function_registry = FunctionRegistry::default_sparse(); - let syscall_registry = FunctionRegistry::>::default_sparse(); + let function_registry = FunctionRegistry::default(); + let syscall_registry = FunctionRegistry::>::default(); if RequisiteVerifier::verify(&prog, &config, &SBPFVersion::V2, &function_registry, &syscall_registry).is_err() { // verify please @@ -40,7 +40,7 @@ fuzz_target!(|data: DumbFuzzData| { &prog, std::sync::Arc::new(BuiltinProgram::new_loader( config, - FunctionRegistry::default_sparse(), + FunctionRegistry::default(), )), SBPFVersion::V2, function_registry, diff --git a/fuzz/fuzz_targets/smart.rs b/fuzz/fuzz_targets/smart.rs index a32f4cba..0ecb535b 100644 --- a/fuzz/fuzz_targets/smart.rs +++ b/fuzz/fuzz_targets/smart.rs @@ -32,8 +32,8 @@ struct FuzzData { fuzz_target!(|data: FuzzData| { let prog = make_program(&data.prog, data.arch); let config = data.template.into(); - let function_registry = FunctionRegistry::default_sparse(); - let syscall_registry = FunctionRegistry::>::default_sparse(); + let function_registry = FunctionRegistry::default(); + let syscall_registry = FunctionRegistry::>::default(); if RequisiteVerifier::verify( prog.into_bytes(), @@ -52,7 +52,7 @@ fuzz_target!(|data: FuzzData| { prog.into_bytes(), std::sync::Arc::new(BuiltinProgram::new_loader( config, - FunctionRegistry::default_sparse(), + FunctionRegistry::default(), )), SBPFVersion::V2, function_registry, diff --git a/fuzz/fuzz_targets/smart_jit_diff.rs b/fuzz/fuzz_targets/smart_jit_diff.rs index 12f1b4cc..87203ca2 100644 --- a/fuzz/fuzz_targets/smart_jit_diff.rs +++ b/fuzz/fuzz_targets/smart_jit_diff.rs @@ -39,8 +39,8 @@ fuzz_target!(|data: FuzzData| { .set_imm(data.exit_imm) .push(); let config = data.template.into(); - let function_registry = FunctionRegistry::default_sparse(); - let syscall_registry = FunctionRegistry::>::default_sparse(); + let function_registry = FunctionRegistry::default(); + let syscall_registry = FunctionRegistry::>::default(); if RequisiteVerifier::verify( prog.into_bytes(), @@ -60,7 +60,7 @@ fuzz_target!(|data: FuzzData| { prog.into_bytes(), std::sync::Arc::new(BuiltinProgram::new_loader( config, - FunctionRegistry::default_sparse(), + FunctionRegistry::default(), )), SBPFVersion::V2, function_registry, diff --git a/fuzz/fuzz_targets/smarter_jit_diff.rs b/fuzz/fuzz_targets/smarter_jit_diff.rs index 739d7afe..6d77df41 100644 --- a/fuzz/fuzz_targets/smarter_jit_diff.rs +++ b/fuzz/fuzz_targets/smarter_jit_diff.rs @@ -29,8 +29,8 @@ struct FuzzData { fuzz_target!(|data: FuzzData| { let prog = make_program(&data.prog); let config = data.template.into(); - let function_registry = FunctionRegistry::default_sparse(); - let syscall_registry = FunctionRegistry::>::default_sparse(); + let function_registry = FunctionRegistry::default(); + let syscall_registry = FunctionRegistry::>::default(); if RequisiteVerifier::verify( prog.into_bytes(), @@ -50,7 +50,7 @@ fuzz_target!(|data: FuzzData| { prog.into_bytes(), std::sync::Arc::new(BuiltinProgram::new_loader( config, - FunctionRegistry::default_sparse(), + FunctionRegistry::default(), )), SBPFVersion::V2, function_registry, diff --git a/fuzz/fuzz_targets/verify_semantic_aware.rs b/fuzz/fuzz_targets/verify_semantic_aware.rs index 918b5783..0c2cc09f 100644 --- a/fuzz/fuzz_targets/verify_semantic_aware.rs +++ b/fuzz/fuzz_targets/verify_semantic_aware.rs @@ -24,8 +24,8 @@ struct FuzzData { fuzz_target!(|data: FuzzData| { let prog = make_program(&data.prog); let config = data.template.into(); - let function_registry = FunctionRegistry::default_sparse(); - let syscall_registry = FunctionRegistry::>::default_sparse(); + let function_registry = FunctionRegistry::default(); + let syscall_registry = FunctionRegistry::>::default(); RequisiteVerifier::verify( prog.into_bytes(), diff --git a/src/assembler.rs b/src/assembler.rs index 28e8f6b8..ffdb3508 100644 --- a/src/assembler.rs +++ b/src/assembler.rs @@ -333,7 +333,7 @@ pub fn assemble( let statements = parse(src)?; let instruction_map = make_instruction_map(sbpf_version); let mut insn_ptr = 0; - let mut function_registry = FunctionRegistry::default_sparse(); + let mut function_registry = FunctionRegistry::default(); let mut labels = HashMap::new(); labels.insert("entrypoint", 0); for statement in statements.iter() { diff --git a/src/elf.rs b/src/elf.rs index 79da05c3..072c8d5c 100644 --- a/src/elf.rs +++ b/src/elf.rs @@ -422,7 +422,7 @@ impl Executable { } // relocate symbols - let mut function_registry = FunctionRegistry::default_sparse(); + let mut function_registry = FunctionRegistry::default(); Self::relocate( &mut function_registry, &loader, @@ -1167,7 +1167,7 @@ mod test { fn loader() -> Arc> { let mut function_registry = - FunctionRegistry::>::default_sparse(); + FunctionRegistry::>::default(); function_registry .register_function_hashed(*b"log", syscalls::SyscallString::vm) .unwrap(); @@ -1931,7 +1931,7 @@ mod test { reject_broken_elfs: true, ..Config::default() }, - FunctionRegistry::default_sparse(), + FunctionRegistry::default(), ); let elf_bytes = std::fs::read("tests/elfs/syscall_reloc_64_32_sbpfv1.so") .expect("failed to read elf file"); diff --git a/src/jit.rs b/src/jit.rs index 08b15078..1f48034e 100644 --- a/src/jit.rs +++ b/src/jit.rs @@ -1744,12 +1744,12 @@ mod tests { fn create_mockup_executable(config: Config, program: &[u8]) -> Executable { let sbpf_version = *config.enabled_sbpf_versions.end(); let mut function_registry = - FunctionRegistry::>::default_sparse(); + FunctionRegistry::>::default(); function_registry .register_function_hashed(*b"gather_bytes", syscalls::SyscallGatherBytes::vm) .unwrap(); let loader = BuiltinProgram::new_loader(config, function_registry); - let mut function_registry = FunctionRegistry::default_sparse(); + let mut function_registry = FunctionRegistry::default(); function_registry .register_function(8, *b"function_foo", 8) .unwrap(); diff --git a/src/program.rs b/src/program.rs index f2230667..8fe58d1c 100644 --- a/src/program.rs +++ b/src/program.rs @@ -93,16 +93,11 @@ pub enum FunctionRegistry { Dense(Vec<(Vec, T)>), } -impl FunctionRegistry { - /// Create an empty sparse function registry - pub fn default_sparse() -> Self { +impl Default for FunctionRegistry { + /// Default for FunctionRegistry returns a sparse registry + fn default() -> Self { FunctionRegistry::Sparse(BTreeMap::new()) } - - /// Create and empty dense function registry - pub fn default_dense() -> Self { - FunctionRegistry::Dense(Vec::new()) - } } impl FunctionRegistry> { @@ -325,7 +320,7 @@ impl BuiltinProgram { pub fn new_mock() -> Self { Self { config: Some(Box::default()), - functions: FunctionRegistry::default_sparse(), + functions: FunctionRegistry::default(), } } @@ -463,7 +458,7 @@ mod tests { #[test] fn test_builtin_program_eq() { let mut function_registry_a = - FunctionRegistry::>::default_sparse(); + FunctionRegistry::>::default(); function_registry_a .register_function_hashed(*b"log", syscalls::SyscallString::vm) .unwrap(); @@ -471,7 +466,7 @@ mod tests { .register_function_hashed(*b"log_64", syscalls::SyscallU64::vm) .unwrap(); let mut function_registry_b = - FunctionRegistry::>::default_sparse(); + FunctionRegistry::>::default(); function_registry_b .register_function_hashed(*b"log_64", syscalls::SyscallU64::vm) .unwrap(); @@ -479,7 +474,7 @@ mod tests { .register_function_hashed(*b"log", syscalls::SyscallString::vm) .unwrap(); let mut function_registry_c = - FunctionRegistry::>::default_sparse(); + FunctionRegistry::>::default(); function_registry_c .register_function_hashed(*b"log_64", syscalls::SyscallU64::vm) .unwrap(); diff --git a/src/vm.rs b/src/vm.rs index 15df1e79..7bff55c4 100644 --- a/src/vm.rs +++ b/src/vm.rs @@ -250,7 +250,7 @@ pub struct CallFrame { /// ]; /// /// let loader = std::sync::Arc::new(BuiltinProgram::new_mock()); -/// let function_registry = FunctionRegistry::default_sparse(); +/// let function_registry = FunctionRegistry::default(); /// let mut executable = Executable::::from_text_bytes(prog, loader.clone(), SBPFVersion::V2, function_registry).unwrap(); /// executable.verify::().unwrap(); /// let mut context_object = TestContextObject::new(1); diff --git a/tests/assembler.rs b/tests/assembler.rs index 7493c179..66df864d 100644 --- a/tests/assembler.rs +++ b/tests/assembler.rs @@ -19,7 +19,7 @@ fn asm(src: &str) -> Result, String> { } fn asm_with_config(src: &str, config: Config) -> Result, String> { - let loader = BuiltinProgram::new_loader(config, FunctionRegistry::default_sparse()); + let loader = BuiltinProgram::new_loader(config, FunctionRegistry::default()); let executable = assemble::(src, Arc::new(loader))?; let (_program_vm_addr, program) = executable.get_text_bytes(); Ok((0..program.len() / ebpf::INSN_SIZE) @@ -526,7 +526,7 @@ fn test_tcp_sack() { TCP_SACK_ASM, Arc::new(BuiltinProgram::new_loader( config, - FunctionRegistry::default_sparse(), + FunctionRegistry::default(), )), ) .unwrap(); diff --git a/tests/disassembler.rs b/tests/disassembler.rs index 2f1fbea6..e77d274f 100644 --- a/tests/disassembler.rs +++ b/tests/disassembler.rs @@ -27,7 +27,7 @@ macro_rules! disasm { }}; ($src:expr, $config:expr) => {{ let src = $src; - let loader = BuiltinProgram::new_loader($config, FunctionRegistry::default_sparse()); + let loader = BuiltinProgram::new_loader($config, FunctionRegistry::default()); let executable = assemble::(src, Arc::new(loader)).unwrap(); let analysis = Analysis::from_executable(&executable).unwrap(); let mut reasm = Vec::new(); diff --git a/tests/execution.rs b/tests/execution.rs index ca9fc8d5..cf63966b 100644 --- a/tests/execution.rs +++ b/tests/execution.rs @@ -148,7 +148,7 @@ macro_rules! test_interpreter_and_jit_asm { { let mut config = $config; config.enable_instruction_tracing = true; - let mut function_registry = FunctionRegistry::>::default_sparse(); + let mut function_registry = FunctionRegistry::>::default(); $(test_interpreter_and_jit!(register, function_registry, $location => $syscall_function);)* let loader = Arc::new(BuiltinProgram::new_loader(config, function_registry)); let mut executable = assemble($source, loader).unwrap(); @@ -170,7 +170,7 @@ macro_rules! test_interpreter_and_jit_elf { file.read_to_end(&mut elf).unwrap(); #[allow(unused_mut)] { - let mut function_registry = FunctionRegistry::>::default_sparse(); + let mut function_registry = FunctionRegistry::>::default(); $(test_interpreter_and_jit!(register, function_registry, $location => $syscall_function);)* let loader = Arc::new(BuiltinProgram::new_loader($config, function_registry)); let mut executable = Executable::::from_elf(&elf, loader).unwrap(); @@ -810,7 +810,7 @@ fn test_pqr() { &prog, loader.clone(), SBPFVersion::V2, - FunctionRegistry::default_sparse(), + FunctionRegistry::default(), ) .unwrap(); test_interpreter_and_jit!( @@ -825,7 +825,7 @@ fn test_pqr() { &prog, loader.clone(), SBPFVersion::V2, - FunctionRegistry::default_sparse(), + FunctionRegistry::default(), ) .unwrap(); test_interpreter_and_jit!( @@ -859,7 +859,7 @@ fn test_err_divide_by_zero() { &prog, loader.clone(), SBPFVersion::V2, - FunctionRegistry::default_sparse(), + FunctionRegistry::default(), ) .unwrap(); test_interpreter_and_jit!( @@ -901,7 +901,7 @@ fn test_err_divide_overflow() { &prog, loader.clone(), SBPFVersion::V2, - FunctionRegistry::default_sparse(), + FunctionRegistry::default(), ) .unwrap(); test_interpreter_and_jit!( @@ -2303,7 +2303,7 @@ fn test_err_mem_access_out_of_bound() { &prog, loader.clone(), SBPFVersion::V2, - FunctionRegistry::default_sparse(), + FunctionRegistry::default(), ) .unwrap(); test_interpreter_and_jit!( @@ -2681,7 +2681,7 @@ declare_builtin_function!( #[allow(unused_mut)] if depth > 0 { let mut function_registry = - FunctionRegistry::>::default_sparse(); + FunctionRegistry::>::default(); function_registry .register_function_hashed(*b"nested_vm_syscall", SyscallNestedVm::vm) .unwrap(); @@ -3383,10 +3383,10 @@ fn execute_generated_program(prog: &[u8]) -> bool { enable_instruction_tracing: true, ..Config::default() }, - FunctionRegistry::default_sparse(), + FunctionRegistry::default(), )), SBPFVersion::V2, - FunctionRegistry::default_sparse(), + FunctionRegistry::default(), ); let mut executable = if let Ok(executable) = executable { executable @@ -4094,14 +4094,13 @@ fn test_invalid_exit_or_return() { enable_instruction_tracing: true, ..Config::default() }; - let function_registry = - FunctionRegistry::>::default_sparse(); + let function_registry = FunctionRegistry::>::default(); let loader = Arc::new(BuiltinProgram::new_loader(config, function_registry)); let mut executable = Executable::::from_text_bytes( prog, loader, sbpf_version, - FunctionRegistry::default_sparse(), + FunctionRegistry::default(), ) .unwrap(); diff --git a/tests/exercise_instructions.rs b/tests/exercise_instructions.rs index 7a5772d1..659c5770 100644 --- a/tests/exercise_instructions.rs +++ b/tests/exercise_instructions.rs @@ -122,7 +122,7 @@ macro_rules! test_interpreter_and_jit_asm { { let mut config = $config; config.enable_instruction_tracing = true; - let mut function_registry = FunctionRegistry::>::default_sparse(); + let mut function_registry = FunctionRegistry::>::default(); $(test_interpreter_and_jit!(register, function_registry, $location => $syscall_function);)* let loader = Arc::new(BuiltinProgram::new_loader(config, function_registry)); let mut executable = assemble($source, loader).unwrap(); diff --git a/tests/verifier.rs b/tests/verifier.rs index 7f0b609e..24df55d1 100644 --- a/tests/verifier.rs +++ b/tests/verifier.rs @@ -128,7 +128,7 @@ fn test_verifier_err_endian_size() { prog, Arc::new(BuiltinProgram::new_mock()), SBPFVersion::V2, - FunctionRegistry::default_sparse(), + FunctionRegistry::default(), ) .unwrap(); executable.verify::().unwrap(); @@ -147,7 +147,7 @@ fn test_verifier_err_incomplete_lddw() { prog, Arc::new(BuiltinProgram::new_mock()), SBPFVersion::V1, - FunctionRegistry::default_sparse(), + FunctionRegistry::default(), ) .unwrap(); executable.verify::().unwrap(); @@ -165,10 +165,10 @@ fn test_verifier_err_lddw_cannot_be_last() { enabled_sbpf_versions: SBPFVersion::V1..=highest_sbpf_version, ..Config::default() }, - FunctionRegistry::default_sparse(), + FunctionRegistry::default(), )), highest_sbpf_version, - FunctionRegistry::default_sparse(), + FunctionRegistry::default(), ) .unwrap(); executable.verify::().unwrap(); @@ -189,7 +189,7 @@ fn test_verifier_err_invalid_reg_dst() { enabled_sbpf_versions: SBPFVersion::V1..=highest_sbpf_version, ..Config::default() }, - FunctionRegistry::default_sparse(), + FunctionRegistry::default(), )), ) .unwrap(); @@ -212,7 +212,7 @@ fn test_verifier_err_invalid_reg_src() { enabled_sbpf_versions: SBPFVersion::V1..=highest_sbpf_version, ..Config::default() }, - FunctionRegistry::default_sparse(), + FunctionRegistry::default(), )), ) .unwrap(); @@ -233,7 +233,7 @@ fn test_verifier_resize_stack_ptr_success() { enable_stack_frame_gaps: false, ..Config::default() }, - FunctionRegistry::default_sparse(), + FunctionRegistry::default(), )), ) .unwrap(); @@ -282,7 +282,7 @@ fn test_verifier_err_callx_cannot_use_r10() { enabled_sbpf_versions: SBPFVersion::V1..=highest_sbpf_version, ..Config::default() }, - FunctionRegistry::default_sparse(), + FunctionRegistry::default(), )), ) .unwrap(); @@ -341,7 +341,7 @@ fn test_verifier_err_unknown_opcode() { prog, Arc::new(BuiltinProgram::new_mock()), SBPFVersion::V2, - FunctionRegistry::default_sparse(), + FunctionRegistry::default(), ) .unwrap(); executable.verify::().unwrap(); @@ -358,7 +358,7 @@ fn test_verifier_unknown_sycall() { prog, Arc::new(BuiltinProgram::new_mock()), SBPFVersion::V2, - FunctionRegistry::default_sparse(), + FunctionRegistry::default(), ) .unwrap(); executable.verify::().unwrap(); @@ -370,8 +370,7 @@ fn test_verifier_known_syscall() { 0x85, 0x00, 0x00, 0x00, 0xfe, 0xc3, 0xf5, 0x6b, // call 0x6bf5c3fe 0x9d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // return ]; - let mut function_registry = - FunctionRegistry::>::default_sparse(); + let mut function_registry = FunctionRegistry::>::default(); function_registry .register_function(0x6bf5c3fe, b"my_syscall", syscalls::SyscallString::vm) .unwrap(); @@ -382,7 +381,7 @@ fn test_verifier_known_syscall() { function_registry, )), SBPFVersion::V2, - FunctionRegistry::default_sparse(), + FunctionRegistry::default(), ) .unwrap(); executable.verify::().unwrap(); @@ -458,7 +457,7 @@ fn test_sdiv_disabled() { enabled_sbpf_versions: SBPFVersion::V1..=highest_sbpf_version, ..Config::default() }, - FunctionRegistry::default_sparse(), + FunctionRegistry::default(), )), ) .unwrap(); @@ -485,7 +484,7 @@ fn return_instr() { prog, Arc::new(BuiltinProgram::new_mock()), sbpf_version, - FunctionRegistry::default_sparse(), + FunctionRegistry::default(), ) .unwrap(); let result = executable.verify::(); @@ -507,7 +506,7 @@ fn return_in_v2() { enabled_sbpf_versions: SBPFVersion::V2..=SBPFVersion::V2, ..Config::default() }, - FunctionRegistry::default_sparse(), + FunctionRegistry::default(), )), ) .unwrap(); @@ -525,7 +524,7 @@ fn function_without_return() { enabled_sbpf_versions: SBPFVersion::V2..=SBPFVersion::V2, ..Config::default() }, - FunctionRegistry::default_sparse(), + FunctionRegistry::default(), )), ) .unwrap();