From 1f054629219aeec07dc0ca3ce03ad0c573eeb034 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Mei=C3=9Fner?= Date: Thu, 12 Oct 2023 19:00:03 +0200 Subject: [PATCH] Adds EbpfVm::invoke_function(). --- src/interpreter.rs | 10 ++-------- src/vm.rs | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/interpreter.rs b/src/interpreter.rs index 9c489e7af..081dfb790 100644 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -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, diff --git a/src/vm.rs b/src/vm.rs index f91a7de56..9f6dbd0bd 100644 --- a/src/vm.rs +++ b/src/vm.rs @@ -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; @@ -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) { + 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], + ); + } }