@@ -38,7 +38,7 @@ use crate::{
38
38
39
39
const MAX_EMPTY_PROGRAM_MACHINE_CODE_LENGTH : usize = 4096 ;
40
40
const MAX_MACHINE_CODE_LENGTH_PER_INSTRUCTION : usize = 110 ;
41
- const MACHINE_CODE_PER_INSTRUCTION_METER_CHECKPOINT : usize = 13 ;
41
+ const MACHINE_CODE_PER_INSTRUCTION_METER_CHECKPOINT : usize = 23 ;
42
42
const MAX_START_PADDING_LENGTH : usize = 256 ;
43
43
44
44
pub struct JitProgram {
@@ -941,12 +941,10 @@ impl<'a, C: ContextObject> JitCompiler<'a, C> {
941
941
// Update `MACHINE_CODE_PER_INSTRUCTION_METER_CHECKPOINT` if you change the code generation here
942
942
if let Some ( pc) = pc {
943
943
self . last_instruction_meter_validation_pc = pc;
944
- // instruction_meter >= self.pc
945
- self . emit_ins ( X86Instruction :: cmp_immediate ( OperandSize :: S64 , REGISTER_INSTRUCTION_METER , pc as i64 , None ) ) ;
946
- } else {
947
- // instruction_meter >= scratch_register
948
- self . emit_ins ( X86Instruction :: cmp ( OperandSize :: S64 , REGISTER_SCRATCH , REGISTER_INSTRUCTION_METER , None ) ) ;
944
+ self . emit_sanitized_load_immediate ( REGISTER_SCRATCH , pc as i64 ) ;
949
945
}
946
+ // If instruction_meter >= pc, throw ExceededMaxInstructions
947
+ self . emit_ins ( X86Instruction :: cmp ( OperandSize :: S64 , REGISTER_SCRATCH , REGISTER_INSTRUCTION_METER , None ) ) ;
950
948
self . emit_ins ( X86Instruction :: conditional_jump_immediate ( 0x86 , self . relative_to_anchor ( ANCHOR_THROW_EXCEEDED_MAX_INSTRUCTIONS , 6 ) ) ) ;
951
949
}
952
950
@@ -1835,9 +1833,9 @@ mod tests {
1835
1833
let instruction_meter_checkpoint_machine_code_length =
1836
1834
instruction_meter_checkpoint_machine_code_length[ 0 ]
1837
1835
- instruction_meter_checkpoint_machine_code_length[ 1 ] ;
1838
- assert_eq ! (
1839
- instruction_meter_checkpoint_machine_code_length,
1840
- MACHINE_CODE_PER_INSTRUCTION_METER_CHECKPOINT
1836
+ assert ! (
1837
+ instruction_meter_checkpoint_machine_code_length
1838
+ <= MACHINE_CODE_PER_INSTRUCTION_METER_CHECKPOINT
1841
1839
) ;
1842
1840
1843
1841
for sbpf_version in [ SBPFVersion :: V0 , SBPFVersion :: V3 ] {
0 commit comments