Skip to content

Commit

Permalink
Removes EbpfVm::stack_pointer.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lichtso committed Nov 27, 2024
1 parent 5540b78 commit f7100a0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 22 deletions.
18 changes: 8 additions & 10 deletions src/jit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 3 additions & 12 deletions src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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],
Expand All @@ -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 {
Expand Down

0 comments on commit f7100a0

Please sign in to comment.