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