Update to rbpf v0.1.23 - Use trait objects to convey helper context (#8648)
This commit is contained in:
parent
7fad53b112
commit
8df4d8b905
|
@ -3630,7 +3630,7 @@ dependencies = [
|
||||||
"num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
"num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"solana-logger 1.1.0",
|
"solana-logger 1.1.0",
|
||||||
"solana-sdk 1.1.0",
|
"solana-sdk 1.1.0",
|
||||||
"solana_rbpf 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)",
|
"solana_rbpf 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"thiserror 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
"thiserror 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -4904,7 +4904,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "solana_rbpf"
|
name = "solana_rbpf"
|
||||||
version = "0.1.21"
|
version = "0.1.23"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -6465,7 +6465,7 @@ dependencies = [
|
||||||
"checksum solana_libra_vm_cache_map 0.0.1-sol4 (registry+https://github.com/rust-lang/crates.io-index)" = "37fa2e1f00a87514cd2169149a5f81a89279703b2523979688d6ef84081a4690"
|
"checksum solana_libra_vm_cache_map 0.0.1-sol4 (registry+https://github.com/rust-lang/crates.io-index)" = "37fa2e1f00a87514cd2169149a5f81a89279703b2523979688d6ef84081a4690"
|
||||||
"checksum solana_libra_vm_runtime 0.0.1-sol4 (registry+https://github.com/rust-lang/crates.io-index)" = "ff9f8a7b8212dc4ece5d93f2839896e633c34d7463856e4a555cbcb5c67e9c26"
|
"checksum solana_libra_vm_runtime 0.0.1-sol4 (registry+https://github.com/rust-lang/crates.io-index)" = "ff9f8a7b8212dc4ece5d93f2839896e633c34d7463856e4a555cbcb5c67e9c26"
|
||||||
"checksum solana_libra_vm_runtime_types 0.0.1-sol4 (registry+https://github.com/rust-lang/crates.io-index)" = "254c23c8f30e7c82ae4dc6694e743400d674c66d371b700eec03378ba994f00b"
|
"checksum solana_libra_vm_runtime_types 0.0.1-sol4 (registry+https://github.com/rust-lang/crates.io-index)" = "254c23c8f30e7c82ae4dc6694e743400d674c66d371b700eec03378ba994f00b"
|
||||||
"checksum solana_rbpf 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)" = "053e2a0f1f6c6298bf832493aeacdd6df98efb756a90feabd33caca9c708f2be"
|
"checksum solana_rbpf 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)" = "832c41d1f4184a9554c41aa29dbeb0d5f8873d72cf2be32411668bc5f047a150"
|
||||||
"checksum sourcefile 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4bf77cb82ba8453b42b6ae1d692e4cdc92f9a47beaf89a847c8be83f4e328ad3"
|
"checksum sourcefile 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4bf77cb82ba8453b42b6ae1d692e4cdc92f9a47beaf89a847c8be83f4e328ad3"
|
||||||
"checksum spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
|
"checksum spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
|
||||||
"checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8"
|
"checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8"
|
||||||
|
|
|
@ -1716,7 +1716,7 @@ dependencies = [
|
||||||
"num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"solana-logger 1.1.0",
|
"solana-logger 1.1.0",
|
||||||
"solana-sdk 1.1.0",
|
"solana-sdk 1.1.0",
|
||||||
"solana_rbpf 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)",
|
"solana_rbpf 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"thiserror 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"thiserror 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -1731,7 +1731,7 @@ dependencies = [
|
||||||
"solana-logger 1.1.0",
|
"solana-logger 1.1.0",
|
||||||
"solana-runtime 1.1.0",
|
"solana-runtime 1.1.0",
|
||||||
"solana-sdk 1.1.0",
|
"solana-sdk 1.1.0",
|
||||||
"solana_rbpf 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)",
|
"solana_rbpf 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
"walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -2070,7 +2070,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "solana_rbpf"
|
name = "solana_rbpf"
|
||||||
version = "0.1.21"
|
version = "0.1.23"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -2947,7 +2947,7 @@ dependencies = [
|
||||||
"checksum sha2 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "27044adfd2e1f077f649f59deb9490d3941d674002f7d062870a60ebe9bd47a0"
|
"checksum sha2 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "27044adfd2e1f077f649f59deb9490d3941d674002f7d062870a60ebe9bd47a0"
|
||||||
"checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
|
"checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
|
||||||
"checksum smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ab606a9c5e214920bb66c458cd7be8ef094f813f20fe77a54cc7dbfff220d4b7"
|
"checksum smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ab606a9c5e214920bb66c458cd7be8ef094f813f20fe77a54cc7dbfff220d4b7"
|
||||||
"checksum solana_rbpf 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)" = "053e2a0f1f6c6298bf832493aeacdd6df98efb756a90feabd33caca9c708f2be"
|
"checksum solana_rbpf 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)" = "832c41d1f4184a9554c41aa29dbeb0d5f8873d72cf2be32411668bc5f047a150"
|
||||||
"checksum sourcefile 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4bf77cb82ba8453b42b6ae1d692e4cdc92f9a47beaf89a847c8be83f4e328ad3"
|
"checksum sourcefile 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4bf77cb82ba8453b42b6ae1d692e4cdc92f9a47beaf89a847c8be83f4e328ad3"
|
||||||
"checksum spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
|
"checksum spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
|
||||||
"checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8"
|
"checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8"
|
||||||
|
|
|
@ -26,7 +26,7 @@ solana-bpf-loader-program = { path = "../bpf_loader", version = "1.1.0" }
|
||||||
solana-logger = { path = "../../logger", version = "1.1.0" }
|
solana-logger = { path = "../../logger", version = "1.1.0" }
|
||||||
solana-runtime = { path = "../../runtime", version = "1.1.0" }
|
solana-runtime = { path = "../../runtime", version = "1.1.0" }
|
||||||
solana-sdk = { path = "../../sdk", version = "1.1.0" }
|
solana-sdk = { path = "../../sdk", version = "1.1.0" }
|
||||||
solana_rbpf = "=0.1.21"
|
solana_rbpf = "=0.1.23"
|
||||||
|
|
||||||
[[bench]]
|
[[bench]]
|
||||||
name = "bpf_loader"
|
name = "bpf_loader"
|
||||||
|
|
|
@ -17,7 +17,8 @@ num-derive = { version = "0.3" }
|
||||||
num-traits = { version = "0.2" }
|
num-traits = { version = "0.2" }
|
||||||
solana-logger = { path = "../../logger", version = "1.1.0" }
|
solana-logger = { path = "../../logger", version = "1.1.0" }
|
||||||
solana-sdk = { path = "../../sdk", version = "1.1.0" }
|
solana-sdk = { path = "../../sdk", version = "1.1.0" }
|
||||||
solana_rbpf = "=0.1.21"
|
solana_rbpf = "=0.1.23"
|
||||||
|
|
||||||
thiserror = "1.0"
|
thiserror = "1.0"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
|
|
|
@ -3,7 +3,7 @@ use alloc::Alloc;
|
||||||
use libc::c_char;
|
use libc::c_char;
|
||||||
use log::*;
|
use log::*;
|
||||||
use solana_rbpf::{
|
use solana_rbpf::{
|
||||||
ebpf::{HelperContext, MM_HEAP_START},
|
ebpf::{HelperObject, MM_HEAP_START},
|
||||||
memory_region::{translate_addr, MemoryRegion},
|
memory_region::{translate_addr, MemoryRegion},
|
||||||
EbpfVm,
|
EbpfVm,
|
||||||
};
|
};
|
||||||
|
@ -11,7 +11,7 @@ use std::{
|
||||||
alloc::Layout,
|
alloc::Layout,
|
||||||
ffi::CStr,
|
ffi::CStr,
|
||||||
io::{Error, ErrorKind},
|
io::{Error, ErrorKind},
|
||||||
mem,
|
mem::align_of,
|
||||||
slice::from_raw_parts,
|
slice::from_raw_parts,
|
||||||
str::from_utf8,
|
str::from_utf8,
|
||||||
};
|
};
|
||||||
|
@ -29,18 +29,22 @@ use crate::allocator_bump::BPFAllocator;
|
||||||
const DEFAULT_HEAP_SIZE: usize = 32 * 1024;
|
const DEFAULT_HEAP_SIZE: usize = 32 * 1024;
|
||||||
|
|
||||||
pub fn register_helpers(vm: &mut EbpfVm) -> Result<MemoryRegion, Error> {
|
pub fn register_helpers(vm: &mut EbpfVm) -> Result<MemoryRegion, Error> {
|
||||||
vm.register_helper_ex("abort", helper_abort, None)?;
|
vm.register_helper_ex("abort", helper_abort)?;
|
||||||
vm.register_helper_ex("sol_panic", helper_sol_panic, None)?;
|
vm.register_helper_ex("sol_panic", helper_sol_panic)?;
|
||||||
vm.register_helper_ex("sol_panic_", helper_sol_panic, None)?;
|
vm.register_helper_ex("sol_panic_", helper_sol_panic)?;
|
||||||
vm.register_helper_ex("sol_log", helper_sol_log, None)?;
|
vm.register_helper_ex("sol_log", helper_sol_log)?;
|
||||||
vm.register_helper_ex("sol_log_", helper_sol_log, None)?;
|
vm.register_helper_ex("sol_log_", helper_sol_log)?;
|
||||||
vm.register_helper_ex("sol_log_64", helper_sol_log_u64, None)?;
|
vm.register_helper_ex("sol_log_64", helper_sol_log_u64)?;
|
||||||
vm.register_helper_ex("sol_log_64_", helper_sol_log_u64, None)?;
|
vm.register_helper_ex("sol_log_64_", helper_sol_log_u64)?;
|
||||||
|
|
||||||
let heap = vec![0_u8; DEFAULT_HEAP_SIZE];
|
let heap = vec![0_u8; DEFAULT_HEAP_SIZE];
|
||||||
let heap_region = MemoryRegion::new_from_slice(&heap, MM_HEAP_START);
|
let heap_region = MemoryRegion::new_from_slice(&heap, MM_HEAP_START);
|
||||||
let context = Box::new(BPFAllocator::new(heap, MM_HEAP_START));
|
vm.register_helper_with_context_ex(
|
||||||
vm.register_helper_ex("sol_alloc_free_", helper_sol_alloc_free, Some(context))?;
|
"sol_alloc_free_",
|
||||||
|
Box::new(HelperSolAllocFree {
|
||||||
|
allocator: BPFAllocator::new(heap, MM_HEAP_START),
|
||||||
|
}),
|
||||||
|
)?;
|
||||||
|
|
||||||
Ok(heap_region)
|
Ok(heap_region)
|
||||||
}
|
}
|
||||||
|
@ -54,7 +58,6 @@ pub fn helper_abort(
|
||||||
_arg3: u64,
|
_arg3: u64,
|
||||||
_arg4: u64,
|
_arg4: u64,
|
||||||
_arg5: u64,
|
_arg5: u64,
|
||||||
_context: &mut HelperContext,
|
|
||||||
_ro_regions: &[MemoryRegion],
|
_ro_regions: &[MemoryRegion],
|
||||||
_rw_regions: &[MemoryRegion],
|
_rw_regions: &[MemoryRegion],
|
||||||
) -> Result<u64, Error> {
|
) -> Result<u64, Error> {
|
||||||
|
@ -73,7 +76,6 @@ pub fn helper_sol_panic(
|
||||||
line: u64,
|
line: u64,
|
||||||
column: u64,
|
column: u64,
|
||||||
_arg5: u64,
|
_arg5: u64,
|
||||||
_context: &mut HelperContext,
|
|
||||||
ro_regions: &[MemoryRegion],
|
ro_regions: &[MemoryRegion],
|
||||||
_rw_regions: &[MemoryRegion],
|
_rw_regions: &[MemoryRegion],
|
||||||
) -> Result<u64, Error> {
|
) -> Result<u64, Error> {
|
||||||
|
@ -99,7 +101,6 @@ pub fn helper_sol_log(
|
||||||
_arg3: u64,
|
_arg3: u64,
|
||||||
_arg4: u64,
|
_arg4: u64,
|
||||||
_arg5: u64,
|
_arg5: u64,
|
||||||
_context: &mut HelperContext,
|
|
||||||
ro_regions: &[MemoryRegion],
|
ro_regions: &[MemoryRegion],
|
||||||
_rw_regions: &[MemoryRegion],
|
_rw_regions: &[MemoryRegion],
|
||||||
) -> Result<u64, Error> {
|
) -> Result<u64, Error> {
|
||||||
|
@ -132,7 +133,6 @@ pub fn helper_sol_log_u64(
|
||||||
arg3: u64,
|
arg3: u64,
|
||||||
arg4: u64,
|
arg4: u64,
|
||||||
arg5: u64,
|
arg5: u64,
|
||||||
_context: &mut HelperContext,
|
|
||||||
_ro_regions: &[MemoryRegion],
|
_ro_regions: &[MemoryRegion],
|
||||||
_rw_regions: &[MemoryRegion],
|
_rw_regions: &[MemoryRegion],
|
||||||
) -> Result<u64, Error> {
|
) -> Result<u64, Error> {
|
||||||
|
@ -151,31 +151,29 @@ pub fn helper_sol_log_u64(
|
||||||
/// memory chunk is given to the allocator during allocator creation and
|
/// memory chunk is given to the allocator during allocator creation and
|
||||||
/// information about that memory (start address and size) is passed
|
/// information about that memory (start address and size) is passed
|
||||||
/// to the VM to use for enforcement.
|
/// to the VM to use for enforcement.
|
||||||
pub fn helper_sol_alloc_free(
|
pub struct HelperSolAllocFree {
|
||||||
size: u64,
|
allocator: BPFAllocator,
|
||||||
free_addr: u64,
|
}
|
||||||
_arg3: u64,
|
impl HelperObject for HelperSolAllocFree {
|
||||||
_arg4: u64,
|
fn call(
|
||||||
_arg5: u64,
|
&mut self,
|
||||||
context: &mut HelperContext,
|
size: u64,
|
||||||
_ro_regions: &[MemoryRegion],
|
free_addr: u64,
|
||||||
_rw_regions: &[MemoryRegion],
|
_arg3: u64,
|
||||||
) -> Result<u64, Error> {
|
_arg4: u64,
|
||||||
if let Some(context) = context {
|
_arg5: u64,
|
||||||
if let Some(allocator) = context.downcast_mut::<BPFAllocator>() {
|
_ro_regions: &[MemoryRegion],
|
||||||
return {
|
_rw_regions: &[MemoryRegion],
|
||||||
let layout = Layout::from_size_align(size as usize, mem::align_of::<u8>()).unwrap();
|
) -> Result<u64, Error> {
|
||||||
if free_addr == 0 {
|
let layout = Layout::from_size_align(size as usize, align_of::<u8>()).unwrap();
|
||||||
match allocator.alloc(layout) {
|
if free_addr == 0 {
|
||||||
Ok(addr) => Ok(addr as u64),
|
match self.allocator.alloc(layout) {
|
||||||
Err(_) => Ok(0),
|
Ok(addr) => Ok(addr as u64),
|
||||||
}
|
Err(_) => Ok(0),
|
||||||
} else {
|
}
|
||||||
allocator.dealloc(free_addr, layout);
|
} else {
|
||||||
Ok(0)
|
self.allocator.dealloc(free_addr, layout);
|
||||||
}
|
Ok(0)
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
}
|
|
||||||
panic!("Failed to get alloc_free context");
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue