github.com/dylandreimerink/gobpfld@v0.6.1-0.20220205171531-e79c330ad608/emulator/inst_jlt.go (about) 1 package emulator 2 3 import ( 4 "github.com/dylandreimerink/gobpfld/ebpf" 5 ) 6 7 var _ Instruction = (*JumpSmallerThan32)(nil) 8 9 type JumpSmallerThan32 struct { 10 ebpf.JumpSmallerThan32 11 } 12 13 func (i *JumpSmallerThan32) Clone() Instruction { 14 c := *i 15 return &c 16 } 17 18 func (i *JumpSmallerThan32) Execute(vm *VM) error { 19 dv, dr, err := readReg(vm, i.Dest) 20 if err != nil { 21 return err 22 } 23 24 if isIMM(dr) && uint32(dv) < uint32(i.Value) { 25 vm.Registers.PC += int(i.Offset) 26 } 27 28 return nil 29 } 30 31 var _ Instruction = (*JumpSmallerThan)(nil) 32 33 type JumpSmallerThan struct { 34 ebpf.JumpSmallerThan 35 } 36 37 func (i *JumpSmallerThan) Clone() Instruction { 38 c := *i 39 return &c 40 } 41 42 func (i *JumpSmallerThan) Execute(vm *VM) error { 43 dv, dr, err := readReg(vm, i.Dest) 44 if err != nil { 45 return err 46 } 47 48 if isIMM(dr) && uint64(dv) < uint64(i.Value) { 49 vm.Registers.PC += int(i.Offset) 50 } 51 52 return nil 53 } 54 55 var _ Instruction = (*JumpSmallerThanRegister32)(nil) 56 57 type JumpSmallerThanRegister32 struct { 58 ebpf.JumpSmallerThanRegister32 59 } 60 61 func (i *JumpSmallerThanRegister32) Clone() Instruction { 62 c := *i 63 return &c 64 } 65 66 func (i *JumpSmallerThanRegister32) Execute(vm *VM) error { 67 dv, dr, err := readReg(vm, i.Dest) 68 if err != nil { 69 return err 70 } 71 72 sv, sr, err := readReg(vm, i.Src) 73 if err != nil { 74 return err 75 } 76 77 if sameRVType(dr, sr) && uint32(dv) < uint32(sv) { 78 vm.Registers.PC += int(i.Offset) 79 } 80 81 return nil 82 } 83 84 var _ Instruction = (*JumpSmallerThanRegister)(nil) 85 86 type JumpSmallerThanRegister struct { 87 ebpf.JumpSmallerThanRegister 88 } 89 90 func (i *JumpSmallerThanRegister) Clone() Instruction { 91 c := *i 92 return &c 93 } 94 95 func (i *JumpSmallerThanRegister) Execute(vm *VM) error { 96 dv, dr, err := readReg(vm, i.Dest) 97 if err != nil { 98 return err 99 } 100 101 sv, sr, err := readReg(vm, i.Src) 102 if err != nil { 103 return err 104 } 105 106 if sameRVType(dr, sr) && uint64(dv) < uint64(sv) { 107 vm.Registers.PC += int(i.Offset) 108 } 109 110 return nil 111 }