Skip to content

Commit

Permalink
Use debug_assert
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasSte committed Oct 22, 2024
1 parent b7bdc5a commit caa7701
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ impl<'a, 'b, C: ContextObject> Interpreter<'a, 'b, C> {
ProgramResult::Err(_err) => return false,
};
} else {
throw_error!(self, EbpfError::UnsupportedInstruction);
debug_assert!(false, "Invalid syscall should have been detected in the verifier.");
}
},
ebpf::RETURN
Expand Down
11 changes: 3 additions & 8 deletions src/jit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,14 +715,15 @@ impl<'a, C: ContextObject> JitCompiler<'a, C> {
// BPF to BPF call
self.emit_internal_call(Value::Constant64(target_pc as i64, true));
} else {
self.emit_throw_unsupported_instruction();
self.emit_ins(X86Instruction::load_immediate(OperandSize::S64, REGISTER_SCRATCH, self.pc as i64));
self.emit_ins(X86Instruction::jump_immediate(self.relative_to_anchor(ANCHOR_CALL_UNSUPPORTED_INSTRUCTION, 5)));
}
},
ebpf::SYSCALL if self.executable.get_sbpf_version().static_syscalls() => {
if let Some((_, function)) = self.executable.get_loader().get_function_registry(self.executable.get_sbpf_version()).lookup_by_key(insn.imm as u32) {
self.emit_syscall_dispatch(function);
} else {
self.emit_throw_unsupported_instruction();
debug_assert!(false, "Invalid syscall should have been detected in the verifier.")
}
},
ebpf::CALL_REG => {
Expand Down Expand Up @@ -1130,12 +1131,6 @@ impl<'a, C: ContextObject> JitCompiler<'a, C> {
self.emit_undo_profile_instruction_count(0);
}

#[inline]
fn emit_throw_unsupported_instruction(&mut self) {
self.emit_ins(X86Instruction::load_immediate(OperandSize::S64, REGISTER_SCRATCH, self.pc as i64));
self.emit_ins(X86Instruction::jump_immediate(self.relative_to_anchor(ANCHOR_CALL_UNSUPPORTED_INSTRUCTION, 5)));
}

#[inline]
fn emit_address_translation(&mut self, dst: Option<u8>, vm_addr: Value, len: u64, value: Option<Value>) {
debug_assert_ne!(dst.is_some(), value.is_some());
Expand Down
2 changes: 2 additions & 0 deletions tests/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4089,6 +4089,7 @@ fn test_mod() {
}

#[test]
#[should_panic(expected = "Invalid syscall should have been detected in the verifier.")]
fn test_invalid_exit_or_return() {
for sbpf_version in [SBPFVersion::V1, SBPFVersion::V2] {
let inst = if sbpf_version == SBPFVersion::V1 {
Expand Down Expand Up @@ -4128,6 +4129,7 @@ fn test_invalid_exit_or_return() {
}

#[test]
#[should_panic(expected = "Invalid syscall should have been detected in the verifier.")]
fn test_unregistered_syscall() {
let prog = &[
0xbf, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, // mov64 r0, 2
Expand Down

0 comments on commit caa7701

Please sign in to comment.