diff --git a/src/error.rs b/src/error.rs index 49ad5f4f2..513ee9410 100644 --- a/src/error.rs +++ b/src/error.rs @@ -33,28 +33,26 @@ pub enum EbpfError { #[error("function #{0} was already registered")] FunctionAlreadyRegistered(usize), /// Exceeded max BPF to BPF call depth - #[error("exceeded max BPF to BPF call depth of {1} at BPF instruction #{0}")] - CallDepthExceeded(usize, usize), + #[error("exceeded max BPF to BPF call depth")] + CallDepthExceeded, /// Attempt to exit from root call frame #[error("attempted to exit root call frame")] ExitRootCallFrame, /// Divide by zero" - #[error("divide by zero at BPF instruction {0}")] - DivideByZero(usize), + #[error("divide by zero at BPF instruction")] + DivideByZero, /// Divide overflow - #[error("division overflow at BPF instruction {0}")] - DivideOverflow(usize), + #[error("division overflow at BPF instruction")] + DivideOverflow, /// Exceeded max instructions allowed - #[error("attempted to execute past the end of the text segment at BPF instruction #{0}")] - ExecutionOverrun(usize), + #[error("attempted to execute past the end of the text segment at BPF instruction")] + ExecutionOverrun, /// Attempt to call to an address outside the text segment - #[error( - "callx at BPF instruction {0} attempted to call outside of the text segment to addr 0x{1:x}" - )] - CallOutsideTextSegment(usize, u64), + #[error("callx attempted to call outside of the text segment")] + CallOutsideTextSegment, /// Exceeded max instructions allowed - #[error("exceeded CUs meter at BPF instruction #{0}")] - ExceededMaxInstructions(usize), + #[error("exceeded CUs meter at BPF instruction")] + ExceededMaxInstructions, /// Program has not been JIT-compiled #[error("program has not been JIT-compiled")] JitNotCompiled, @@ -75,11 +73,11 @@ pub enum EbpfError { )] StackAccessViolation(usize, AccessType, u64, u64, i64), /// Invalid instruction - #[error("invalid BPF instruction at {0}")] - InvalidInstruction(usize), + #[error("invalid BPF instruction")] + InvalidInstruction, /// Unsupported instruction - #[error("unsupported BPF instruction at {0}")] - UnsupportedInstruction(usize), + #[error("unsupported BPF instruction")] + UnsupportedInstruction, /// Compilation is too big to fit #[error("Compilation exhausted text segment at BPF instruction {0}")] ExhaustedTextSegment(usize), diff --git a/src/interpreter.rs b/src/interpreter.rs index ae0b90ea4..cb0679787 100644 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -52,20 +52,14 @@ macro_rules! throw_error { $self.vm.program_result = ProgramResult::Err($err); return false; }}; - (DivideByZero; $self:expr, $pc:expr, $src:expr, $ty:ty) => { + (DivideByZero; $self:expr, $src:expr, $ty:ty) => { if $src as $ty == 0 { - throw_error!( - $self, - EbpfError::DivideByZero($pc + ebpf::ELF_INSN_DUMP_OFFSET) - ); + throw_error!($self, EbpfError::DivideByZero); } }; - (DivideOverflow; $self:expr, $pc:expr, $src:expr, $dst:expr, $ty:ty) => { + (DivideOverflow; $self:expr, $src:expr, $dst:expr, $ty:ty) => { if $dst as $ty == <$ty>::MIN && $src as $ty == -1 { - throw_error!( - $self, - EbpfError::DivideOverflow($pc + ebpf::ELF_INSN_DUMP_OFFSET) - ); + throw_error!($self, EbpfError::DivideOverflow); } }; } @@ -121,7 +115,7 @@ impl<'a, 'b, C: ContextObject> Interpreter<'a, 'b, C> { } } - fn check_pc(&mut self, current_pc: usize) -> bool { + fn check_pc(&mut self) -> bool { if self .pc .checked_mul(ebpf::INSN_SIZE) @@ -130,13 +124,7 @@ impl<'a, 'b, C: ContextObject> Interpreter<'a, 'b, C> { { true } else { - throw_error!( - self, - EbpfError::CallOutsideTextSegment( - current_pc + ebpf::ELF_INSN_DUMP_OFFSET, - self.program_vm_addr + (self.pc * ebpf::INSN_SIZE) as u64, - ) - ); + throw_error!(self, EbpfError::CallOutsideTextSegment); } } @@ -156,13 +144,7 @@ impl<'a, 'b, C: ContextObject> Interpreter<'a, 'b, C> { self.vm.call_depth += 1; if self.vm.call_depth as usize == config.max_call_depth { - throw_error!( - self, - EbpfError::CallDepthExceeded( - self.pc + ebpf::ELF_INSN_DUMP_OFFSET - 1, - config.max_call_depth, - ) - ); + throw_error!(self, EbpfError::CallDepthExceeded); } if !self.executable.get_sbpf_version().dynamic_stack_frames() { @@ -183,12 +165,11 @@ impl<'a, 'b, C: ContextObject> Interpreter<'a, 'b, C> { pub fn step(&mut self) -> bool { let config = &self.executable.get_config(); - let mut instruction_width = 1; self.due_insn_count += 1; let pc = self.pc; - self.pc += instruction_width; + self.pc += 1; if self.pc * ebpf::INSN_SIZE > self.program.len() { - throw_error!(self, EbpfError::ExecutionOverrun(pc + ebpf::ELF_INSN_DUMP_OFFSET)); + throw_error!(self, EbpfError::ExecutionOverrun); } let mut insn = ebpf::get_insn_unchecked(self.program, pc); let dst = insn.dst as usize; @@ -214,7 +195,6 @@ impl<'a, 'b, C: ContextObject> Interpreter<'a, 'b, C> { ebpf::LD_DW_IMM => { ebpf::augment_lddw_unchecked(self.program, &mut insn); - instruction_width = 2; self.pc += 1; self.reg[dst] = insn.imm as u64; }, @@ -286,7 +266,7 @@ impl<'a, 'b, C: ContextObject> Interpreter<'a, 'b, C> { ebpf::MUL32_REG if !self.executable.get_sbpf_version().enable_pqr() => self.reg[dst] = (self.reg[dst] as i32).wrapping_mul(self.reg[src] as i32) as u64, ebpf::DIV32_IMM if !self.executable.get_sbpf_version().enable_pqr() => self.reg[dst] = (self.reg[dst] as u32 / insn.imm as u32) as u64, ebpf::DIV32_REG if !self.executable.get_sbpf_version().enable_pqr() => { - throw_error!(DivideByZero; self, pc, self.reg[src], u32); + throw_error!(DivideByZero; self, self.reg[src], u32); self.reg[dst] = (self.reg[dst] as u32 / self.reg[src] as u32) as u64; }, ebpf::OR32_IMM => self.reg[dst] = (self.reg[dst] as u32 | insn.imm as u32) as u64, @@ -300,7 +280,7 @@ impl<'a, 'b, C: ContextObject> Interpreter<'a, 'b, C> { ebpf::NEG32 if self.executable.get_sbpf_version().enable_neg() => self.reg[dst] = (self.reg[dst] as i32).wrapping_neg() as u64 & (u32::MAX as u64), ebpf::MOD32_IMM if !self.executable.get_sbpf_version().enable_pqr() => self.reg[dst] = (self.reg[dst] as u32 % insn.imm as u32) as u64, ebpf::MOD32_REG if !self.executable.get_sbpf_version().enable_pqr() => { - throw_error!(DivideByZero; self, pc, self.reg[src], u32); + throw_error!(DivideByZero; self, self.reg[src], u32); self.reg[dst] = (self.reg[dst] as u32 % self.reg[src] as u32) as u64; }, ebpf::XOR32_IMM => self.reg[dst] = (self.reg[dst] as u32 ^ insn.imm as u32) as u64, @@ -315,7 +295,7 @@ impl<'a, 'b, C: ContextObject> Interpreter<'a, 'b, C> { 32 => (self.reg[dst] as u32).to_le() as u64, 64 => self.reg[dst].to_le(), _ => { - throw_error!(self, EbpfError::InvalidInstruction(pc + ebpf::ELF_INSN_DUMP_OFFSET)); + throw_error!(self, EbpfError::InvalidInstruction); } }; }, @@ -325,7 +305,7 @@ impl<'a, 'b, C: ContextObject> Interpreter<'a, 'b, C> { 32 => (self.reg[dst] as u32).to_be() as u64, 64 => self.reg[dst].to_be(), _ => { - throw_error!(self, EbpfError::InvalidInstruction(pc + ebpf::ELF_INSN_DUMP_OFFSET)); + throw_error!(self, EbpfError::InvalidInstruction); } }; }, @@ -343,7 +323,7 @@ impl<'a, 'b, C: ContextObject> Interpreter<'a, 'b, C> { ebpf::MUL64_REG if !self.executable.get_sbpf_version().enable_pqr() => self.reg[dst] = self.reg[dst].wrapping_mul(self.reg[src]), ebpf::DIV64_IMM if !self.executable.get_sbpf_version().enable_pqr() => self.reg[dst] /= insn.imm as u64, ebpf::DIV64_REG if !self.executable.get_sbpf_version().enable_pqr() => { - throw_error!(DivideByZero; self, pc, self.reg[src], u64); + throw_error!(DivideByZero; self, self.reg[src], u64); self.reg[dst] /= self.reg[src]; }, ebpf::OR64_IMM => self.reg[dst] |= insn.imm as u64, @@ -357,7 +337,7 @@ impl<'a, 'b, C: ContextObject> Interpreter<'a, 'b, C> { ebpf::NEG64 if self.executable.get_sbpf_version().enable_neg() => self.reg[dst] = (self.reg[dst] as i64).wrapping_neg() as u64, ebpf::MOD64_IMM if !self.executable.get_sbpf_version().enable_pqr() => self.reg[dst] %= insn.imm as u64, ebpf::MOD64_REG if !self.executable.get_sbpf_version().enable_pqr() => { - throw_error!(DivideByZero; self, pc, self.reg[src], u64); + throw_error!(DivideByZero; self, self.reg[src], u64); self.reg[dst] %= self.reg[src]; }, ebpf::XOR64_IMM => self.reg[dst] ^= insn.imm as u64, @@ -383,64 +363,64 @@ impl<'a, 'b, C: ContextObject> Interpreter<'a, 'b, C> { self.reg[dst] = (self.reg[dst] as u32 / insn.imm as u32) as u64; } ebpf::UDIV32_REG if self.executable.get_sbpf_version().enable_pqr() => { - throw_error!(DivideByZero; self, pc, self.reg[src], u32); + throw_error!(DivideByZero; self, self.reg[src], u32); self.reg[dst] = (self.reg[dst] as u32 / self.reg[src] as u32) as u64; }, ebpf::UDIV64_IMM if self.executable.get_sbpf_version().enable_pqr() => { self.reg[dst] /= insn.imm as u64; } ebpf::UDIV64_REG if self.executable.get_sbpf_version().enable_pqr() => { - throw_error!(DivideByZero; self, pc, self.reg[src], u64); + throw_error!(DivideByZero; self, self.reg[src], u64); self.reg[dst] /= self.reg[src]; }, ebpf::UREM32_IMM if self.executable.get_sbpf_version().enable_pqr() => { self.reg[dst] = (self.reg[dst] as u32 % insn.imm as u32) as u64; } ebpf::UREM32_REG if self.executable.get_sbpf_version().enable_pqr() => { - throw_error!(DivideByZero; self, pc, self.reg[src], u32); + throw_error!(DivideByZero; self, self.reg[src], u32); self.reg[dst] = (self.reg[dst] as u32 % self.reg[src] as u32) as u64; }, ebpf::UREM64_IMM if self.executable.get_sbpf_version().enable_pqr() => { self.reg[dst] %= insn.imm as u64; } ebpf::UREM64_REG if self.executable.get_sbpf_version().enable_pqr() => { - throw_error!(DivideByZero; self, pc, self.reg[src], u64); + throw_error!(DivideByZero; self, self.reg[src], u64); self.reg[dst] %= self.reg[src]; }, ebpf::SDIV32_IMM if self.executable.get_sbpf_version().enable_pqr() => { - throw_error!(DivideOverflow; self, pc, insn.imm, self.reg[dst], i32); + throw_error!(DivideOverflow; self, insn.imm, self.reg[dst], i32); self.reg[dst] = (self.reg[dst] as i32 / insn.imm as i32) as u64; } ebpf::SDIV32_REG if self.executable.get_sbpf_version().enable_pqr() => { - throw_error!(DivideByZero; self, pc, self.reg[src], i32); - throw_error!(DivideOverflow; self, pc, self.reg[src], self.reg[dst], i32); + throw_error!(DivideByZero; self, self.reg[src], i32); + throw_error!(DivideOverflow; self, self.reg[src], self.reg[dst], i32); self.reg[dst] = (self.reg[dst] as i32 / self.reg[src] as i32) as u64; }, ebpf::SDIV64_IMM if self.executable.get_sbpf_version().enable_pqr() => { - throw_error!(DivideOverflow; self, pc, insn.imm, self.reg[dst], i64); + throw_error!(DivideOverflow; self, insn.imm, self.reg[dst], i64); self.reg[dst] = (self.reg[dst] as i64 / insn.imm) as u64; } ebpf::SDIV64_REG if self.executable.get_sbpf_version().enable_pqr() => { - throw_error!(DivideByZero; self, pc, self.reg[src], i64); - throw_error!(DivideOverflow; self, pc, self.reg[src], self.reg[dst], i64); + throw_error!(DivideByZero; self, self.reg[src], i64); + throw_error!(DivideOverflow; self, self.reg[src], self.reg[dst], i64); self.reg[dst] = (self.reg[dst] as i64 / self.reg[src] as i64) as u64; }, ebpf::SREM32_IMM if self.executable.get_sbpf_version().enable_pqr() => { - throw_error!(DivideOverflow; self, pc, insn.imm, self.reg[dst], i32); + throw_error!(DivideOverflow; self, insn.imm, self.reg[dst], i32); self.reg[dst] = (self.reg[dst] as i32 % insn.imm as i32) as u64; } ebpf::SREM32_REG if self.executable.get_sbpf_version().enable_pqr() => { - throw_error!(DivideByZero; self, pc, self.reg[src], i32); - throw_error!(DivideOverflow; self, pc, self.reg[src], self.reg[dst], i32); + throw_error!(DivideByZero; self, self.reg[src], i32); + throw_error!(DivideOverflow; self, self.reg[src], self.reg[dst], i32); self.reg[dst] = (self.reg[dst] as i32 % self.reg[src] as i32) as u64; }, ebpf::SREM64_IMM if self.executable.get_sbpf_version().enable_pqr() => { - throw_error!(DivideOverflow; self, pc, insn.imm, self.reg[dst], i64); + throw_error!(DivideOverflow; self, insn.imm, self.reg[dst], i64); self.reg[dst] = (self.reg[dst] as i64 % insn.imm) as u64; } ebpf::SREM64_REG if self.executable.get_sbpf_version().enable_pqr() => { - throw_error!(DivideByZero; self, pc, self.reg[src], i64); - throw_error!(DivideOverflow; self, pc, self.reg[src], self.reg[dst], i64); + throw_error!(DivideByZero; self, self.reg[src], i64); + throw_error!(DivideOverflow; self, self.reg[src], self.reg[dst], i64); self.reg[dst] = (self.reg[dst] as i64 % self.reg[src] as i64) as u64; }, @@ -479,15 +459,15 @@ impl<'a, 'b, C: ContextObject> Interpreter<'a, 'b, C> { return false; } if target_pc < self.program_vm_addr { - throw_error!(self, EbpfError::CallOutsideTextSegment(pc + ebpf::ELF_INSN_DUMP_OFFSET, target_pc / ebpf::INSN_SIZE as u64 * ebpf::INSN_SIZE as u64)); + throw_error!(self, EbpfError::CallOutsideTextSegment); } self.pc = (target_pc - self.program_vm_addr) as usize / ebpf::INSN_SIZE; - if !self.check_pc(pc) { + if !self.check_pc() { return false; } if self.executable.get_sbpf_version().static_syscalls() && self.executable.get_function_registry().lookup_by_key(self.pc as u32).is_none() { self.due_insn_count += 1; - throw_error!(self, EbpfError::UnsupportedInstruction(self.pc + ebpf::ELF_INSN_DUMP_OFFSET)); + throw_error!(self, EbpfError::UnsupportedInstruction); } }, @@ -538,21 +518,21 @@ impl<'a, 'b, C: ContextObject> Interpreter<'a, 'b, C> { return false; } self.pc = target_pc; - if !self.check_pc(pc) { + if !self.check_pc() { return false; } } } if !resolved { - throw_error!(self, EbpfError::UnsupportedInstruction(pc + ebpf::ELF_INSN_DUMP_OFFSET)); + throw_error!(self, EbpfError::UnsupportedInstruction); } } ebpf::EXIT => { if self.vm.call_depth == 0 { if config.enable_instruction_meter && self.due_insn_count > self.vm.previous_instruction_meter { - throw_error!(self, EbpfError::ExceededMaxInstructions(pc + ebpf::ELF_INSN_DUMP_OFFSET)); + throw_error!(self, EbpfError::ExceededMaxInstructions); } self.vm.program_result = ProgramResult::Ok(self.reg[0]); return false; @@ -570,16 +550,15 @@ impl<'a, 'b, C: ContextObject> Interpreter<'a, 'b, C> { config.stack_frame_size * if config.enable_stack_frame_gaps { 2 } else { 1 }; self.vm.stack_pointer -= stack_frame_size as u64; } - if !self.check_pc(pc) { + if !self.check_pc() { return false; } } - _ => throw_error!(self, EbpfError::UnsupportedInstruction(pc + ebpf::ELF_INSN_DUMP_OFFSET)), + _ => throw_error!(self, EbpfError::UnsupportedInstruction), } if config.enable_instruction_meter && self.due_insn_count >= self.vm.previous_instruction_meter { - // Use `pc + instruction_width` instead of `self.pc` here because jumps and calls don't continue at the end of this instruction - throw_error!(self, EbpfError::ExceededMaxInstructions(pc + instruction_width + ebpf::ELF_INSN_DUMP_OFFSET)); + throw_error!(self, EbpfError::ExceededMaxInstructions); } true diff --git a/src/jit.rs b/src/jit.rs index d54a2b172..345cc8851 100644 --- a/src/jit.rs +++ b/src/jit.rs @@ -528,7 +528,7 @@ impl<'a, C: ContextObject> JitCompiler<'a, C> { } 64 => {} _ => { - return Err(EbpfError::InvalidInstruction(self.pc + ebpf::ELF_INSN_DUMP_OFFSET)); + return Err(EbpfError::InvalidInstruction); } } }, @@ -541,7 +541,7 @@ impl<'a, C: ContextObject> JitCompiler<'a, C> { 32 => self.emit_ins(X86Instruction::bswap(OperandSize::S32, dst)), 64 => self.emit_ins(X86Instruction::bswap(OperandSize::S64, dst)), _ => { - return Err(EbpfError::InvalidInstruction(self.pc + ebpf::ELF_INSN_DUMP_OFFSET)); + return Err(EbpfError::InvalidInstruction); } } }, @@ -711,7 +711,7 @@ impl<'a, C: ContextObject> JitCompiler<'a, C> { self.emit_ins(X86Instruction::return_near()); }, - _ => return Err(EbpfError::UnsupportedInstruction(self.pc + ebpf::ELF_INSN_DUMP_OFFSET)), + _ => return Err(EbpfError::UnsupportedInstruction), } self.pc += 1; @@ -722,8 +722,7 @@ impl<'a, C: ContextObject> JitCompiler<'a, C> { return Err(EbpfError::ExhaustedTextSegment(self.pc)); } self.emit_validate_and_profile_instruction_count(true, Some(self.pc + 2)); - self.emit_ins(X86Instruction::load_immediate(OperandSize::S64, R11, self.pc as i64)); - self.emit_set_exception_kind(EbpfError::ExecutionOverrun(0)); + self.emit_set_exception_kind(EbpfError::ExecutionOverrun); self.emit_ins(X86Instruction::jump_immediate(self.relative_to_anchor(ANCHOR_THROW_EXCEPTION, 5))); self.resolve_jumps(); @@ -1232,7 +1231,7 @@ impl<'a, C: ContextObject> JitCompiler<'a, C> { self.emit_ins(X86Instruction::test(size, R11, R11, None)); // r11 == 0 } - // MIN / -1, raise EbpfError::DivideOverflow(pc) + // MIN / -1, raise EbpfError::DivideOverflow self.emit_ins(X86Instruction::load_immediate(OperandSize::S64, R11, self.pc as i64)); self.emit_ins(X86Instruction::conditional_jump_immediate(0x84, self.relative_to_anchor(ANCHOR_DIV_OVERFLOW, 6))); } @@ -1343,15 +1342,12 @@ impl<'a, C: ContextObject> JitCompiler<'a, C> { // Handler for EbpfError::ExceededMaxInstructions self.set_anchor(ANCHOR_CALL_EXCEEDED_MAX_INSTRUCTIONS); - self.emit_set_exception_kind(EbpfError::ExceededMaxInstructions(0)); + self.emit_set_exception_kind(EbpfError::ExceededMaxInstructions); self.emit_ins(X86Instruction::mov(OperandSize::S64, ARGUMENT_REGISTERS[0], R11)); // R11 = instruction_meter; // Fall through // Epilogue for errors self.set_anchor(ANCHOR_THROW_EXCEPTION_UNCHECKED); - self.emit_ins(X86Instruction::lea(OperandSize::S64, RBP, R10, Some(X86IndirectAccess::Offset(self.slot_on_environment_stack(RuntimeEnvironmentSlot::ProgramResult) + std::mem::size_of::() as i32)))); - self.emit_ins(X86Instruction::store(OperandSize::S64, R11, R10, X86IndirectAccess::Offset(std::mem::size_of::() as i32))); // result.pc = self.pc; - self.emit_ins(X86Instruction::alu(OperandSize::S64, 0x81, 0, R10, ebpf::ELF_INSN_DUMP_OFFSET as i64, Some(X86IndirectAccess::Offset(std::mem::size_of::() as i32)))); // result.pc += ebpf::ELF_INSN_DUMP_OFFSET; self.emit_ins(X86Instruction::jump_immediate(self.relative_to_anchor(ANCHOR_EPILOGUE, 5))); // Quit gracefully @@ -1370,29 +1366,28 @@ impl<'a, C: ContextObject> JitCompiler<'a, C> { // Handler for EbpfError::AccessViolation self.set_anchor(ANCHOR_ACCESS_VIOLATION); - self.emit_ins(X86Instruction::load(OperandSize::S64, RBP, R10, X86IndirectAccess::Offset(self.slot_on_environment_stack(RuntimeEnvironmentSlot::ProgramResult) + std::mem::size_of::() as i32))); // err = *env.result.err; + self.emit_ins(X86Instruction::store(OperandSize::S64, R11, R10, X86IndirectAccess::Offset(std::mem::size_of::() as i32 * 2))); // result.pc = self.pc; + self.emit_ins(X86Instruction::alu(OperandSize::S64, 0x81, 0, R10, ebpf::ELF_INSN_DUMP_OFFSET as i64, Some(X86IndirectAccess::Offset(std::mem::size_of::() as i32 * 2)))); // result.pc += ebpf::ELF_INSN_DUMP_OFFSET; self.emit_ins(X86Instruction::jump_immediate(self.relative_to_anchor(ANCHOR_THROW_EXCEPTION, 5))); // Handler for EbpfError::CallDepthExceeded self.set_anchor(ANCHOR_CALL_DEPTH_EXCEEDED); - self.emit_set_exception_kind(EbpfError::CallDepthExceeded(0, 0)); - self.emit_ins(X86Instruction::store_immediate(OperandSize::S64, R10, X86IndirectAccess::Offset((std::mem::size_of::() * 2) as i32), self.config.max_call_depth as i64)); // depth = jit.config.max_call_depth; + self.emit_set_exception_kind(EbpfError::CallDepthExceeded); self.emit_ins(X86Instruction::jump_immediate(self.relative_to_anchor(ANCHOR_THROW_EXCEPTION, 5))); // Handler for EbpfError::CallOutsideTextSegment self.set_anchor(ANCHOR_CALL_OUTSIDE_TEXT_SEGMENT); - self.emit_set_exception_kind(EbpfError::CallOutsideTextSegment(0, 0)); - self.emit_ins(X86Instruction::store(OperandSize::S64, REGISTER_MAP[0], R10, X86IndirectAccess::Offset((std::mem::size_of::() * 2) as i32))); // target_address = RAX; + self.emit_set_exception_kind(EbpfError::CallOutsideTextSegment); self.emit_ins(X86Instruction::jump_immediate(self.relative_to_anchor(ANCHOR_THROW_EXCEPTION, 5))); // Handler for EbpfError::DivideByZero self.set_anchor(ANCHOR_DIV_BY_ZERO); - self.emit_set_exception_kind(EbpfError::DivideByZero(0)); + self.emit_set_exception_kind(EbpfError::DivideByZero); self.emit_ins(X86Instruction::jump_immediate(self.relative_to_anchor(ANCHOR_THROW_EXCEPTION, 5))); // Handler for EbpfError::DivideOverflow self.set_anchor(ANCHOR_DIV_OVERFLOW); - self.emit_set_exception_kind(EbpfError::DivideOverflow(0)); + self.emit_set_exception_kind(EbpfError::DivideOverflow); self.emit_ins(X86Instruction::jump_immediate(self.relative_to_anchor(ANCHOR_THROW_EXCEPTION, 5))); // Handler for EbpfError::UnsupportedInstruction @@ -1400,7 +1395,7 @@ impl<'a, C: ContextObject> JitCompiler<'a, C> { if self.config.enable_instruction_tracing { self.emit_ins(X86Instruction::call_immediate(self.relative_to_anchor(ANCHOR_TRACE, 5))); } - self.emit_set_exception_kind(EbpfError::UnsupportedInstruction(0)); + self.emit_set_exception_kind(EbpfError::UnsupportedInstruction); self.emit_ins(X86Instruction::jump_immediate(self.relative_to_anchor(ANCHOR_THROW_EXCEPTION, 5))); // Routine for external functions @@ -1736,7 +1731,7 @@ mod tests { if result.is_err() { assert!(matches!( result.unwrap_err(), - EbpfError::UnsupportedInstruction(_) + EbpfError::UnsupportedInstruction )); continue; } diff --git a/tests/execution.rs b/tests/execution.rs index d65f61b4d..06ddae37b 100644 --- a/tests/execution.rs +++ b/tests/execution.rs @@ -744,7 +744,7 @@ fn test_err_divide_by_zero() { executable, [], TestContextObject::new(2), - ProgramResult::Err(EbpfError::DivideByZero(30)), + ProgramResult::Err(EbpfError::DivideByZero), ); } } @@ -786,7 +786,7 @@ fn test_err_divide_overflow() { executable, [], TestContextObject::new(4), - ProgramResult::Err(EbpfError::DivideOverflow(32)), + ProgramResult::Err(EbpfError::DivideOverflow), ); } } @@ -1345,7 +1345,7 @@ fn test_exit_capped() { [], (), TestContextObject::new(0), - ProgramResult::Err(EbpfError::ExceededMaxInstructions(29)), + ProgramResult::Err(EbpfError::ExceededMaxInstructions), ); } @@ -2158,7 +2158,7 @@ fn test_stack_call_depth_tracking() { [], (), TestContextObject::new(2), - ProgramResult::Err(EbpfError::CallDepthExceeded(31, config.max_call_depth)), + ProgramResult::Err(EbpfError::CallDepthExceeded), ); } } @@ -2292,7 +2292,7 @@ fn test_err_callx_unregistered() { [], (), TestContextObject::new(6), - ProgramResult::Err(EbpfError::UnsupportedInstruction(35)), + ProgramResult::Err(EbpfError::UnsupportedInstruction), ); } @@ -2306,7 +2306,7 @@ fn test_err_callx_oob_low() { [], (), TestContextObject::new(2), - ProgramResult::Err(EbpfError::CallOutsideTextSegment(30, 0)), + ProgramResult::Err(EbpfError::CallOutsideTextSegment), ); } @@ -2322,7 +2322,7 @@ fn test_err_callx_oob_high() { [], (), TestContextObject::new(4), - ProgramResult::Err(EbpfError::CallOutsideTextSegment(32, 0xffffffff00000000)), + ProgramResult::Err(EbpfError::CallOutsideTextSegment), ); } @@ -2359,16 +2359,12 @@ fn test_bpf_to_bpf_depth() { [Config::default().max_call_depth as u8 + 1], (), TestContextObject::new(60), - ProgramResult::Err(EbpfError::CallDepthExceeded( - 35, - Config::default().max_call_depth - )), + ProgramResult::Err(EbpfError::CallDepthExceeded), ); } #[test] fn test_err_reg_stack_depth() { - let config = Config::default(); test_interpreter_and_jit_asm!( " mov64 r0, 0x1 @@ -2378,7 +2374,7 @@ fn test_err_reg_stack_depth() { [], (), TestContextObject::new(60), - ProgramResult::Err(EbpfError::CallDepthExceeded(31, config.max_call_depth)), + ProgramResult::Err(EbpfError::CallDepthExceeded), ); } @@ -2520,7 +2516,7 @@ fn nested_vm_syscall( *result = if throw == 0 { ProgramResult::Ok(42) } else { - ProgramResult::Err(EbpfError::CallDepthExceeded(33, 0)) + ProgramResult::Err(EbpfError::CallDepthExceeded) }; #[allow(unused_mut)] if depth > 0 { @@ -2577,7 +2573,7 @@ fn test_nested_vm_syscall() { &mut memory_mapping, &mut result, ); - assert_error!(result, "CallDepthExceeded(33, 0)"); + assert_error!(result, "CallDepthExceeded"); } // Instruction Meter Limit @@ -2591,7 +2587,7 @@ fn test_tight_infinite_loop_conditional() { [], (), TestContextObject::new(4), - ProgramResult::Err(EbpfError::ExceededMaxInstructions(30)), + ProgramResult::Err(EbpfError::ExceededMaxInstructions), ); } @@ -2604,7 +2600,7 @@ fn test_tight_infinite_loop_unconditional() { [], (), TestContextObject::new(4), - ProgramResult::Err(EbpfError::ExceededMaxInstructions(30)), + ProgramResult::Err(EbpfError::ExceededMaxInstructions), ); } @@ -2619,7 +2615,7 @@ fn test_tight_infinite_recursion() { [], (), TestContextObject::new(4), - ProgramResult::Err(EbpfError::ExceededMaxInstructions(31)), + ProgramResult::Err(EbpfError::ExceededMaxInstructions), ); } @@ -2639,7 +2635,7 @@ fn test_tight_infinite_recursion_callx() { [], (), TestContextObject::new(8), - ProgramResult::Err(EbpfError::ExceededMaxInstructions(36)), + ProgramResult::Err(EbpfError::ExceededMaxInstructions), ); } @@ -2673,7 +2669,7 @@ fn test_err_instruction_count_syscall_capped() { "bpf_syscall_string" => syscalls::bpf_syscall_string, ), TestContextObject::new(3), - ProgramResult::Err(EbpfError::ExceededMaxInstructions(32)), + ProgramResult::Err(EbpfError::ExceededMaxInstructions), ); } @@ -2694,7 +2690,7 @@ fn test_non_terminate_early() { [], (), TestContextObject::new(7), - ProgramResult::Err(EbpfError::UnsupportedInstruction(35)), + ProgramResult::Err(EbpfError::UnsupportedInstruction), ); } @@ -2717,7 +2713,7 @@ fn test_err_non_terminate_capped() { "bpf_trace_printf" => syscalls::bpf_trace_printf, ), TestContextObject::new(7), - ProgramResult::Err(EbpfError::ExceededMaxInstructions(36)), + ProgramResult::Err(EbpfError::ExceededMaxInstructions), ); test_interpreter_and_jit_asm!( " @@ -2736,7 +2732,7 @@ fn test_err_non_terminate_capped() { "bpf_trace_printf" => syscalls::bpf_trace_printf, ), TestContextObject::new(1000), - ProgramResult::Err(EbpfError::ExceededMaxInstructions(37)), + ProgramResult::Err(EbpfError::ExceededMaxInstructions), ); } @@ -2754,7 +2750,7 @@ fn test_err_capped_before_exception() { [], (), TestContextObject::new(4), - ProgramResult::Err(EbpfError::ExceededMaxInstructions(33)), + ProgramResult::Err(EbpfError::ExceededMaxInstructions), ); test_interpreter_and_jit_asm!( " @@ -2768,7 +2764,7 @@ fn test_err_capped_before_exception() { [], (), TestContextObject::new(4), - ProgramResult::Err(EbpfError::ExceededMaxInstructions(33)), + ProgramResult::Err(EbpfError::ExceededMaxInstructions), ); } @@ -2787,7 +2783,7 @@ fn test_err_exit_capped() { [], (), TestContextObject::new(5), - ProgramResult::Err(EbpfError::ExceededMaxInstructions(35)), + ProgramResult::Err(EbpfError::ExceededMaxInstructions), ); test_interpreter_and_jit_asm!( " @@ -2803,7 +2799,7 @@ fn test_err_exit_capped() { [], (), TestContextObject::new(6), - ProgramResult::Err(EbpfError::ExceededMaxInstructions(36)), + ProgramResult::Err(EbpfError::ExceededMaxInstructions), ); test_interpreter_and_jit_asm!( " @@ -2815,7 +2811,7 @@ fn test_err_exit_capped() { [], (), TestContextObject::new(3), - ProgramResult::Err(EbpfError::ExceededMaxInstructions(33)), + ProgramResult::Err(EbpfError::ExceededMaxInstructions), ); } @@ -2855,7 +2851,7 @@ fn test_err_call_unresolved() { [], (), TestContextObject::new(6), - ProgramResult::Err(EbpfError::UnsupportedInstruction(34)), + ProgramResult::Err(EbpfError::UnsupportedInstruction), ); } @@ -2910,7 +2906,7 @@ fn test_err_unresolved_syscall_static() { [], (), TestContextObject::new(4), - ProgramResult::Err(EbpfError::UnsupportedInstruction(32)), + ProgramResult::Err(EbpfError::UnsupportedInstruction), ); } @@ -3483,7 +3479,7 @@ fn test_lddw() { [], (), TestContextObject::new(4), - ProgramResult::Err(EbpfError::ExceededMaxInstructions(33)), + ProgramResult::Err(EbpfError::ExceededMaxInstructions), ); test_interpreter_and_jit_asm!( " @@ -3497,7 +3493,7 @@ fn test_lddw() { [], (), TestContextObject::new(5), - ProgramResult::Err(EbpfError::UnsupportedInstruction(34)), + ProgramResult::Err(EbpfError::UnsupportedInstruction), ); test_interpreter_and_jit_asm!( " @@ -3514,7 +3510,7 @@ fn test_lddw() { [], (), TestContextObject::new(5), - ProgramResult::Err(EbpfError::UnsupportedInstruction(36)), + ProgramResult::Err(EbpfError::UnsupportedInstruction), ); test_interpreter_and_jit_asm!( " @@ -3530,7 +3526,7 @@ fn test_lddw() { [], (), TestContextObject::new(3), - ProgramResult::Err(EbpfError::UnsupportedInstruction(36)), + ProgramResult::Err(EbpfError::UnsupportedInstruction), ); test_interpreter_and_jit_asm!( " @@ -3543,7 +3539,7 @@ fn test_lddw() { [], (), TestContextObject::new(2), - ProgramResult::Err(EbpfError::ExceededMaxInstructions(32)), + ProgramResult::Err(EbpfError::ExceededMaxInstructions), ); } @@ -3840,7 +3836,7 @@ fn test_div() { [], (), TestContextObject::new(3), - ProgramResult::Err(EbpfError::DivideByZero(31)), + ProgramResult::Err(EbpfError::DivideByZero), ); test_interpreter_and_jit_asm!( " @@ -3852,7 +3848,7 @@ fn test_div() { [], (), TestContextObject::new(3), - ProgramResult::Err(EbpfError::DivideByZero(31)), + ProgramResult::Err(EbpfError::DivideByZero), ); } @@ -3913,7 +3909,7 @@ fn test_mod() { [], (), TestContextObject::new(3), - ProgramResult::Err(EbpfError::DivideByZero(31)), + ProgramResult::Err(EbpfError::DivideByZero), ); test_interpreter_and_jit_asm!( " @@ -3925,6 +3921,6 @@ fn test_mod() { [], (), TestContextObject::new(3), - ProgramResult::Err(EbpfError::DivideByZero(31)), + ProgramResult::Err(EbpfError::DivideByZero), ); }