Rbpf v0.2.0 (#13365)

* Updates rbpf to v0.2.0,
which unifies the interfaces of the interpreter and the JIT.
However, the JIT is not enabled yet.
This commit is contained in:
Alexander Meißner
2020-11-04 18:46:26 +01:00
committed by GitHub
parent 5db6e4748d
commit 4999fe298b
10 changed files with 636 additions and 466 deletions

View File

@@ -6,8 +6,9 @@ extern crate solana_bpf_loader_program;
use solana_bpf_loader_program::{
create_vm,
serialization::{deserialize_parameters, serialize_parameters},
ThisInstructionMeter,
};
use solana_rbpf::vm::EbpfVm;
use solana_rbpf::vm::Executable;
use solana_runtime::{
bank::Bank,
bank_client::BankClient,
@@ -23,7 +24,7 @@ use solana_sdk::{
instruction::{AccountMeta, CompiledInstruction, Instruction, InstructionError},
keyed_account::KeyedAccount,
message::Message,
process_instruction::{BpfComputeBudget, MockInvokeContext},
process_instruction::{BpfComputeBudget, InvokeContext, MockInvokeContext},
pubkey::Pubkey,
signature::{Keypair, Signer},
sysvar::{clock, fees, rent, slot_hashes, stake_history},
@@ -74,25 +75,29 @@ fn run_program(
file.read_to_end(&mut data).unwrap();
let loader_id = bpf_loader::id();
let mut invoke_context = MockInvokeContext::default();
let executable = EbpfVm::create_executable_from_elf(&data, None).unwrap();
let (mut vm, heap_region) = create_vm(
&loader_id,
executable.as_ref(),
parameter_accounts,
&mut invoke_context,
)
.unwrap();
let mut parameter_bytes = serialize_parameters(
let parameter_bytes = serialize_parameters(
&bpf_loader::id(),
program_id,
parameter_accounts,
&instruction_data,
)
.unwrap();
let compute_meter = invoke_context.get_compute_meter();
let mut instruction_meter = ThisInstructionMeter { compute_meter };
let executable = Executable::from_elf(&data, None).unwrap();
let mut vm = create_vm(
&loader_id,
executable.as_ref(),
&parameter_bytes,
parameter_accounts,
&mut invoke_context,
)
.unwrap();
assert_eq!(
SUCCESS,
vm.execute_program(parameter_bytes.as_mut_slice(), &[], &[heap_region.clone()])
vm.execute_program_interpreted(&mut instruction_meter)
.unwrap()
);
deserialize_parameters(&bpf_loader::id(), parameter_accounts, &parameter_bytes).unwrap();
@@ -722,8 +727,11 @@ fn test_program_bpf_call_depth() {
let result = bank_client.send_and_confirm_instruction(&mint_keypair, instruction);
assert!(result.is_ok());
let instruction =
Instruction::new(program_id, &BpfComputeBudget::default().max_call_depth, vec![]);
let instruction = Instruction::new(
program_id,
&BpfComputeBudget::default().max_call_depth,
vec![],
);
let result = bank_client.send_and_confirm_instruction(&mint_keypair, instruction);
assert!(result.is_err());
}
@@ -811,7 +819,6 @@ fn test_program_bpf_instruction_introspection() {
Some(&mint_keypair.pubkey()),
);
let result = bank_client.send_and_confirm_message(&[&mint_keypair], message);
println!("result: {:?}", result);
assert!(result.is_ok());
// writable special instructions11111 key, should not be allowed