Skip to content

Commit d22086f

Browse files
committed
Makes the target_pc parameter of emit_profile_instruction_count() non optional
1 parent 46facd1 commit d22086f

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/jit.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ impl<'a, C: ContextObject> JitCompiler<'a, C> {
440440

441441
match insn.opc {
442442
ebpf::LD_DW_IMM if !self.executable.get_sbpf_version().disable_lddw() => {
443-
self.emit_validate_and_profile_instruction_count(Some(self.pc + 2));
443+
self.emit_validate_and_profile_instruction_count(self.pc + 2);
444444
self.pc += 1;
445445
self.result.pc_section[self.pc] = unsafe { self.anchors[ANCHOR_CALL_UNSUPPORTED_INSTRUCTION].offset_from(self.result.text_section.as_ptr()) as u32 };
446446
ebpf::augment_lddw_unchecked(self.program, &mut insn);
@@ -719,7 +719,7 @@ impl<'a, C: ContextObject> JitCompiler<'a, C> {
719719

720720
// BPF_JMP class
721721
ebpf::JA => {
722-
self.emit_validate_and_profile_instruction_count(Some(target_pc));
722+
self.emit_validate_and_profile_instruction_count(target_pc);
723723
let jump_offset = self.relative_to_target_pc(target_pc, 5);
724724
self.emit_ins(X86Instruction::jump_immediate(jump_offset));
725725
},
@@ -789,7 +789,7 @@ impl<'a, C: ContextObject> JitCompiler<'a, C> {
789789
|| (insn.opc == ebpf::RETURN && !self.executable.get_sbpf_version().static_syscalls()) {
790790
return Err(EbpfError::UnsupportedInstruction);
791791
}
792-
self.emit_validate_and_profile_instruction_count(Some(0));
792+
self.emit_validate_and_profile_instruction_count(0);
793793

794794
let call_depth_access = X86IndirectAccess::Offset(self.slot_in_vm(RuntimeEnvironmentSlot::CallDepth));
795795
// If env.call_depth == 0, we've reached the exit instruction of the entry point
@@ -814,7 +814,7 @@ impl<'a, C: ContextObject> JitCompiler<'a, C> {
814814
if self.offset_in_text_section + MAX_MACHINE_CODE_LENGTH_PER_INSTRUCTION * 2 >= self.result.text_section.len() {
815815
return Err(EbpfError::ExhaustedTextSegment(self.pc));
816816
}
817-
self.emit_validate_and_profile_instruction_count(Some(self.pc + 1));
817+
self.emit_validate_and_profile_instruction_count(self.pc + 1);
818818
self.emit_ins(X86Instruction::load_immediate(REGISTER_SCRATCH, self.pc as i64)); // Save pc
819819
self.emit_set_exception_kind(EbpfError::ExecutionOverrun);
820820
self.emit_ins(X86Instruction::jump_immediate(self.relative_to_anchor(ANCHOR_THROW_EXCEPTION, 5)));
@@ -979,8 +979,7 @@ impl<'a, C: ContextObject> JitCompiler<'a, C> {
979979
}
980980

981981
#[inline]
982-
fn emit_validate_and_profile_instruction_count(&mut self, target_pc: Option<usize>) {
983-
let target_pc = target_pc.unwrap();
982+
fn emit_validate_and_profile_instruction_count(&mut self, target_pc: usize) {
984983
self.last_instruction_meter_validation_pc = self.pc;
985984
self.emit_ins(X86Instruction::load_immediate(REGISTER_SCRATCH, ((target_pc << 32 | self.pc) as i64) ^ self.immediate_value_key));
986985
self.emit_ins(X86Instruction::call_immediate(self.relative_to_anchor(ANCHOR_VALIDATE_AND_PROFILE_INSTRUCTION_COUNT, 5)));
@@ -1140,7 +1139,7 @@ impl<'a, C: ContextObject> JitCompiler<'a, C> {
11401139

11411140
#[inline]
11421141
fn emit_syscall_dispatch(&mut self, function: BuiltinFunction<C>) {
1143-
self.emit_validate_and_profile_instruction_count(Some(0));
1142+
self.emit_validate_and_profile_instruction_count(0);
11441143
self.emit_ins(X86Instruction::load_immediate(REGISTER_SCRATCH, function as usize as i64));
11451144
self.emit_ins(X86Instruction::call_immediate(self.relative_to_anchor(ANCHOR_EXTERNAL_FUNCTION_CALL, 5)));
11461145
self.emit_undo_profile_instruction_count(0);
@@ -1215,7 +1214,7 @@ impl<'a, C: ContextObject> JitCompiler<'a, C> {
12151214

12161215
#[inline]
12171216
fn emit_conditional_branch_reg(&mut self, op: u8, bitwise: bool, first_operand: X86Register, second_operand: X86Register, target_pc: usize) {
1218-
self.emit_validate_and_profile_instruction_count(Some(target_pc));
1217+
self.emit_validate_and_profile_instruction_count(target_pc);
12191218
if bitwise { // Logical
12201219
self.emit_ins(X86Instruction::test(OperandSize::S64, first_operand, second_operand, None));
12211220
} else { // Arithmetic
@@ -1228,7 +1227,7 @@ impl<'a, C: ContextObject> JitCompiler<'a, C> {
12281227

12291228
#[inline]
12301229
fn emit_conditional_branch_imm(&mut self, op: u8, bitwise: bool, immediate: i64, second_operand: X86Register, target_pc: usize) {
1231-
self.emit_validate_and_profile_instruction_count(Some(target_pc));
1230+
self.emit_validate_and_profile_instruction_count(target_pc);
12321231
if self.should_sanitize_constant(immediate) {
12331232
self.emit_ins(X86Instruction::mov_mmx(OperandSize::S64, REGISTER_SCRATCH, MM0));
12341233
self.emit_sanitized_load_immediate(REGISTER_SCRATCH, immediate);

0 commit comments

Comments
 (0)