Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor - Make FunctionRegistry accept dense indexes #617

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion benches/elf_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ use std::{fs::File, io::Read, sync::Arc};
use test::Bencher;

fn loader() -> Arc<BuiltinProgram<TestContextObject>> {
let mut function_registry = FunctionRegistry::<BuiltinFunction<TestContextObject>>::default();
let mut function_registry =
FunctionRegistry::<BuiltinFunction<TestContextObject>>::default_sparse();
function_registry
.register_function_hashed(*b"log", syscalls::SyscallString::vm)
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion benches/vm_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ fn bench_jit_vs_interpreter(
assembly,
Arc::new(BuiltinProgram::new_loader(
config,
FunctionRegistry::default(),
FunctionRegistry::default_sparse(),
)),
)
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
2 changes: 1 addition & 1 deletion examples/disassemble.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn main() {
program,
loader,
SBPFVersion::V2,
FunctionRegistry::default(),
FunctionRegistry::default_sparse(),
)
.unwrap();
let analysis = Analysis::from_executable(&executable).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion examples/to_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions fuzz/fuzz_targets/dumb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<BuiltinFunction<TestContextObject>>::default();
let function_registry = FunctionRegistry::default_sparse();
let syscall_registry = FunctionRegistry::<BuiltinFunction<TestContextObject>>::default_sparse();

if RequisiteVerifier::verify(&prog, &config, &SBPFVersion::V2, &function_registry, &syscall_registry).is_err() {
// verify please
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions fuzz/fuzz_targets/smart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<BuiltinFunction<TestContextObject>>::default();
let function_registry = FunctionRegistry::default_sparse();
let syscall_registry = FunctionRegistry::<BuiltinFunction<TestContextObject>>::default_sparse();

if RequisiteVerifier::verify(
prog.into_bytes(),
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions fuzz/fuzz_targets/smart_jit_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<BuiltinFunction<TestContextObject>>::default();
let function_registry = FunctionRegistry::default_sparse();
let syscall_registry = FunctionRegistry::<BuiltinFunction<TestContextObject>>::default_sparse();

if RequisiteVerifier::verify(
prog.into_bytes(),
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions fuzz/fuzz_targets/smarter_jit_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<BuiltinFunction<TestContextObject>>::default();
let function_registry = FunctionRegistry::default_sparse();
let syscall_registry = FunctionRegistry::<BuiltinFunction<TestContextObject>>::default_sparse();

if RequisiteVerifier::verify(
prog.into_bytes(),
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions fuzz/fuzz_targets/verify_semantic_aware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<BuiltinFunction<TestContextObject>>::default();
let function_registry = FunctionRegistry::default_sparse();
let syscall_registry = FunctionRegistry::<BuiltinFunction<TestContextObject>>::default_sparse();

RequisiteVerifier::verify(
prog.into_bytes(),
Expand Down
2 changes: 1 addition & 1 deletion src/assembler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ pub fn assemble<C: ContextObject>(
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() {
Expand Down
9 changes: 6 additions & 3 deletions src/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ElfParserError> for ElfError {
Expand Down Expand Up @@ -419,7 +422,7 @@ impl<C: ContextObject> Executable<C> {
}

// relocate symbols
let mut function_registry = FunctionRegistry::default();
let mut function_registry = FunctionRegistry::default_sparse();
Self::relocate(
&mut function_registry,
&loader,
Expand Down Expand Up @@ -1164,7 +1167,7 @@ mod test {

fn loader() -> Arc<BuiltinProgram<TestContextObject>> {
let mut function_registry =
FunctionRegistry::<BuiltinFunction<TestContextObject>>::default();
FunctionRegistry::<BuiltinFunction<TestContextObject>>::default_sparse();
function_registry
.register_function_hashed(*b"log", syscalls::SyscallString::vm)
.unwrap();
Expand Down Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions src/jit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1744,12 +1744,12 @@ mod tests {
fn create_mockup_executable(config: Config, program: &[u8]) -> Executable<TestContextObject> {
let sbpf_version = *config.enabled_sbpf_versions.end();
let mut function_registry =
FunctionRegistry::<BuiltinFunction<TestContextObject>>::default();
FunctionRegistry::<BuiltinFunction<TestContextObject>>::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();
Expand Down
Loading