Bump solana_rbpf to version 0.2.13 (#18068)

* Moves syscall_registry into the rbpf Executable constructor.

* Adds the reject_unresolved_syscalls flag which is only set when deploying programs via the CLI.
This commit is contained in:
Alexander Meißner
2021-07-07 09:50:11 +02:00
committed by GitHub
parent 04787be8b1
commit 8d5c04e257
13 changed files with 98 additions and 66 deletions

8
Cargo.lock generated
View File

@ -1661,9 +1661,9 @@ dependencies = [
[[package]] [[package]]
name = "goblin" name = "goblin"
version = "0.3.0" version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c69552f48b18aa6102ce0c82dd9bc9d3f8af5fc0a5797069b1b466b90570e39c" checksum = "0b1800b95efee8ad4ef04517d4d69f8e209e763b1668f1179aeeedd0e454da55"
dependencies = [ dependencies = [
"log 0.4.14", "log 0.4.14",
"plain", "plain",
@ -5802,9 +5802,9 @@ dependencies = [
[[package]] [[package]]
name = "solana_rbpf" name = "solana_rbpf"
version = "0.2.12" version = "0.2.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c44596a3613a44f76a7f6e5205464a1e78d1529fa19e8eacde0b9e55a6387f50" checksum = "fc1dced9892c2b0273318ef4d8486112ea7c7a7b8eb563a20e7858ad921b4719"
dependencies = [ dependencies = [
"byteorder", "byteorder",
"combine", "combine",

View File

@ -38,7 +38,7 @@ solana-config-program = { path = "../programs/config", version = "=1.8.0" }
solana-faucet = { path = "../faucet", version = "=1.8.0" } solana-faucet = { path = "../faucet", version = "=1.8.0" }
solana-logger = { path = "../logger", version = "=1.8.0" } solana-logger = { path = "../logger", version = "=1.8.0" }
solana-net-utils = { path = "../net-utils", version = "=1.8.0" } solana-net-utils = { path = "../net-utils", version = "=1.8.0" }
solana_rbpf = "=0.2.12" solana_rbpf = "=0.2.13"
solana-remote-wallet = { path = "../remote-wallet", version = "=1.8.0" } solana-remote-wallet = { path = "../remote-wallet", version = "=1.8.0" }
solana-sdk = { path = "../sdk", version = "=1.8.0" } solana-sdk = { path = "../sdk", version = "=1.8.0" }
solana-transaction-status = { path = "../transaction-status", version = "=1.8.0" } solana-transaction-status = { path = "../transaction-status", version = "=1.8.0" }

View File

@ -9,7 +9,7 @@ use bip39::{Language, Mnemonic, MnemonicType, Seed};
use clap::{App, AppSettings, Arg, ArgMatches, SubCommand}; use clap::{App, AppSettings, Arg, ArgMatches, SubCommand};
use log::*; use log::*;
use solana_account_decoder::{UiAccountEncoding, UiDataSliceConfig}; use solana_account_decoder::{UiAccountEncoding, UiDataSliceConfig};
use solana_bpf_loader_program::{BpfError, ThisInstructionMeter}; use solana_bpf_loader_program::{syscalls::register_syscalls, BpfError, ThisInstructionMeter};
use solana_clap_utils::{self, input_parsers::*, input_validators::*, keypair::*}; use solana_clap_utils::{self, input_parsers::*, input_validators::*, keypair::*};
use solana_cli_output::{ use solana_cli_output::{
display::new_spinner_progress_bar, CliProgram, CliProgramAccountType, CliProgramAuthority, display::new_spinner_progress_bar, CliProgram, CliProgramAccountType, CliProgramAuthority,
@ -42,6 +42,7 @@ use solana_sdk::{
loader_instruction, loader_instruction,
message::Message, message::Message,
native_token::Sol, native_token::Sol,
process_instruction::MockInvokeContext,
pubkey::Pubkey, pubkey::Pubkey,
signature::{keypair_from_seed, read_keypair_file, Keypair, Signer}, signature::{keypair_from_seed, read_keypair_file, Keypair, Signer},
signers::Signers, signers::Signers,
@ -1785,12 +1786,17 @@ fn read_and_verify_elf(program_location: &str) -> Result<Vec<u8>, Box<dyn std::e
let mut program_data = Vec::new(); let mut program_data = Vec::new();
file.read_to_end(&mut program_data) file.read_to_end(&mut program_data)
.map_err(|err| format!("Unable to read program file: {}", err))?; .map_err(|err| format!("Unable to read program file: {}", err))?;
let mut invoke_context = MockInvokeContext::new(vec![]);
// Verify the program // Verify the program
<dyn Executable<BpfError, ThisInstructionMeter>>::from_elf( <dyn Executable<BpfError, ThisInstructionMeter>>::from_elf(
&program_data, &program_data,
Some(|x| verifier::check(x)), Some(|x| verifier::check(x)),
Config::default(), Config {
reject_unresolved_syscalls: true,
..Config::default()
},
register_syscalls(&mut invoke_context).unwrap(),
) )
.map_err(|err| format!("ELF error: {}", err))?; .map_err(|err| format!("ELF error: {}", err))?;

Binary file not shown.

View File

@ -1122,9 +1122,9 @@ checksum = "bcc8e0c9bce37868955864dbecd2b1ab2bdf967e6f28066d65aaac620444b65c"
[[package]] [[package]]
name = "goblin" name = "goblin"
version = "0.3.0" version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c69552f48b18aa6102ce0c82dd9bc9d3f8af5fc0a5797069b1b466b90570e39c" checksum = "0b1800b95efee8ad4ef04517d4d69f8e209e763b1668f1179aeeedd0e454da55"
dependencies = [ dependencies = [
"log", "log",
"plain", "plain",
@ -3649,9 +3649,9 @@ dependencies = [
[[package]] [[package]]
name = "solana_rbpf" name = "solana_rbpf"
version = "0.2.12" version = "0.2.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c44596a3613a44f76a7f6e5205464a1e78d1529fa19e8eacde0b9e55a6387f50" checksum = "fc1dced9892c2b0273318ef4d8486112ea7c7a7b8eb563a20e7858ad921b4719"
dependencies = [ dependencies = [
"byteorder 1.4.3", "byteorder 1.4.3",
"combine", "combine",

View File

@ -30,7 +30,7 @@ solana-bpf-loader-program = { path = "../bpf_loader", version = "=1.8.0" }
solana-cli-output = { path = "../../cli-output", version = "=1.8.0" } solana-cli-output = { path = "../../cli-output", version = "=1.8.0" }
solana-logger = { path = "../../logger", version = "=1.8.0" } solana-logger = { path = "../../logger", version = "=1.8.0" }
solana-measure = { path = "../../measure", version = "=1.8.0" } solana-measure = { path = "../../measure", version = "=1.8.0" }
solana_rbpf = "=0.2.12" solana_rbpf = "=0.2.13"
solana-runtime = { path = "../../runtime", version = "=1.8.0" } solana-runtime = { path = "../../runtime", version = "=1.8.0" }
solana-sdk = { path = "../../sdk", version = "=1.8.0" } solana-sdk = { path = "../../sdk", version = "=1.8.0" }
solana-transaction-status = { path = "../../transaction-status", version = "=1.8.0" } solana-transaction-status = { path = "../../transaction-status", version = "=1.8.0" }

View File

@ -11,7 +11,7 @@ use solana_bpf_loader_program::{
ThisInstructionMeter, ThisInstructionMeter,
}; };
use solana_measure::measure::Measure; use solana_measure::measure::Measure;
use solana_rbpf::vm::{Config, Executable, InstructionMeter}; use solana_rbpf::vm::{Config, Executable, InstructionMeter, SyscallRegistry};
use solana_runtime::{ use solana_runtime::{
bank::Bank, bank::Bank,
bank_client::BankClient, bank_client::BankClient,
@ -79,6 +79,7 @@ fn bench_program_create_executable(bencher: &mut Bencher) {
&elf, &elf,
None, None,
Config::default(), Config::default(),
SyscallRegistry::default(),
) )
.unwrap(); .unwrap();
}); });
@ -97,10 +98,13 @@ fn bench_program_alu(bencher: &mut Bencher) {
let mut invoke_context = MockInvokeContext::new(vec![]); let mut invoke_context = MockInvokeContext::new(vec![]);
let elf = load_elf("bench_alu").unwrap(); let elf = load_elf("bench_alu").unwrap();
let mut executable = let mut executable = <dyn Executable<BpfError, ThisInstructionMeter>>::from_elf(
<dyn Executable<BpfError, ThisInstructionMeter>>::from_elf(&elf, None, Config::default()) &elf,
None,
Config::default(),
register_syscalls(&mut invoke_context).unwrap(),
)
.unwrap(); .unwrap();
executable.set_syscall_registry(register_syscalls(&mut invoke_context).unwrap());
executable.jit_compile().unwrap(); executable.jit_compile().unwrap();
let compute_meter = invoke_context.get_compute_meter(); let compute_meter = invoke_context.get_compute_meter();
let mut instruction_meter = ThisInstructionMeter { compute_meter }; let mut instruction_meter = ThisInstructionMeter { compute_meter };
@ -225,10 +229,13 @@ fn bench_instruction_count_tuner(_bencher: &mut Bencher) {
.unwrap(); .unwrap();
let elf = load_elf("tuner").unwrap(); let elf = load_elf("tuner").unwrap();
let mut executable = let executable = <dyn Executable<BpfError, ThisInstructionMeter>>::from_elf(
<dyn Executable<BpfError, ThisInstructionMeter>>::from_elf(&elf, None, Config::default()) &elf,
None,
Config::default(),
register_syscalls(&mut invoke_context).unwrap(),
)
.unwrap(); .unwrap();
executable.set_syscall_registry(register_syscalls(&mut invoke_context).unwrap());
let compute_meter = invoke_context.get_compute_meter(); let compute_meter = invoke_context.get_compute_meter();
let mut instruction_meter = ThisInstructionMeter { compute_meter }; let mut instruction_meter = ThisInstructionMeter { compute_meter };
let mut vm = create_vm( let mut vm = create_vm(

View File

@ -210,14 +210,16 @@ fn run_program(
let mut instruction_meter = ThisInstructionMeter { compute_meter }; let mut instruction_meter = ThisInstructionMeter { compute_meter };
let config = Config { let config = Config {
max_call_depth: 20,
stack_frame_size: 4096,
enable_instruction_meter: true,
enable_instruction_tracing: true, enable_instruction_tracing: true,
..Config::default()
}; };
let mut executable = let mut executable = <dyn Executable<BpfError, ThisInstructionMeter>>::from_elf(
<dyn Executable<BpfError, ThisInstructionMeter>>::from_elf(&data, None, config).unwrap(); &data,
executable.set_syscall_registry(register_syscalls(&mut invoke_context).unwrap()); None,
config,
register_syscalls(&mut invoke_context).unwrap(),
)
.unwrap();
executable.jit_compile().unwrap(); executable.jit_compile().unwrap();
let mut instruction_count = 0; let mut instruction_count = 0;

View File

@ -23,7 +23,7 @@ sha3 = "0.9.1"
solana-measure = { path = "../../measure", version = "=1.8.0" } solana-measure = { path = "../../measure", version = "=1.8.0" }
solana-runtime = { path = "../../runtime", version = "=1.8.0" } solana-runtime = { path = "../../runtime", version = "=1.8.0" }
solana-sdk = { path = "../../sdk", version = "=1.8.0" } solana-sdk = { path = "../../sdk", version = "=1.8.0" }
solana_rbpf = "=0.2.12" solana_rbpf = "=0.2.13"
thiserror = "1.0" thiserror = "1.0"
[dev-dependencies] [dev-dependencies]

View File

@ -82,15 +82,20 @@ pub fn create_executor(
let config = Config { let config = Config {
max_call_depth: bpf_compute_budget.max_call_depth, max_call_depth: bpf_compute_budget.max_call_depth,
stack_frame_size: bpf_compute_budget.stack_frame_size, stack_frame_size: bpf_compute_budget.stack_frame_size,
enable_instruction_meter: true,
enable_instruction_tracing: log_enabled!(Trace), enable_instruction_tracing: log_enabled!(Trace),
..Config::default()
}; };
let mut executable = { let mut executable = {
let keyed_accounts = invoke_context.get_keyed_accounts()?; let keyed_accounts = invoke_context.get_keyed_accounts()?;
let program = keyed_account_at_index(keyed_accounts, program_account_index)?; let program = keyed_account_at_index(keyed_accounts, program_account_index)?;
let account = program.try_account_ref()?; let account = program.try_account_ref()?;
let data = &account.data()[program_data_offset..]; let data = &account.data()[program_data_offset..];
<dyn Executable<BpfError, ThisInstructionMeter>>::from_elf(data, None, config) <dyn Executable<BpfError, ThisInstructionMeter>>::from_elf(
data,
None,
config,
syscall_registry,
)
} }
.map_err(|e| map_ebpf_error(invoke_context, e))?; .map_err(|e| map_ebpf_error(invoke_context, e))?;
let (_, elf_bytes) = executable let (_, elf_bytes) = executable
@ -98,7 +103,6 @@ pub fn create_executor(
.map_err(|e| map_ebpf_error(invoke_context, e))?; .map_err(|e| map_ebpf_error(invoke_context, e))?;
verifier::check(elf_bytes) verifier::check(elf_bytes)
.map_err(|e| map_ebpf_error(invoke_context, EbpfError::UserError(e.into())))?; .map_err(|e| map_ebpf_error(invoke_context, EbpfError::UserError(e.into())))?;
executable.set_syscall_registry(syscall_registry);
if use_jit { if use_jit {
if let Err(err) = executable.jit_compile() { if let Err(err) = executable.jit_compile() {
ic_msg!(invoke_context, "Failed to compile program {:?}", err); ic_msg!(invoke_context, "Failed to compile program {:?}", err);
@ -853,6 +857,7 @@ impl Executor for BpfExecutor {
mod tests { mod tests {
use super::*; use super::*;
use rand::Rng; use rand::Rng;
use solana_rbpf::vm::SyscallRegistry;
use solana_runtime::{bank::Bank, bank_client::BankClient}; use solana_runtime::{bank::Bank, bank_client::BankClient};
use solana_sdk::{ use solana_sdk::{
account::{ account::{
@ -905,9 +910,10 @@ mod tests {
solana_rbpf::elf::register_bpf_function(&mut bpf_functions, 0, "entrypoint").unwrap(); solana_rbpf::elf::register_bpf_function(&mut bpf_functions, 0, "entrypoint").unwrap();
let program = <dyn Executable<BpfError, TestInstructionMeter>>::from_text_bytes( let program = <dyn Executable<BpfError, TestInstructionMeter>>::from_text_bytes(
program, program,
bpf_functions,
None, None,
Config::default(), Config::default(),
SyscallRegistry::default(),
bpf_functions,
) )
.unwrap(); .unwrap();
let mut vm = let mut vm =

View File

@ -2375,13 +2375,6 @@ mod tests {
}; };
use std::str::FromStr; use std::str::FromStr;
const DEFAULT_CONFIG: Config = Config {
max_call_depth: 20,
stack_frame_size: 4_096,
enable_instruction_meter: true,
enable_instruction_tracing: false,
};
macro_rules! assert_access_violation { macro_rules! assert_access_violation {
($result:expr, $va:expr, $len:expr) => { ($result:expr, $va:expr, $len:expr) => {
match $result { match $result {
@ -2397,9 +2390,10 @@ mod tests {
const LENGTH: u64 = 1000; const LENGTH: u64 = 1000;
let data = vec![0u8; LENGTH as usize]; let data = vec![0u8; LENGTH as usize];
let addr = data.as_ptr() as u64; let addr = data.as_ptr() as u64;
let config = Config::default();
let memory_mapping = MemoryMapping::new::<UserError>( let memory_mapping = MemoryMapping::new::<UserError>(
vec![MemoryRegion::new_from_slice(&data, START, 0, false)], vec![MemoryRegion::new_from_slice(&data, START, 0, false)],
&DEFAULT_CONFIG, &config,
) )
.unwrap(); .unwrap();
@ -2436,6 +2430,7 @@ mod tests {
// Pubkey // Pubkey
let pubkey = solana_sdk::pubkey::new_rand(); let pubkey = solana_sdk::pubkey::new_rand();
let addr = &pubkey as *const _ as u64; let addr = &pubkey as *const _ as u64;
let config = Config::default();
let memory_mapping = MemoryMapping::new::<UserError>( let memory_mapping = MemoryMapping::new::<UserError>(
vec![MemoryRegion { vec![MemoryRegion {
host_addr: addr, host_addr: addr,
@ -2444,7 +2439,7 @@ mod tests {
vm_gap_shift: 63, vm_gap_shift: 63,
is_writable: false, is_writable: false,
}], }],
&DEFAULT_CONFIG, &config,
) )
.unwrap(); .unwrap();
let translated_pubkey = let translated_pubkey =
@ -2466,7 +2461,7 @@ mod tests {
vm_gap_shift: 63, vm_gap_shift: 63,
is_writable: false, is_writable: false,
}], }],
&DEFAULT_CONFIG, &config,
) )
.unwrap(); .unwrap();
let translated_instruction = let translated_instruction =
@ -2485,6 +2480,7 @@ mod tests {
let data: Vec<u8> = vec![]; let data: Vec<u8> = vec![];
assert_eq!(0x1 as *const u8, data.as_ptr()); assert_eq!(0x1 as *const u8, data.as_ptr());
let addr = good_data.as_ptr() as *const _ as u64; let addr = good_data.as_ptr() as *const _ as u64;
let config = Config::default();
let memory_mapping = MemoryMapping::new::<UserError>( let memory_mapping = MemoryMapping::new::<UserError>(
vec![MemoryRegion { vec![MemoryRegion {
host_addr: addr, host_addr: addr,
@ -2493,7 +2489,7 @@ mod tests {
vm_gap_shift: 63, vm_gap_shift: 63,
is_writable: false, is_writable: false,
}], }],
&DEFAULT_CONFIG, &config,
) )
.unwrap(); .unwrap();
let translated_data = translate_slice::<u8>( let translated_data = translate_slice::<u8>(
@ -2518,7 +2514,7 @@ mod tests {
vm_gap_shift: 63, vm_gap_shift: 63,
is_writable: false, is_writable: false,
}], }],
&DEFAULT_CONFIG, &config,
) )
.unwrap(); .unwrap();
let translated_data = translate_slice::<u8>( let translated_data = translate_slice::<u8>(
@ -2561,7 +2557,7 @@ mod tests {
vm_gap_shift: 63, vm_gap_shift: 63,
is_writable: false, is_writable: false,
}], }],
&DEFAULT_CONFIG, &config,
) )
.unwrap(); .unwrap();
let translated_data = translate_slice::<u64>( let translated_data = translate_slice::<u64>(
@ -2591,7 +2587,7 @@ mod tests {
vm_gap_shift: 63, vm_gap_shift: 63,
is_writable: false, is_writable: false,
}], }],
&DEFAULT_CONFIG, &config,
) )
.unwrap(); .unwrap();
let translated_data = translate_slice::<Pubkey>( let translated_data = translate_slice::<Pubkey>(
@ -2611,6 +2607,7 @@ mod tests {
fn test_translate_string_and_do() { fn test_translate_string_and_do() {
let string = "Gaggablaghblagh!"; let string = "Gaggablaghblagh!";
let addr = string.as_ptr() as *const _ as u64; let addr = string.as_ptr() as *const _ as u64;
let config = Config::default();
let memory_mapping = MemoryMapping::new::<UserError>( let memory_mapping = MemoryMapping::new::<UserError>(
vec![MemoryRegion { vec![MemoryRegion {
host_addr: addr, host_addr: addr,
@ -2619,7 +2616,7 @@ mod tests {
vm_gap_shift: 63, vm_gap_shift: 63,
is_writable: false, is_writable: false,
}], }],
&DEFAULT_CONFIG, &config,
) )
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
@ -2642,9 +2639,9 @@ mod tests {
#[test] #[test]
#[should_panic(expected = "UserError(SyscallError(Abort))")] #[should_panic(expected = "UserError(SyscallError(Abort))")]
fn test_syscall_abort() { fn test_syscall_abort() {
let config = Config::default();
let memory_mapping = let memory_mapping =
MemoryMapping::new::<UserError>(vec![MemoryRegion::default()], &DEFAULT_CONFIG) MemoryMapping::new::<UserError>(vec![MemoryRegion::default()], &config).unwrap();
.unwrap();
let mut result: Result<u64, EbpfError<BpfError>> = Ok(0); let mut result: Result<u64, EbpfError<BpfError>> = Ok(0);
SyscallAbort::call( SyscallAbort::call(
&mut SyscallAbort {}, &mut SyscallAbort {},
@ -2664,6 +2661,7 @@ mod tests {
fn test_syscall_sol_panic() { fn test_syscall_sol_panic() {
let string = "Gaggablaghblagh!"; let string = "Gaggablaghblagh!";
let addr = string.as_ptr() as *const _ as u64; let addr = string.as_ptr() as *const _ as u64;
let config = Config::default();
let memory_mapping = MemoryMapping::new::<UserError>( let memory_mapping = MemoryMapping::new::<UserError>(
vec![MemoryRegion { vec![MemoryRegion {
host_addr: addr, host_addr: addr,
@ -2672,7 +2670,7 @@ mod tests {
vm_gap_shift: 63, vm_gap_shift: 63,
is_writable: false, is_writable: false,
}], }],
&DEFAULT_CONFIG, &config,
) )
.unwrap(); .unwrap();
@ -2740,6 +2738,7 @@ mod tests {
loader_id: &bpf_loader::id(), loader_id: &bpf_loader::id(),
enforce_aligned_host_addrs: true, enforce_aligned_host_addrs: true,
}; };
let config = Config::default();
let memory_mapping = MemoryMapping::new::<UserError>( let memory_mapping = MemoryMapping::new::<UserError>(
vec![MemoryRegion { vec![MemoryRegion {
host_addr: addr, host_addr: addr,
@ -2748,7 +2747,7 @@ mod tests {
vm_gap_shift: 63, vm_gap_shift: 63,
is_writable: false, is_writable: false,
}], }],
&DEFAULT_CONFIG, &config,
) )
.unwrap(); .unwrap();
@ -2853,7 +2852,8 @@ mod tests {
compute_meter, compute_meter,
logger, logger,
}; };
let memory_mapping = MemoryMapping::new::<UserError>(vec![], &DEFAULT_CONFIG).unwrap(); let config = Config::default();
let memory_mapping = MemoryMapping::new::<UserError>(vec![], &config).unwrap();
let mut result: Result<u64, EbpfError<BpfError>> = Ok(0); let mut result: Result<u64, EbpfError<BpfError>> = Ok(0);
syscall_sol_log_u64.call(1, 2, 3, 4, 5, &memory_mapping, &mut result); syscall_sol_log_u64.call(1, 2, 3, 4, 5, &memory_mapping, &mut result);
@ -2880,6 +2880,7 @@ mod tests {
loader_id: &bpf_loader::id(), loader_id: &bpf_loader::id(),
enforce_aligned_host_addrs: true, enforce_aligned_host_addrs: true,
}; };
let config = Config::default();
let memory_mapping = MemoryMapping::new::<UserError>( let memory_mapping = MemoryMapping::new::<UserError>(
vec![MemoryRegion { vec![MemoryRegion {
host_addr: addr, host_addr: addr,
@ -2888,7 +2889,7 @@ mod tests {
vm_gap_shift: 63, vm_gap_shift: 63,
is_writable: false, is_writable: false,
}], }],
&DEFAULT_CONFIG, &config,
) )
.unwrap(); .unwrap();
@ -2923,6 +2924,7 @@ mod tests {
#[test] #[test]
fn test_syscall_sol_alloc_free() { fn test_syscall_sol_alloc_free() {
let config = Config::default();
// large alloc // large alloc
{ {
let heap = AlignedMemory::new_with_size(100, HOST_ALIGN); let heap = AlignedMemory::new_with_size(100, HOST_ALIGN);
@ -2933,7 +2935,7 @@ mod tests {
0, 0,
true, true,
)], )],
&DEFAULT_CONFIG, &config,
) )
.unwrap(); .unwrap();
let mut syscall = SyscallAllocFree { let mut syscall = SyscallAllocFree {
@ -2960,7 +2962,7 @@ mod tests {
0, 0,
true, true,
)], )],
&DEFAULT_CONFIG, &config,
) )
.unwrap(); .unwrap();
let mut syscall = SyscallAllocFree { let mut syscall = SyscallAllocFree {
@ -2986,7 +2988,7 @@ mod tests {
0, 0,
true, true,
)], )],
&DEFAULT_CONFIG, &config,
) )
.unwrap(); .unwrap();
let mut syscall = SyscallAllocFree { let mut syscall = SyscallAllocFree {
@ -3006,6 +3008,7 @@ mod tests {
fn check_alignment<T>() { fn check_alignment<T>() {
let heap = AlignedMemory::new_with_size(100, HOST_ALIGN); let heap = AlignedMemory::new_with_size(100, HOST_ALIGN);
let config = Config::default();
let memory_mapping = MemoryMapping::new::<UserError>( let memory_mapping = MemoryMapping::new::<UserError>(
vec![MemoryRegion::new_from_slice( vec![MemoryRegion::new_from_slice(
heap.as_slice(), heap.as_slice(),
@ -3013,7 +3016,7 @@ mod tests {
0, 0,
true, true,
)], )],
&DEFAULT_CONFIG, &config,
) )
.unwrap(); .unwrap();
let mut syscall = SyscallAllocFree { let mut syscall = SyscallAllocFree {
@ -3064,6 +3067,7 @@ mod tests {
let ro_len = bytes_to_hash.len() as u64; let ro_len = bytes_to_hash.len() as u64;
let ro_va = 96; let ro_va = 96;
let rw_va = 192; let rw_va = 192;
let config = Config::default();
let memory_mapping = MemoryMapping::new::<UserError>( let memory_mapping = MemoryMapping::new::<UserError>(
vec![ vec![
MemoryRegion { MemoryRegion {
@ -3095,7 +3099,7 @@ mod tests {
is_writable: true, is_writable: true,
}, },
], ],
&DEFAULT_CONFIG, &config,
) )
.unwrap(); .unwrap();
let compute_meter: Rc<RefCell<dyn ComputeMeter>> = let compute_meter: Rc<RefCell<dyn ComputeMeter>> =
@ -3161,6 +3165,7 @@ mod tests {
#[test] #[test]
fn test_syscall_get_sysvar() { fn test_syscall_get_sysvar() {
let config = Config::default();
// Test clock sysvar // Test clock sysvar
{ {
let got_clock = Clock::default(); let got_clock = Clock::default();
@ -3174,7 +3179,7 @@ mod tests {
vm_gap_shift: 63, vm_gap_shift: 63,
is_writable: true, is_writable: true,
}], }],
&DEFAULT_CONFIG, &config,
) )
.unwrap(); .unwrap();
@ -3216,7 +3221,7 @@ mod tests {
vm_gap_shift: 63, vm_gap_shift: 63,
is_writable: true, is_writable: true,
}], }],
&DEFAULT_CONFIG, &config,
) )
.unwrap(); .unwrap();
@ -3266,7 +3271,7 @@ mod tests {
vm_gap_shift: 63, vm_gap_shift: 63,
is_writable: true, is_writable: true,
}], }],
&DEFAULT_CONFIG, &config,
) )
.unwrap(); .unwrap();
@ -3306,7 +3311,7 @@ mod tests {
vm_gap_shift: 63, vm_gap_shift: 63,
is_writable: true, is_writable: true,
}], }],
&DEFAULT_CONFIG, &config,
) )
.unwrap(); .unwrap();

View File

@ -15,4 +15,4 @@ serde_json = "1.0.64"
solana-bpf-loader-program = { path = "../programs/bpf_loader", version = "=1.8.0" } solana-bpf-loader-program = { path = "../programs/bpf_loader", version = "=1.8.0" }
solana-logger = { path = "../logger", version = "=1.8.0" } solana-logger = { path = "../logger", version = "=1.8.0" }
solana-sdk = { path = "../sdk", version = "=1.8.0" } solana-sdk = { path = "../sdk", version = "=1.8.0" }
solana_rbpf = "=0.2.12" solana_rbpf = "=0.2.13"

View File

@ -185,14 +185,21 @@ native machine code before execting it in the virtual machine.",
file.seek(SeekFrom::Start(0)).unwrap(); file.seek(SeekFrom::Start(0)).unwrap();
let mut contents = Vec::new(); let mut contents = Vec::new();
file.read_to_end(&mut contents).unwrap(); file.read_to_end(&mut contents).unwrap();
let syscall_registry = register_syscalls(&mut invoke_context).unwrap();
let mut executable = if magic == [0x7f, 0x45, 0x4c, 0x46] { let mut executable = if magic == [0x7f, 0x45, 0x4c, 0x46] {
<dyn Executable<BpfError, ThisInstructionMeter>>::from_elf(&contents, None, config) <dyn Executable<BpfError, ThisInstructionMeter>>::from_elf(
&contents,
None,
config,
syscall_registry,
)
.map_err(|err| format!("Executable constructor failed: {:?}", err)) .map_err(|err| format!("Executable constructor failed: {:?}", err))
} else { } else {
assemble::<BpfError, ThisInstructionMeter>( assemble::<BpfError, ThisInstructionMeter>(
std::str::from_utf8(contents.as_slice()).unwrap(), std::str::from_utf8(contents.as_slice()).unwrap(),
None, None,
config, config,
syscall_registry,
) )
} }
.unwrap(); .unwrap();
@ -201,7 +208,6 @@ native machine code before execting it in the virtual machine.",
let (_, elf_bytes) = executable.get_text_bytes().unwrap(); let (_, elf_bytes) = executable.get_text_bytes().unwrap();
check(elf_bytes).unwrap(); check(elf_bytes).unwrap();
} }
executable.set_syscall_registry(register_syscalls(&mut invoke_context).unwrap());
executable.jit_compile().unwrap(); executable.jit_compile().unwrap();
let analysis = Analysis::from_executable(executable.as_ref()); let analysis = Analysis::from_executable(executable.as_ref());