diff --git a/src/jit.rs b/src/jit.rs index 587b9cda..04904b5f 100644 --- a/src/jit.rs +++ b/src/jit.rs @@ -255,15 +255,14 @@ struct Jump { enum RuntimeEnvironmentSlot { HostStackPointer = 0, CallDepth = 1, - StackPointer = 2, - ContextObjectPointer = 3, - PreviousInstructionMeter = 4, - DueInsnCount = 5, - StopwatchNumerator = 6, - StopwatchDenominator = 7, - Registers = 8, - ProgramResult = 20, - MemoryMapping = 28, + ContextObjectPointer = 2, + PreviousInstructionMeter = 3, + DueInsnCount = 4, + StopwatchNumerator = 5, + StopwatchDenominator = 6, + Registers = 7, + ProgramResult = 19, + MemoryMapping = 27, } /* Explanation of the Instruction Meter @@ -1747,7 +1746,6 @@ mod tests { check_slot!(env, host_stack_pointer, HostStackPointer); check_slot!(env, call_depth, CallDepth); - check_slot!(env, stack_pointer, StackPointer); check_slot!(env, context_object_pointer, ContextObjectPointer); check_slot!(env, previous_instruction_meter, PreviousInstructionMeter); check_slot!(env, due_insn_count, DueInsnCount); diff --git a/src/vm.rs b/src/vm.rs index 18ad7d5d..3afa01b6 100644 --- a/src/vm.rs +++ b/src/vm.rs @@ -287,13 +287,6 @@ pub struct EbpfVm<'a, C: ContextObject> { /// Incremented on calls and decremented on exits. It's used to enforce /// config.max_call_depth and to know when to terminate execution. pub call_depth: u64, - /// Guest stack pointer (r11). - /// - /// The stack pointer isn't exposed as an actual register. Only sub and add - /// instructions (typically generated by the LLVM backend) are allowed to - /// access it when sbpf_version.dynamic_stack_frames()=true. Its value is only - /// stored here and therefore the register is not tracked in REGISTER_MAP. - pub stack_pointer: u64, /// Pointer to ContextObject pub context_object_pointer: &'a mut C, /// Last return value of instruction_meter.get_remaining() @@ -329,7 +322,8 @@ impl<'a, C: ContextObject> EbpfVm<'a, C> { stack_len: usize, ) -> Self { let config = loader.get_config(); - let stack_pointer = + let mut registers = [0u64; 12]; + registers[ebpf::FRAME_PTR_REG] = ebpf::MM_STACK_START.saturating_add(if sbpf_version.dynamic_stack_frames() { // the stack is fully descending, frames start as empty and change size anytime r11 is modified stack_len @@ -343,13 +337,12 @@ impl<'a, C: ContextObject> EbpfVm<'a, C> { EbpfVm { host_stack_pointer: std::ptr::null_mut(), call_depth: 0, - stack_pointer, context_object_pointer: context_object, previous_instruction_meter: 0, due_insn_count: 0, stopwatch_numerator: 0, stopwatch_denominator: 0, - registers: [0u64; 12], + registers, program_result: ProgramResult::Ok(0), memory_mapping, call_frames: vec![CallFrame::default(); config.max_call_depth], @@ -368,9 +361,7 @@ impl<'a, C: ContextObject> EbpfVm<'a, C> { interpreted: bool, ) -> (u64, ProgramResult) { debug_assert!(Arc::ptr_eq(&self.loader, executable.get_loader())); - // R1 points to beginning of input memory, R10 to the stack of the first frame, R11 is the pc (hidden) self.registers[1] = ebpf::MM_INPUT_START; - self.registers[ebpf::FRAME_PTR_REG] = self.stack_pointer; self.registers[11] = executable.get_entrypoint_instruction_offset() as u64; let config = executable.get_config(); let initial_insn_count = if config.enable_instruction_meter {