Pull in solana_rbpf v0.1.14 (#5609)
This commit is contained in:
@ -26,7 +26,7 @@ solana-bpf-loader-api = { path = "../bpf_loader_api", version = "0.18.0-pre2" }
|
||||
solana-logger = { path = "../../logger", version = "0.18.0-pre2" }
|
||||
solana-runtime = { path = "../../runtime", version = "0.18.0-pre2" }
|
||||
solana-sdk = { path = "../../sdk", version = "0.18.0-pre2" }
|
||||
solana_rbpf = "=0.1.13"
|
||||
solana_rbpf = "=0.1.14"
|
||||
|
||||
[[bench]]
|
||||
name = "bpf_loader"
|
||||
|
@ -3,7 +3,7 @@
|
||||
extern crate test;
|
||||
|
||||
use byteorder::{ByteOrder, LittleEndian, WriteBytesExt};
|
||||
use solana_rbpf::EbpfVmRaw;
|
||||
use solana_rbpf::EbpfVm;
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::io::Error;
|
||||
@ -44,7 +44,7 @@ const ARMSTRONG_EXPECTED: u64 = 5;
|
||||
#[bench]
|
||||
fn bench_program_load_elf(bencher: &mut Bencher) {
|
||||
let elf = load_elf().unwrap();
|
||||
let mut vm = EbpfVmRaw::new(None).unwrap();
|
||||
let mut vm = EbpfVm::new(None).unwrap();
|
||||
vm.set_verifier(empty_check).unwrap();
|
||||
|
||||
bencher.iter(|| {
|
||||
@ -55,7 +55,7 @@ fn bench_program_load_elf(bencher: &mut Bencher) {
|
||||
#[bench]
|
||||
fn bench_program_verify(bencher: &mut Bencher) {
|
||||
let elf = load_elf().unwrap();
|
||||
let mut vm = EbpfVmRaw::new(None).unwrap();
|
||||
let mut vm = EbpfVm::new(None).unwrap();
|
||||
vm.set_verifier(empty_check).unwrap();
|
||||
vm.set_elf(&elf).unwrap();
|
||||
|
||||
@ -101,28 +101,29 @@ fn bench_program_alu(bencher: &mut Bencher) {
|
||||
println!(" {:?} MIPS", mips);
|
||||
println!("{{ \"type\": \"bench\", \"name\": \"bench_program_alu_interpreted_mips\", \"median\": {:?}, \"deviation\": 0 }}", mips);
|
||||
|
||||
println!("JIT to native:");
|
||||
vm.jit_compile().unwrap();
|
||||
unsafe {
|
||||
assert_eq!(
|
||||
1, /*true*/
|
||||
vm.execute_program_jit(&mut inner_iter).unwrap()
|
||||
);
|
||||
}
|
||||
assert_eq!(ARMSTRONG_LIMIT, LittleEndian::read_u64(&inner_iter));
|
||||
assert_eq!(
|
||||
ARMSTRONG_EXPECTED,
|
||||
LittleEndian::read_u64(&inner_iter[mem::size_of::<u64>()..])
|
||||
);
|
||||
// JIT disabled until address translation support is added
|
||||
// println!("JIT to native:");
|
||||
// vm.jit_compile().unwrap();
|
||||
// unsafe {
|
||||
// assert_eq!(
|
||||
// 1, /*true*/
|
||||
// vm.execute_program_jit(&mut inner_iter).unwrap()
|
||||
// );
|
||||
// }
|
||||
// assert_eq!(ARMSTRONG_LIMIT, LittleEndian::read_u64(&inner_iter));
|
||||
// assert_eq!(
|
||||
// ARMSTRONG_EXPECTED,
|
||||
// LittleEndian::read_u64(&inner_iter[mem::size_of::<u64>()..])
|
||||
// );
|
||||
|
||||
bencher.iter(|| unsafe {
|
||||
vm.execute_program_jit(&mut inner_iter).unwrap();
|
||||
});
|
||||
let summary = bencher.bench(|_bencher| {}).unwrap();
|
||||
println!(" {:?} instructions", instructions);
|
||||
println!(" {:?} ns/iter median", summary.median as u64);
|
||||
assert!(0f64 != summary.median);
|
||||
let mips = (instructions * (ns_per_s / summary.median as u64)) / one_million;
|
||||
println!(" {:?} MIPS", mips);
|
||||
println!("{{ \"type\": \"bench\", \"name\": \"bench_program_alu_jit_to_native_mips\", \"median\": {:?}, \"deviation\": 0 }}", mips);
|
||||
// bencher.iter(|| unsafe {
|
||||
// vm.execute_program_jit(&mut inner_iter).unwrap();
|
||||
// });
|
||||
// let summary = bencher.bench(|_bencher| {}).unwrap();
|
||||
// println!(" {:?} instructions", instructions);
|
||||
// println!(" {:?} ns/iter median", summary.median as u64);
|
||||
// assert!(0f64 != summary.median);
|
||||
// let mips = (instructions * (ns_per_s / summary.median as u64)) / one_million;
|
||||
// println!(" {:?} MIPS", mips);
|
||||
// println!("{{ \"type\": \"bench\", \"name\": \"bench_program_alu_jit_to_native_mips\", \"median\": {:?}, \"deviation\": 0 }}", mips);
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ extern bool entrypoint(const uint8_t *input) {
|
||||
}
|
||||
}
|
||||
|
||||
sol_log_64(x, count, 0, 0, 0);
|
||||
// sol_log_64(x, count, 0, 0, 0);
|
||||
*result = count;
|
||||
return true;
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ log = "0.4.8"
|
||||
serde = "1.0.99"
|
||||
solana-logger = { path = "../../logger", version = "0.18.0-pre2" }
|
||||
solana-sdk = { path = "../../sdk", version = "0.18.0-pre2" }
|
||||
solana_rbpf = "=0.1.13"
|
||||
solana_rbpf = "=0.1.14"
|
||||
|
||||
[lib]
|
||||
crate-type = ["lib"]
|
||||
|
@ -3,8 +3,8 @@ use std::fmt;
|
||||
|
||||
/// Based loosely on the unstable std::alloc::Alloc trait
|
||||
pub trait Alloc {
|
||||
fn alloc(&mut self, layout: Layout) -> Result<*mut u8, AllocErr>;
|
||||
fn dealloc(&mut self, ptr: *mut u8, layout: Layout);
|
||||
fn alloc(&mut self, layout: Layout) -> Result<u64, AllocErr>;
|
||||
fn dealloc(&mut self, addr: u64, layout: Layout);
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||
|
@ -6,27 +6,35 @@ use std::alloc::Layout;
|
||||
#[derive(Debug)]
|
||||
pub struct BPFAllocator {
|
||||
heap: Vec<u8>,
|
||||
pos: usize,
|
||||
start: u64,
|
||||
len: u64,
|
||||
pos: u64,
|
||||
}
|
||||
|
||||
impl BPFAllocator {
|
||||
pub fn new(heap: Vec<u8>) -> Self {
|
||||
Self { heap, pos: 0 }
|
||||
pub fn new(heap: Vec<u8>, virtual_address: u64) -> Self {
|
||||
let len = heap.len() as u64;
|
||||
Self {
|
||||
heap,
|
||||
start: virtual_address,
|
||||
len,
|
||||
pos: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Alloc for BPFAllocator {
|
||||
fn alloc(&mut self, layout: Layout) -> Result<*mut u8, AllocErr> {
|
||||
if self.pos + layout.size() <= self.heap.len() {
|
||||
let ptr = unsafe { self.heap.as_mut_ptr().add(self.pos) };
|
||||
self.pos += layout.size();
|
||||
Ok(ptr)
|
||||
fn alloc(&mut self, layout: Layout) -> Result<u64, AllocErr> {
|
||||
if self.pos + layout.size() as u64 <= self.len {
|
||||
let addr = self.start + self.pos;
|
||||
self.pos += layout.size() as u64;
|
||||
Ok(addr)
|
||||
} else {
|
||||
Err(AllocErr)
|
||||
}
|
||||
}
|
||||
|
||||
fn dealloc(&mut self, _ptr: *mut u8, _layout: Layout) {
|
||||
fn dealloc(&mut self, _addr: u64, _layout: Layout) {
|
||||
// It's a bump allocator, free not supported
|
||||
}
|
||||
}
|
||||
|
@ -1,40 +0,0 @@
|
||||
use crate::alloc;
|
||||
|
||||
use alloc::{Alloc, AllocErr};
|
||||
use std::alloc::{self as system_alloc, Layout};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct BPFAllocator {
|
||||
allocated: usize,
|
||||
size: usize,
|
||||
}
|
||||
|
||||
impl BPFAllocator {
|
||||
pub fn new(heap: Vec<u8>) -> Self {
|
||||
Self {
|
||||
allocated: 0,
|
||||
size: heap.len(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Alloc for BPFAllocator {
|
||||
fn alloc(&mut self, layout: Layout) -> Result<*mut u8, AllocErr> {
|
||||
if self.allocated + layout.size() <= self.size {
|
||||
let ptr = unsafe { system_alloc::alloc(layout) };
|
||||
if !ptr.is_null() {
|
||||
self.allocated += layout.size();
|
||||
return Ok(ptr);
|
||||
}
|
||||
}
|
||||
Err(AllocErr)
|
||||
}
|
||||
|
||||
#[allow(clippy::not_unsafe_ptr_arg_deref)]
|
||||
fn dealloc(&mut self, ptr: *mut u8, layout: Layout) {
|
||||
self.allocated -= layout.size();
|
||||
unsafe {
|
||||
system_alloc::dealloc(ptr, layout);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,13 @@
|
||||
use crate::Alloc;
|
||||
use crate::alloc;
|
||||
use alloc::Alloc;
|
||||
use libc::c_char;
|
||||
use log::*;
|
||||
use solana_rbpf::{EbpfVmRaw, MemoryRegion};
|
||||
use solana_rbpf::{
|
||||
ebpf::{HelperContext, MM_HEAP_START},
|
||||
memory_region::{translate_addr, MemoryRegion},
|
||||
EbpfVm,
|
||||
};
|
||||
use std::alloc::Layout;
|
||||
use std::any::Any;
|
||||
use std::ffi::CStr;
|
||||
use std::io::{Error, ErrorKind};
|
||||
use std::mem;
|
||||
@ -13,126 +17,66 @@ use std::str::from_utf8;
|
||||
/// Program heap allocators are intended to allocate/free from a given
|
||||
/// chunk of memory. The specific allocator implementation is
|
||||
/// selectable at build-time.
|
||||
/// Enable only one of the following BPFAllocator implementations.
|
||||
/// Only one allocator is currently supported
|
||||
|
||||
/// Simple bump allocator, never frees
|
||||
use crate::allocator_bump::BPFAllocator;
|
||||
|
||||
/// Use the system heap (test purposes only). This allocator relies on the system heap
|
||||
/// and there is no mechanism to check read-write access privileges
|
||||
/// at the moment. Therefor you must disable memory bounds checking
|
||||
// use allocator_system::BPFAllocator;
|
||||
|
||||
/// Default program heap size, allocators
|
||||
/// are expected to enforce this
|
||||
const DEFAULT_HEAP_SIZE: usize = 32 * 1024;
|
||||
|
||||
pub fn register_helpers(vm: &mut EbpfVmRaw) -> Result<(MemoryRegion), Error> {
|
||||
vm.register_helper_ex("abort", Some(helper_abort_verify), helper_abort, None)?;
|
||||
vm.register_helper_ex(
|
||||
"sol_panic",
|
||||
Some(helper_sol_panic_verify),
|
||||
helper_sol_panic,
|
||||
None,
|
||||
)?;
|
||||
vm.register_helper_ex(
|
||||
"sol_panic_",
|
||||
Some(helper_sol_panic_verify),
|
||||
helper_sol_panic,
|
||||
None,
|
||||
)?;
|
||||
vm.register_helper_ex("sol_log", Some(helper_sol_log_verify), helper_sol_log, None)?;
|
||||
vm.register_helper_ex(
|
||||
"sol_log_",
|
||||
Some(helper_sol_log_verify_),
|
||||
helper_sol_log_,
|
||||
None,
|
||||
)?;
|
||||
vm.register_helper_ex("sol_log_64", None, helper_sol_log_u64, None)?;
|
||||
vm.register_helper_ex("sol_log_64_", None, helper_sol_log_u64, None)?;
|
||||
pub fn register_helpers(vm: &mut EbpfVm) -> Result<(MemoryRegion), Error> {
|
||||
vm.register_helper_ex("abort", helper_abort, None)?;
|
||||
vm.register_helper_ex("sol_panic", helper_sol_panic, None)?;
|
||||
vm.register_helper_ex("sol_panic_", helper_sol_panic, None)?;
|
||||
vm.register_helper_ex("sol_log", helper_sol_log, None)?;
|
||||
vm.register_helper_ex("sol_log_", helper_sol_log, None)?;
|
||||
vm.register_helper_ex("sol_log_64", helper_sol_log_u64, None)?;
|
||||
vm.register_helper_ex("sol_log_64_", helper_sol_log_u64, None)?;
|
||||
|
||||
let heap = vec![0_u8; DEFAULT_HEAP_SIZE];
|
||||
let heap_region = MemoryRegion::new_from_slice(&heap);
|
||||
let context = Box::new(BPFAllocator::new(heap));
|
||||
vm.register_helper_ex(
|
||||
"sol_alloc_free_",
|
||||
None,
|
||||
helper_sol_alloc_free,
|
||||
Some(context),
|
||||
)?;
|
||||
let heap_region = MemoryRegion::new_from_slice(&heap, MM_HEAP_START);
|
||||
let context = Box::new(BPFAllocator::new(heap, MM_HEAP_START));
|
||||
vm.register_helper_ex("sol_alloc_free_", helper_sol_alloc_free, Some(context))?;
|
||||
|
||||
Ok(heap_region)
|
||||
}
|
||||
|
||||
/// Verifies a string passed out of the program
|
||||
fn verify_string(addr: u64, ro_regions: &[MemoryRegion]) -> Result<(()), Error> {
|
||||
for region in ro_regions.iter() {
|
||||
if region.addr <= addr && (addr as u64) < region.addr + region.len {
|
||||
let c_buf: *const c_char = addr as *const c_char;
|
||||
let max_size = region.addr + region.len - addr;
|
||||
unsafe {
|
||||
for i in 0..max_size {
|
||||
if std::ptr::read(c_buf.offset(i as isize)) == 0 {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
}
|
||||
return Err(Error::new(ErrorKind::Other, "Error, Unterminated string"));
|
||||
}
|
||||
}
|
||||
Err(Error::new(
|
||||
ErrorKind::Other,
|
||||
"Error: Load segfault, bad string pointer",
|
||||
))
|
||||
}
|
||||
|
||||
type Context = Option<Box<dyn Any + 'static>>;
|
||||
|
||||
/// Abort helper functions, called when the BPF program calls `abort()`
|
||||
/// The verify function returns an error which will cause the BPF program
|
||||
/// to be halted immediately
|
||||
pub fn helper_abort_verify(
|
||||
_arg1: u64,
|
||||
_arg2: u64,
|
||||
_arg3: u64,
|
||||
_arg4: u64,
|
||||
_arg5: u64,
|
||||
_context: &mut Context,
|
||||
_ro_regions: &[MemoryRegion],
|
||||
_rw_regions: &[MemoryRegion],
|
||||
) -> Result<(()), Error> {
|
||||
Err(Error::new(
|
||||
ErrorKind::Other,
|
||||
"Error: BPF program called abort()!",
|
||||
))
|
||||
}
|
||||
pub fn helper_abort(
|
||||
_arg1: u64,
|
||||
_arg2: u64,
|
||||
_arg3: u64,
|
||||
_arg4: u64,
|
||||
_arg5: u64,
|
||||
_context: &mut Context,
|
||||
) -> u64 {
|
||||
// Never called because its verify function always returns an error
|
||||
0
|
||||
_context: &mut HelperContext,
|
||||
_ro_regions: &[MemoryRegion],
|
||||
_rw_regions: &[MemoryRegion],
|
||||
) -> Result<(u64), Error> {
|
||||
Err(Error::new(
|
||||
ErrorKind::Other,
|
||||
"Error: BPF program called abort()!",
|
||||
))
|
||||
}
|
||||
|
||||
/// Panic helper functions, called when the BPF program calls 'sol_panic_()`
|
||||
/// The verify function returns an error which will cause the BPF program
|
||||
/// to be halted immediately
|
||||
pub fn helper_sol_panic_verify(
|
||||
pub fn helper_sol_panic(
|
||||
file: u64,
|
||||
len: u64,
|
||||
line: u64,
|
||||
column: u64,
|
||||
_arg4: u64,
|
||||
_arg5: u64,
|
||||
_context: &mut Context,
|
||||
_context: &mut HelperContext,
|
||||
ro_regions: &[MemoryRegion],
|
||||
_rw_regions: &[MemoryRegion],
|
||||
) -> Result<(()), Error> {
|
||||
if verify_string(file, ro_regions).is_ok() {
|
||||
let c_buf: *const c_char = file as *const c_char;
|
||||
) -> Result<(u64), Error> {
|
||||
if let Ok(host_addr) = translate_addr(file, len as usize, "Load", 0, ro_regions) {
|
||||
let c_buf: *const c_char = host_addr as *const c_char;
|
||||
let c_str: &CStr = unsafe { CStr::from_ptr(c_buf) };
|
||||
if let Ok(slice) = c_str.to_str() {
|
||||
return Err(Error::new(
|
||||
@ -146,94 +90,51 @@ pub fn helper_sol_panic_verify(
|
||||
}
|
||||
Err(Error::new(ErrorKind::Other, "Error: BPF program Panicked"))
|
||||
}
|
||||
pub fn helper_sol_panic(
|
||||
_arg1: u64,
|
||||
_arg2: u64,
|
||||
_arg3: u64,
|
||||
_arg4: u64,
|
||||
_arg5: u64,
|
||||
_context: &mut Context,
|
||||
) -> u64 {
|
||||
// Never called because its verify function always returns an error
|
||||
0
|
||||
}
|
||||
|
||||
/// Logging helper functions, called when the BPF program calls `sol_log_()` or
|
||||
/// `sol_log_64_()`.
|
||||
pub fn helper_sol_log_verify(
|
||||
addr: u64,
|
||||
_arg2: u64,
|
||||
_arg3: u64,
|
||||
_arg4: u64,
|
||||
_arg5: u64,
|
||||
_context: &mut Context,
|
||||
ro_regions: &[MemoryRegion],
|
||||
_rw_regions: &[MemoryRegion],
|
||||
) -> Result<(()), Error> {
|
||||
verify_string(addr, ro_regions)
|
||||
}
|
||||
pub fn helper_sol_log(
|
||||
addr: u64,
|
||||
_arg2: u64,
|
||||
_arg3: u64,
|
||||
_arg4: u64,
|
||||
_arg5: u64,
|
||||
_context: &mut Context,
|
||||
) -> u64 {
|
||||
let c_buf: *const c_char = addr as *const c_char;
|
||||
let c_str: &CStr = unsafe { CStr::from_ptr(c_buf) };
|
||||
match c_str.to_str() {
|
||||
Ok(slice) => info!("info!: {:?}", slice),
|
||||
Err(e) => warn!("Error: Cannot print invalid string: {}", e),
|
||||
};
|
||||
0
|
||||
}
|
||||
pub fn helper_sol_log_verify_(
|
||||
addr: u64,
|
||||
len: u64,
|
||||
_arg3: u64,
|
||||
_arg4: u64,
|
||||
_arg5: u64,
|
||||
_context: &mut Context,
|
||||
_context: &mut HelperContext,
|
||||
ro_regions: &[MemoryRegion],
|
||||
_rw_regions: &[MemoryRegion],
|
||||
) -> Result<(()), Error> {
|
||||
for region in ro_regions.iter() {
|
||||
if region.addr <= addr && (addr as u64) + len <= region.addr + region.len {
|
||||
return Ok(());
|
||||
) -> Result<(u64), Error> {
|
||||
let host_addr = translate_addr(addr, len as usize, "Load", 0, ro_regions)?;
|
||||
let c_buf: *const c_char = host_addr as *const c_char;
|
||||
unsafe {
|
||||
for i in 0..len {
|
||||
let c = std::ptr::read(c_buf.offset(i as isize));
|
||||
if i == len - 1 || c == 0 {
|
||||
let message =
|
||||
from_utf8(from_raw_parts(host_addr as *const u8, len as usize)).unwrap();
|
||||
println!("info!: {}", message);
|
||||
return Ok(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(Error::new(
|
||||
ErrorKind::Other,
|
||||
"Error: Load segfault, bad string pointer",
|
||||
"Error: Unterminated string logged",
|
||||
))
|
||||
}
|
||||
pub fn helper_sol_log_(
|
||||
addr: u64,
|
||||
len: u64,
|
||||
_arg3: u64,
|
||||
_arg4: u64,
|
||||
_arg5: u64,
|
||||
_context: &mut Context,
|
||||
) -> u64 {
|
||||
let ptr: *const u8 = addr as *const u8;
|
||||
let message = unsafe { from_utf8(from_raw_parts(ptr, len as usize)).unwrap() };
|
||||
info!("info: {:?}", message);
|
||||
0
|
||||
}
|
||||
|
||||
pub fn helper_sol_log_u64(
|
||||
arg1: u64,
|
||||
arg2: u64,
|
||||
arg3: u64,
|
||||
arg4: u64,
|
||||
arg5: u64,
|
||||
_context: &mut Context,
|
||||
) -> u64 {
|
||||
_context: &mut HelperContext,
|
||||
_ro_regions: &[MemoryRegion],
|
||||
_rw_regions: &[MemoryRegion],
|
||||
) -> Result<(u64), Error> {
|
||||
info!(
|
||||
"info!: {:#x}, {:#x}, {:#x}, {:#x}, {:#x}",
|
||||
arg1, arg2, arg3, arg4, arg5
|
||||
);
|
||||
0
|
||||
Ok(0)
|
||||
}
|
||||
|
||||
/// Dynamic memory allocation helper called when the BPF program calls
|
||||
@ -244,24 +145,26 @@ pub fn helper_sol_log_u64(
|
||||
/// to the VM to use for enforcement.
|
||||
pub fn helper_sol_alloc_free(
|
||||
size: u64,
|
||||
free_ptr: u64,
|
||||
free_addr: u64,
|
||||
_arg3: u64,
|
||||
_arg4: u64,
|
||||
_arg5: u64,
|
||||
context: &mut Context,
|
||||
) -> u64 {
|
||||
context: &mut HelperContext,
|
||||
_ro_regions: &[MemoryRegion],
|
||||
_rw_regions: &[MemoryRegion],
|
||||
) -> Result<(u64), Error> {
|
||||
if let Some(context) = context {
|
||||
if let Some(allocator) = context.downcast_mut::<BPFAllocator>() {
|
||||
return {
|
||||
let layout = Layout::from_size_align(size as usize, mem::align_of::<u8>()).unwrap();
|
||||
if free_ptr == 0 {
|
||||
if free_addr == 0 {
|
||||
match allocator.alloc(layout) {
|
||||
Ok(ptr) => ptr as u64,
|
||||
Err(_) => 0,
|
||||
Ok(addr) => Ok(addr as u64),
|
||||
Err(_) => Ok(0),
|
||||
}
|
||||
} else {
|
||||
allocator.dealloc(free_ptr as *mut u8, layout);
|
||||
0
|
||||
allocator.dealloc(free_addr, layout);
|
||||
Ok(0)
|
||||
}
|
||||
};
|
||||
};
|
||||
|
@ -1,6 +1,5 @@
|
||||
pub mod alloc;
|
||||
pub mod allocator_bump;
|
||||
pub mod allocator_system;
|
||||
pub mod bpf_verifier;
|
||||
pub mod helpers;
|
||||
|
||||
@ -14,10 +13,9 @@ macro_rules! solana_bpf_loader {
|
||||
};
|
||||
}
|
||||
|
||||
use alloc::Alloc;
|
||||
use byteorder::{ByteOrder, LittleEndian, WriteBytesExt};
|
||||
use log::*;
|
||||
use solana_rbpf::{EbpfVmRaw, MemoryRegion};
|
||||
use solana_rbpf::{memory_region::MemoryRegion, EbpfVm};
|
||||
use solana_sdk::account::KeyedAccount;
|
||||
use solana_sdk::instruction::InstructionError;
|
||||
use solana_sdk::loader_instruction::LoaderInstruction;
|
||||
@ -26,8 +24,8 @@ use std::io::prelude::*;
|
||||
use std::io::Error;
|
||||
use std::mem;
|
||||
|
||||
pub fn create_vm(prog: &[u8]) -> Result<(EbpfVmRaw, MemoryRegion), Error> {
|
||||
let mut vm = EbpfVmRaw::new(None)?;
|
||||
pub fn create_vm(prog: &[u8]) -> Result<(EbpfVm, MemoryRegion), Error> {
|
||||
let mut vm = EbpfVm::new(None)?;
|
||||
vm.set_verifier(bpf_verifier::check)?;
|
||||
vm.set_max_instruction_count(36000)?;
|
||||
vm.set_elf(&prog)?;
|
||||
@ -168,7 +166,7 @@ mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "Error: Execution exceeded maximum number of instructions")]
|
||||
#[should_panic(expected = "Error: Exceeded maximum number of instructions allowed")]
|
||||
fn test_non_terminating_program() {
|
||||
#[rustfmt::skip]
|
||||
let prog = &[
|
||||
@ -178,7 +176,7 @@ mod tests {
|
||||
];
|
||||
let input = &mut [0x00];
|
||||
|
||||
let mut vm = EbpfVmRaw::new(None).unwrap();
|
||||
let mut vm = EbpfVm::new(None).unwrap();
|
||||
vm.set_verifier(bpf_verifier::check).unwrap();
|
||||
vm.set_max_instruction_count(10).unwrap();
|
||||
vm.set_program(prog).unwrap();
|
||||
|
Reference in New Issue
Block a user