github.com/dylandreimerink/gobpfld@v0.6.1-0.20220205171531-e79c330ad608/emulator/inst_jeq.go (about) 1 package emulator 2 3 import ( 4 "github.com/dylandreimerink/gobpfld/ebpf" 5 ) 6 7 var _ Instruction = (*JumpEqual32)(nil) 8 9 type JumpEqual32 struct { 10 ebpf.JumpEqual32 11 } 12 13 func (i *JumpEqual32) Clone() Instruction { 14 c := *i 15 return &c 16 } 17 18 func (i *JumpEqual32) 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) && int32(dv) == i.Value { 25 vm.Registers.PC += int(i.Offset) 26 } 27 28 return nil 29 } 30 31 var _ Instruction = (*JumpEqual)(nil) 32 33 type JumpEqual struct { 34 ebpf.JumpEqual 35 } 36 37 func (i *JumpEqual) Clone() Instruction { 38 c := *i 39 return &c 40 } 41 42 func (i *JumpEqual) 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) && dv == int64(i.Value) { 49 vm.Registers.PC += int(i.Offset) 50 } 51 52 return nil 53 } 54 55 var _ Instruction = (*JumpEqualRegister32)(nil) 56 57 type JumpEqualRegister32 struct { 58 ebpf.JumpEqualRegister32 59 } 60 61 func (i *JumpEqualRegister32) Clone() Instruction { 62 c := *i 63 return &c 64 } 65 66 func (i *JumpEqualRegister32) 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) && int32(dv) == int32(sv) { 78 vm.Registers.PC += int(i.Offset) 79 } 80 81 return nil 82 } 83 84 var _ Instruction = (*JumpEqualRegister)(nil) 85 86 type JumpEqualRegister struct { 87 ebpf.JumpEqualRegister 88 } 89 90 func (i *JumpEqualRegister) Clone() Instruction { 91 c := *i 92 return &c 93 } 94 95 func (i *JumpEqualRegister) 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) && dv == sv { 107 vm.Registers.PC += int(i.Offset) 108 } 109 110 return nil 111 }