Skip to content

Commit

Permalink
CPI harness: migrate to new error mapping logic (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
ravyu-jump authored Sep 6, 2024
1 parent cc79619 commit 05435cd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/utils/vm/err_map.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* DEPRECATED, use utils/err_map.rs instead. Saving this for vm_interp.rs, which will
need more substantial changes to accomodate the newer err_map.rs */
use solana_program_runtime::solana_rbpf::error::EbpfError;
use solana_program_runtime::solana_rbpf::verifier::VerifierError;
const TRUNCATE_ERROR_WORDS: usize = 7;
Expand Down
19 changes: 7 additions & 12 deletions src/vm_cpi_syscall.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use crate::{
load_builtins,
proto::{SyscallContext, SyscallEffects},
utils::{self, vm::mem_regions, vm::STACK_SIZE},
utils::{
err_map::stable_result_to_err_no,
vm::{mem_regions, STACK_SIZE},
},
InstrContext,
};
use solana_bpf_loader_program::syscalls::create_program_runtime_environment_v1;
Expand Down Expand Up @@ -230,19 +233,15 @@ fn execute_vm_cpi_syscall(input: SyscallContext) -> Option<SyscallEffects> {

// Unwrap and return the effects of the syscall
let program_result = vm.program_result;
let program_id = instr_ctx.instruction.program_id;
Some(SyscallEffects {
error: match program_result {
StableResult::Ok(_) => 0,
StableResult::Err(ref ebpf_error) => {
utils::vm::err_map::get_fd_vm_err_code(ebpf_error).into()
}
},
// Register 0 doesn't seem to contain the result, maybe we're missing some code from agave.
// Regardless, the result is available in vm.program_result, so we can return it from there.
r0: match program_result {
StableResult::Ok(n) => n,
StableResult::Err(_) => 0,
},
error: stable_result_to_err_no(program_result, vm.context_object_pointer, &program_id),
cu_avail: vm.context_object_pointer.get_remaining(),
heap,
stack,
Expand All @@ -253,11 +252,7 @@ fn execute_vm_cpi_syscall(input: SyscallContext) -> Option<SyscallEffects> {
.get_log_collector()?
.borrow()
.get_recorded_content()
.iter()
.fold(String::new(), |mut acc, s| {
acc.push_str(s);
acc
})
.join("\n")
.into_bytes(),
..Default::default()
})
Expand Down

0 comments on commit 05435cd

Please sign in to comment.