Singlular syscall context (#24204)

This commit is contained in:
Jack May
2022-04-11 16:05:09 -07:00
committed by GitHub
parent c1687b0604
commit 8a754d45b3
8 changed files with 466 additions and 399 deletions

View File

@ -1,16 +0,0 @@
use std::{alloc::Layout, fmt};
/// Based loosely on the unstable std::alloc::Alloc trait
pub trait Alloc {
fn alloc(&mut self, layout: Layout) -> Result<u64, AllocErr>;
fn dealloc(&mut self, addr: u64, layout: Layout);
}
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct AllocErr;
impl fmt::Display for AllocErr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("Error: Memory allocation failed")
}
}

View File

@ -1,8 +1,7 @@
#![allow(clippy::integer_arithmetic)]
use {
crate::alloc,
alloc::{Alloc, AllocErr},
solana_program_runtime::invoke_context::{Alloc, AllocErr},
solana_rbpf::aligned_memory::AlignedMemory,
std::alloc::Layout,
};

View File

@ -1,7 +1,6 @@
#![deny(clippy::integer_arithmetic)]
#![deny(clippy::indexing_slicing)]
pub mod alloc;
pub mod allocator_bump;
pub mod deprecated;
pub mod serialization;
@ -234,7 +233,6 @@ pub fn create_vm<'a, 'b>(
program: &'a Pin<Box<Executable<BpfError, ThisInstructionMeter>>>,
parameter_bytes: &mut [u8],
invoke_context: &'a mut InvokeContext<'b>,
orig_data_lens: &'a [usize],
) -> Result<EbpfVm<'a, BpfError, ThisInstructionMeter>, EbpfError<BpfError>> {
let compute_budget = invoke_context.get_compute_budget();
let heap_size = compute_budget.heap_size.unwrap_or(HEAP_LENGTH);
@ -251,7 +249,7 @@ pub fn create_vm<'a, 'b>(
let mut heap =
AlignedMemory::new_with_size(compute_budget.heap_size.unwrap_or(HEAP_LENGTH), HOST_ALIGN);
let mut vm = EbpfVm::new(program, heap.as_slice_mut(), parameter_bytes)?;
syscalls::bind_syscall_context_objects(&mut vm, invoke_context, heap, orig_data_lens)?;
syscalls::bind_syscall_context_objects(&mut vm, invoke_context, heap)?;
Ok(vm)
}
@ -1145,6 +1143,7 @@ impl Executor for BpfExecutor {
let (mut parameter_bytes, account_lengths) =
serialize_parameters(invoke_context.transaction_context, instruction_context)?;
serialize_time.stop();
invoke_context.set_orig_account_lengths(account_lengths)?;
let mut create_vm_time = Measure::start("create_vm");
let mut execute_time;
let execution_result = {
@ -1152,7 +1151,6 @@ impl Executor for BpfExecutor {
&self.executable,
parameter_bytes.as_slice_mut(),
invoke_context,
&account_lengths,
) {
Ok(info) => info,
Err(e) => {
@ -1234,7 +1232,7 @@ impl Executor for BpfExecutor {
.transaction_context
.get_current_instruction_context()?,
parameter_bytes.as_slice(),
&account_lengths,
invoke_context.get_orig_account_lengths()?,
invoke_context
.feature_set
.is_active(&do_support_realloc::id()),

File diff suppressed because it is too large Load Diff