Skip to content

Commit

Permalink
Moves SBPFVersion, FunctionRegistry, BuiltinFunction and BuiltinProgr…
Browse files Browse the repository at this point in the history
…am into a new file
  • Loading branch information
Lichtso committed Sep 28, 2023
1 parent 42c5e90 commit 193bba0
Show file tree
Hide file tree
Showing 26 changed files with 406 additions and 355 deletions.
5 changes: 3 additions & 2 deletions benches/elf_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ extern crate test;
extern crate test_utils;

use solana_rbpf::{
elf::{Executable, FunctionRegistry},
elf::Executable,
program::{BuiltinFunction, BuiltinProgram, FunctionRegistry},
syscalls,
vm::{BuiltinFunction, BuiltinProgram, Config, TestContextObject},
vm::{Config, TestContextObject},
};
use std::{fs::File, io::Read, sync::Arc};
use test::Bencher;
Expand Down
4 changes: 1 addition & 3 deletions benches/jit_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ extern crate solana_rbpf;
extern crate test;

use solana_rbpf::{
elf::Executable,
verifier::RequisiteVerifier,
vm::{BuiltinProgram, TestContextObject},
elf::Executable, program::BuiltinProgram, verifier::RequisiteVerifier, vm::TestContextObject,
};
use std::{fs::File, io::Read, sync::Arc};
use test::Bencher;
Expand Down
2 changes: 1 addition & 1 deletion benches/memory_mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ extern crate test;

use rand::{rngs::SmallRng, Rng, SeedableRng};
use solana_rbpf::{
elf::SBPFVersion,
memory_region::{
AccessType, AlignedMemoryMapping, MemoryRegion, MemoryState, UnalignedMemoryMapping,
},
program::SBPFVersion,
vm::Config,
};
use test::Bencher;
Expand Down
5 changes: 3 additions & 2 deletions benches/vm_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ extern crate test;

use solana_rbpf::{
ebpf,
elf::{Executable, FunctionRegistry},
elf::Executable,
memory_region::MemoryRegion,
program::{BuiltinProgram, FunctionRegistry},
verifier::RequisiteVerifier,
vm::{BuiltinProgram, Config, TestContextObject},
vm::{Config, TestContextObject},
};
use std::{fs::File, io::Read, sync::Arc};
use test::Bencher;
Expand Down
5 changes: 3 additions & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ use solana_rbpf::{
aligned_memory::AlignedMemory,
assembler::assemble,
ebpf,
elf::{Executable, FunctionRegistry},
elf::Executable,
memory_region::{MemoryMapping, MemoryRegion},
program::{BuiltinProgram, FunctionRegistry},
static_analysis::Analysis,
verifier::RequisiteVerifier,
vm::{BuiltinProgram, Config, DynamicAnalysis, EbpfVm, TestContextObject},
vm::{Config, DynamicAnalysis, EbpfVm, TestContextObject},
};
use std::{fs::File, io::Read, path::Path, sync::Arc};

Expand Down
5 changes: 3 additions & 2 deletions examples/disassemble.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

extern crate solana_rbpf;
use solana_rbpf::{
elf::{Executable, FunctionRegistry, SBPFVersion},
elf::Executable,
program::{BuiltinProgram, FunctionRegistry, SBPFVersion},
static_analysis::Analysis,
vm::{BuiltinProgram, TestContextObject},
vm::TestContextObject,
};
use std::sync::Arc;

Expand Down
5 changes: 3 additions & 2 deletions examples/to_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ use std::path::PathBuf;

extern crate solana_rbpf;
use solana_rbpf::{
elf::{Executable, FunctionRegistry, SBPFVersion},
elf::Executable,
program::{BuiltinProgram, FunctionRegistry, SBPFVersion},
static_analysis::Analysis,
vm::{BuiltinProgram, TestContextObject},
vm::TestContextObject,
};
use std::sync::Arc;
// Turn a program into a JSON string.
Expand Down
10 changes: 7 additions & 3 deletions fuzz/fuzz_targets/dumb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ use libfuzzer_sys::fuzz_target;

use solana_rbpf::{
ebpf,
elf::{Executable, FunctionRegistry, SBPFVersion},
elf::Executable,
memory_region::MemoryRegion,
program::{BuiltinProgram, FunctionRegistry, SBPFVersion},
verifier::{RequisiteVerifier, Verifier},
vm::{BuiltinProgram, TestContextObject},
vm::TestContextObject,
};
use test_utils::create_vm;

Expand All @@ -35,7 +36,10 @@ fuzz_target!(|data: DumbFuzzData| {
let mut mem = data.mem;
let executable = Executable::<TestContextObject>::from_text_bytes(
&prog,
std::sync::Arc::new(BuiltinProgram::new_loader(config, FunctionRegistry::default())),
std::sync::Arc::new(BuiltinProgram::new_loader(
config,
FunctionRegistry::default(),
)),
SBPFVersion::V2,
function_registry,
)
Expand Down
19 changes: 15 additions & 4 deletions fuzz/fuzz_targets/smart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ use libfuzzer_sys::fuzz_target;
use grammar_aware::*;
use solana_rbpf::{
ebpf,
elf::{Executable, FunctionRegistry, SBPFVersion},
elf::Executable,
insn_builder::{Arch, IntoBytes},
memory_region::MemoryRegion,
program::{BuiltinProgram, FunctionRegistry, SBPFVersion},
verifier::{RequisiteVerifier, Verifier},
vm::{BuiltinProgram, TestContextObject},
vm::TestContextObject,
};
use test_utils::create_vm;

Expand All @@ -32,14 +33,24 @@ fuzz_target!(|data: FuzzData| {
let prog = make_program(&data.prog, data.arch);
let config = data.template.into();
let function_registry = FunctionRegistry::default();
if RequisiteVerifier::verify(prog.into_bytes(), &config, &SBPFVersion::V2, &function_registry).is_err() {
if RequisiteVerifier::verify(
prog.into_bytes(),
&config,
&SBPFVersion::V2,
&function_registry,
)
.is_err()
{
// verify please
return;
}
let mut mem = data.mem;
let executable = Executable::<TestContextObject>::from_text_bytes(
prog.into_bytes(),
std::sync::Arc::new(BuiltinProgram::new_loader(config, FunctionRegistry::default())),
std::sync::Arc::new(BuiltinProgram::new_loader(
config,
FunctionRegistry::default(),
)),
SBPFVersion::V2,
function_registry,
)
Expand Down
19 changes: 15 additions & 4 deletions fuzz/fuzz_targets/smart_jit_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ use libfuzzer_sys::fuzz_target;
use grammar_aware::*;
use solana_rbpf::{
ebpf,
elf::{Executable, FunctionRegistry, SBPFVersion},
elf::Executable,
insn_builder::{Arch, Instruction, IntoBytes},
memory_region::MemoryRegion,
program::{BuiltinProgram, FunctionRegistry, SBPFVersion},
verifier::{RequisiteVerifier, Verifier},
vm::{BuiltinProgram, TestContextObject},
vm::TestContextObject,
};
use test_utils::create_vm;

Expand Down Expand Up @@ -39,15 +40,25 @@ fuzz_target!(|data: FuzzData| {
.push();
let config = data.template.into();
let function_registry = FunctionRegistry::default();
if RequisiteVerifier::verify(prog.into_bytes(), &config, &SBPFVersion::V2, &function_registry).is_err() {
if RequisiteVerifier::verify(
prog.into_bytes(),
&config,
&SBPFVersion::V2,
&function_registry,
)
.is_err()
{
// verify please
return;
}
let mut interp_mem = data.mem.clone();
let mut jit_mem = data.mem;
let mut executable = Executable::<TestContextObject>::from_text_bytes(
prog.into_bytes(),
std::sync::Arc::new(BuiltinProgram::new_loader(config, FunctionRegistry::default())),
std::sync::Arc::new(BuiltinProgram::new_loader(
config,
FunctionRegistry::default(),
)),
SBPFVersion::V2,
function_registry,
)
Expand Down
26 changes: 18 additions & 8 deletions fuzz/fuzz_targets/smarter_jit_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ use libfuzzer_sys::fuzz_target;
use semantic_aware::*;
use solana_rbpf::{
ebpf,
elf::{Executable, FunctionRegistry, SBPFVersion},
elf::Executable,
insn_builder::IntoBytes,
memory_region::MemoryRegion,
program::{BuiltinProgram, FunctionRegistry, SBPFVersion},
static_analysis::Analysis,
verifier::{RequisiteVerifier, Verifier},
vm::{
BuiltinProgram, ContextObject, TestContextObject,
},
vm::{ContextObject, TestContextObject},
};
use test_utils::create_vm;

Expand All @@ -38,15 +37,25 @@ fuzz_target!(|data: FuzzData| {
let prog = make_program(&data.prog);
let config = data.template.into();
let function_registry = FunctionRegistry::default();
if RequisiteVerifier::verify(prog.into_bytes(), &config, &SBPFVersion::V2, &function_registry).is_err() {
if RequisiteVerifier::verify(
prog.into_bytes(),
&config,
&SBPFVersion::V2,
&function_registry,
)
.is_err()
{
// verify please
return;
}
let mut interp_mem = data.mem.clone();
let mut jit_mem = data.mem;
let mut executable = Executable::<TestContextObject>::from_text_bytes(
prog.into_bytes(),
std::sync::Arc::new(BuiltinProgram::new_loader(config, FunctionRegistry::default())),
std::sync::Arc::new(BuiltinProgram::new_loader(
config,
FunctionRegistry::default(),
)),
SBPFVersion::V2,
function_registry,
)
Expand Down Expand Up @@ -82,8 +91,9 @@ fuzz_target!(|data: FuzzData| {
let jit_res_str = format!("{:?}", jit_res);
if interp_res_str != jit_res_str {
// spot check: there's a meaningless bug where ExceededMaxInstructions is different due to jump calculations
if interp_res_str.contains("ExceededMaxInstructions") &&
jit_res_str.contains("ExceededMaxInstructions") {
if interp_res_str.contains("ExceededMaxInstructions")
&& jit_res_str.contains("ExceededMaxInstructions")
{
return;
}
eprintln!("{:#?}", &data.prog);
Expand Down
10 changes: 8 additions & 2 deletions fuzz/fuzz_targets/verify_semantic_aware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use libfuzzer_sys::fuzz_target;

use semantic_aware::*;
use solana_rbpf::{
elf::{FunctionRegistry, SBPFVersion},
insn_builder::IntoBytes,
program::{FunctionRegistry, SBPFVersion},
verifier::{RequisiteVerifier, Verifier},
};

Expand All @@ -24,5 +24,11 @@ fuzz_target!(|data: FuzzData| {
let prog = make_program(&data.prog);
let config = data.template.into();
let function_registry = FunctionRegistry::default();
RequisiteVerifier::verify(prog.into_bytes(), &config, &SBPFVersion::V2, &function_registry).unwrap();
RequisiteVerifier::verify(
prog.into_bytes(),
&config,
&SBPFVersion::V2,
&function_registry,
)
.unwrap();
});
7 changes: 4 additions & 3 deletions src/assembler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ use crate::{
Statement,
},
ebpf::{self, Insn},
elf::{Executable, FunctionRegistry, SBPFVersion},
vm::{BuiltinProgram, ContextObject},
elf::Executable,
program::{BuiltinProgram, FunctionRegistry, SBPFVersion},
vm::ContextObject,
};
use std::{collections::HashMap, sync::Arc};

Expand Down Expand Up @@ -258,7 +259,7 @@ fn insn(opc: u8, dst: i64, src: i64, off: i64, imm: i64) -> Result<Insn, String>
/// # Examples
///
/// ```
/// use solana_rbpf::{assembler::assemble, vm::{Config, TestContextObject, BuiltinProgram}};
/// use solana_rbpf::{assembler::assemble, program::BuiltinProgram, vm::{Config, TestContextObject}};
/// let executable = assemble::<TestContextObject>(
/// "add64 r1, 0x605
/// mov64 r2, 0x32
Expand Down
4 changes: 2 additions & 2 deletions src/disassembler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
use crate::{
ebpf,
elf::{FunctionRegistry, SBPFVersion},
program::{BuiltinProgram, FunctionRegistry, SBPFVersion},
static_analysis::CfgNode,
vm::{BuiltinProgram, ContextObject},
vm::ContextObject,
};
use std::collections::BTreeMap;

Expand Down
Loading

0 comments on commit 193bba0

Please sign in to comment.