Browse Source

src/jit.rs: Remove division-by-zero handler from JIT

The handler for the case where we hit a division by zero in compiled
code is no longer used, since we have updated the behaviour in a
previous commit and no longer need to exit early by jumping to the end
of the program. Remove the handler.

Signed-off-by: Quentin Monnet <quentin@isovalent.com>
Quentin Monnet 2 năm trước cách đây
mục cha
commit
84a9ec353b
1 tập tin đã thay đổi với 1 bổ sung21 xóa
  1. 1 21
      src/jit.rs

+ 1 - 21
src/jit.rs

@@ -22,8 +22,7 @@ const PAGE_SIZE: usize = 4096;
 
 // Special values for target_pc in struct Jump
 const TARGET_OFFSET: isize = ebpf::PROG_MAX_INSNS as isize;
-const TARGET_PC_EXIT:         isize = TARGET_OFFSET + 1;
-const TARGET_PC_DIV_BY_ZERO:  isize = TARGET_OFFSET + 2;
+const TARGET_PC_EXIT: isize = TARGET_OFFSET + 1;
 
 #[derive(Copy, Clone)]
 enum OperandSize {
@@ -846,25 +845,6 @@ impl<'a> JitMemory<'a> {
 
         emit1(self, 0xc3); // ret
 
-        // Division by zero handler
-        set_anchor(self, TARGET_PC_DIV_BY_ZERO);
-        fn log(pc: u64) -> i64 {
-            // Write error message on stderr.
-            // We would like to panic!() instead (but does not work here), or maybe return an
-            // error, that is, if we also turn all other panics into errors someday.
-            // Note: needs `use std::io::Write;`
-            //     let res = writeln!(&mut std::io::stderr(),
-            //                        "[JIT] Error: division by zero (insn {:?})\n", pc);
-            //     match res {
-            //         Ok(_)  => 0,
-            //         Err(_) => -1
-            //     }
-            pc as i64 // Just to prevent warnings
-        }
-        emit_mov(self, RCX, RDI); // muldivmod stored pc in RCX
-        emit_call(self, log as usize);
-        emit_load_imm(self, map_register(0), -1);
-        emit_jmp(self, TARGET_PC_EXIT);
         Ok(())
     }