Skip to content

Commit

Permalink
Adds EbpfVm::invoke_function().
Browse files Browse the repository at this point in the history
  • Loading branch information
Lichtso committed Oct 12, 2023
1 parent 47f57fa commit 1f05462
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
10 changes: 2 additions & 8 deletions src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,14 +475,8 @@ impl<'a, 'b, C: ContextObject> Interpreter<'a, 'b, C> {
resolved = true;

self.vm.due_insn_count = self.vm.previous_instruction_meter - self.vm.due_insn_count;
function(
unsafe { (self.vm as *mut _ as *mut u64).offset(get_runtime_environment_key() as isize) as *mut _ },
self.reg[1],
self.reg[2],
self.reg[3],
self.reg[4],
self.reg[5],
);
self.vm.registers[0..6].copy_from_slice(&self.reg[0..6]);
self.vm.invoke_function(function);
self.vm.due_insn_count = 0;
self.reg[0] = match &self.vm.program_result {
ProgramResult::Ok(value) => *value,
Expand Down
17 changes: 16 additions & 1 deletion src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{
error::{EbpfError, ProgramResult},
interpreter::Interpreter,
memory_region::MemoryMapping,
program::{BuiltinProgram, FunctionRegistry, SBPFVersion},
program::{BuiltinFunction, BuiltinProgram, FunctionRegistry, SBPFVersion},
static_analysis::{Analysis, TraceLogEntry},
};
use rand::Rng;
Expand Down Expand Up @@ -421,4 +421,19 @@ impl<'a, C: ContextObject> EbpfVm<'a, C> {
std::mem::swap(&mut result, &mut self.program_result);
(instruction_count, result)
}

/// Invokes a built-in function
pub fn invoke_function(&mut self, function: BuiltinFunction<C>) {
function(
unsafe {
(self as *mut _ as *mut u64).offset(get_runtime_environment_key() as isize)
as *mut _
},
self.registers[1],
self.registers[2],
self.registers[3],
self.registers[4],
self.registers[5],
);
}
}

0 comments on commit 1f05462

Please sign in to comment.