This commit is contained in:
Alexander Meißner
2021-11-17 10:31:07 +01:00
committed by GitHub
parent c53174dc56
commit 318d26f0ff
13 changed files with 371 additions and 114 deletions

View File

@@ -1,6 +1,7 @@
#![allow(clippy::integer_arithmetic)]
pub mod alloc;
pub mod allocator_bump;
pub mod bpf_verifier;
pub mod deprecated;
pub mod serialization;
pub mod syscalls;
@@ -9,6 +10,7 @@ pub mod upgradeable_with_jit;
pub mod with_jit;
use crate::{
bpf_verifier::VerifierError,
serialization::{deserialize_parameters, serialize_parameters},
syscalls::SyscallError,
};
@@ -20,7 +22,6 @@ use solana_rbpf::{
error::{EbpfError, UserDefinedError},
memory_region::MemoryRegion,
static_analysis::Analysis,
verifier::{self, VerifierError},
vm::{Config, EbpfVm, Executable, InstructionMeter},
};
use solana_runtime::message_processor::MessageProcessor;
@@ -85,27 +86,23 @@ pub fn create_executor(
let config = Config {
max_call_depth: bpf_compute_budget.max_call_depth,
stack_frame_size: bpf_compute_budget.stack_frame_size,
enable_instruction_meter: true,
enable_instruction_tracing: log_enabled!(Trace),
..Config::default()
};
let mut executable = {
let keyed_accounts = invoke_context.get_keyed_accounts()?;
let program = keyed_account_at_index(keyed_accounts, program_account_index)?;
let account = program.try_account_ref()?;
let data = &account.data()[program_data_offset..];
<dyn Executable<BpfError, ThisInstructionMeter>>::from_elf(
data,
None,
config,
syscall_registry,
)
<dyn Executable<BpfError, ThisInstructionMeter>>::from_elf(data, None, config)
}
.map_err(|e| map_ebpf_error(invoke_context, e))?;
let (_, elf_bytes) = executable
.get_text_bytes()
.map_err(|e| map_ebpf_error(invoke_context, e))?;
verifier::check(elf_bytes)
.map_err(|e| map_ebpf_error(invoke_context, EbpfError::UserError(e.into())))?;
bpf_verifier::check(elf_bytes)
.map_err(|e| map_ebpf_error(invoke_context, EbpfError::UserError(e)))?;
executable.set_syscall_registry(syscall_registry);
if use_jit {
if let Err(err) = executable.jit_compile() {
ic_msg!(invoke_context, "Failed to compile program {:?}", err);
@@ -1004,7 +1001,6 @@ impl Executor for BpfExecutor {
mod tests {
use super::*;
use rand::Rng;
use solana_rbpf::vm::SyscallRegistry;
use solana_runtime::{bank::Bank, bank_client::BankClient};
use solana_sdk::{
account::{
@@ -1058,10 +1054,9 @@ mod tests {
solana_rbpf::elf::register_bpf_function(&mut bpf_functions, 0, "entrypoint").unwrap();
let program = <dyn Executable<BpfError, TestInstructionMeter>>::from_text_bytes(
program,
bpf_functions,
None,
Config::default(),
SyscallRegistry::default(),
bpf_functions,
)
.unwrap();
let mut vm =
@@ -1072,12 +1067,12 @@ mod tests {
}
#[test]
#[should_panic(expected = "LDDWCannotBeLast")]
#[should_panic(expected = "VerifierError(LDDWCannotBeLast)")]
fn test_bpf_loader_check_load_dw() {
let prog = &[
0x18, 0x00, 0x00, 0x00, 0x88, 0x77, 0x66, 0x55, // first half of lddw
];
verifier::check(prog).unwrap();
bpf_verifier::check(prog).unwrap();
}
#[test]