asm

package
v0.0.0-...-21cfbab Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2023 License: Apache-2.0, Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package asm contains a basic eBPF bytecode assembler. So far, the instructions that are useful in our BPF programs have been added but adding additional instructions is straightforward following the pattern.

Most BPF instructions are 8 bytes (the exception being 64-bit immediate loads). All 8-byte instructions have the same format and the vast majority are general purpose instructions (i.e. they operate on the designated src/dst register only and don't clobber anything else). We only use the general purpose instructions at present.

The instruction format is represented by the Insn type. It consists of a 1-byte opcode, 4 bits each for src and dst registers, a 16-bit offset (used for loads, stores and jumps) and a 32-bit signed immediate.

The BPF ALU supports both 32-bit and 64-bit arithmetic and jump instructions. Since only 2 registers can be named in an instruction, ALU operations use the dst register as one of their inputs as well as the output.

BPF supports calling certain designated helper functions, which are exported by the kernel. To call a helper function, place its arguments in R1-R5 and then execute the Call instruction with one of the HelperXXX constants.

Index

Examples

Constants

View Source
const (

	// Scratch/return/exit value
	R0 Reg = 0
	// Scratch/arguments.
	R1 Reg = 1
	R2 Reg = 2
	R3 Reg = 3
	R4 Reg = 4
	R5 Reg = 5
	// Callee saves.
	R6 Reg = 6
	R7 Reg = 7
	R8 Reg = 8
	R9 Reg = 9
	// Read-only, frame pointer.
	R10 Reg = 10

	// RPseudoMapFD is special source register value used with LoadImm64
	// to indicate a map file descriptor.
	RPseudoMapFD = 1

	// Lowest 3 bits of opcode are the instruction class.
	OpClassLoadImm  = 0b00000_000 // 0x0
	OpClassLoadReg  = 0b00000_001 // 0x1
	OpClassStoreImm = 0b00000_010 // 0x2
	OpClassStoreReg = 0b00000_011 // 0x3
	OpClassALU32    = 0b00000_100 // 0x4
	OpClassJump64   = 0b00000_101 // 0x5 64-bit wide operands (jump target always in offset)
	OpClassJump32   = 0b00000_110 // 0x6 32-bit wide operands (jump target always in offset)
	OpClassALU64    = 0b00000_111 // 0x7

	// For memory operations, the upper 3 bits are the mode.
	MemOpModeImm  = 0b000_00_000
	MemOpModeAbs  = 0b001_00_000 // Carry over from cBPF, non-general-purpose
	MemOpModeInd  = 0b010_00_000 // Carry over from cBPF, non-general-purpose
	MemOpModeMem  = 0b011_00_000 // eBPF general memory op.
	MemOpModeXADD = 0b110_00_000 // eBPF general memory op.

	// For memory operations, the middle two bits are the size modifier.
	MemOpSize8  = 0b000_10_000
	MemOpSize16 = 0b000_01_000
	MemOpSize32 = 0b000_00_000
	MemOpSize64 = 0b000_11_000

	// ALU operations have upper 4 bits for the operation
	ALUOpAdd     = 0b0000_0_000 // 0x0
	ALUOpSub     = 0b0001_0_000 // 0x1
	ALUOpMul     = 0b0010_0_000 // 0x2
	ALUOpDiv     = 0b0011_0_000 // 0x3
	ALUOpOr      = 0b0100_0_000 // 0x4
	ALUOpAnd     = 0b0101_0_000 // 0x5
	ALUOpShiftL  = 0b0110_0_000 // 0x6
	ALUOpShiftR  = 0b0111_0_000 // 0x7
	ALUOpNegate  = 0b1000_0_000 // 0x8
	ALUOpMod     = 0b1001_0_000 // 0x9
	ALUOpXOR     = 0b1010_0_000 // 0xa
	ALUOpMov     = 0b1011_0_000 // 0xb
	ALUOpAShiftR = 0b1100_0_000 // 0xc
	ALUOpEndian  = 0b1101_0_000 // 0xd

	OpEndianToBE   = 0x8
	OpEndianToLE   = 0x0
	OpEndianFromBE = OpEndianToBE
	OpEndianFromLE = OpEndianToLE

	// And one bit for the source.
	ALUSrcImm = 0b0000_0_000 // 0x0
	ALUSrcReg = 0b0000_1_000 // 0x8

	// Jumps are similar but they have a different set of operations.
	JumpOpA    = 0b0000_0_000 // 0x00 BPF_JMP only
	JumpOpEq   = 0b0001_0_000 // 0x10
	JumpOpGT   = 0b0010_0_000 // 0x20
	JumpOpGE   = 0b0011_0_000 // 0x30
	JumpOpSet  = 0b0100_0_000 // 0x40
	JumpOpNE   = 0b0101_0_000 // 0x50
	JumpOpSGT  = 0b0110_0_000 // 0x60
	JumpOpSGE  = 0b0111_0_000 // 0x70
	JumpOpCall = 0b1000_0_000 // 0x80 BPF_JMP only
	JumpOpExit = 0b1001_0_000 // 0x90 BPF_JMP only
	JumpOpLT   = 0b1010_0_000 // 0xa0
	JumpOpLE   = 0b1011_0_000 // 0xb0
	JumpOpSLT  = 0b1100_0_000 // 0xc0
	JumpOpSLE  = 0b1101_0_000 // 0xd0

	// Load/store opcodes.
	StoreReg8  OpCode = OpClassStoreReg | MemOpModeMem | MemOpSize8
	StoreReg16 OpCode = OpClassStoreReg | MemOpModeMem | MemOpSize16
	StoreReg32 OpCode = OpClassStoreReg | MemOpModeMem | MemOpSize32
	StoreReg64 OpCode = OpClassStoreReg | MemOpModeMem | MemOpSize64

	// TODO: check these opcodes, should they be OpClassStoreMem with an immediate source instead?
	StoreImm8  OpCode = OpClassStoreImm | MemOpModeImm | MemOpSize8
	StoreImm16 OpCode = OpClassStoreImm | MemOpModeImm | MemOpSize16
	StoreImm32 OpCode = OpClassStoreImm | MemOpModeImm | MemOpSize32
	StoreImm64 OpCode = OpClassStoreImm | MemOpModeImm | MemOpSize64

	LoadReg8  OpCode = OpClassLoadReg | MemOpModeMem | MemOpSize8
	LoadReg16 OpCode = OpClassLoadReg | MemOpModeMem | MemOpSize16
	LoadReg32 OpCode = OpClassLoadReg | MemOpModeMem | MemOpSize32
	LoadReg64 OpCode = OpClassLoadReg | MemOpModeMem | MemOpSize64

	// LoadImm64 loads a 64-bit immediate value; it is a double-length instruction.
	// The immediate is split into two 32-bit halves; the first half is in the
	// first instruction's immediate; the second half is in the second instruction's
	// immediate.  The second instruction's other parts are zet to 0.
	LoadImm64    OpCode = OpClassLoadImm | MemOpModeImm | MemOpSize64
	LoadImm64Pt2 OpCode = 0

	// 64-bit comparison operations.  These do a 64-bit ALU operation between
	// two registers and then do a relative jump to the offset in the instruction.
	// The offset is relative to the next instruction (due to PC auto-increment).
	JumpEq64  OpCode = OpClassJump64 | ALUSrcReg | JumpOpEq
	JumpGT64  OpCode = OpClassJump64 | ALUSrcReg | JumpOpGT
	JumpGE64  OpCode = OpClassJump64 | ALUSrcReg | JumpOpGE
	JumpSet64 OpCode = OpClassJump64 | ALUSrcReg | JumpOpSet
	JumpNE64  OpCode = OpClassJump64 | ALUSrcReg | JumpOpNE
	JumpSGT64 OpCode = OpClassJump64 | ALUSrcReg | JumpOpSGT
	JumpSGE64 OpCode = OpClassJump64 | ALUSrcReg | JumpOpSGE
	JumpLT64  OpCode = OpClassJump64 | ALUSrcReg | JumpOpLT
	JumpLE64  OpCode = OpClassJump64 | ALUSrcReg | JumpOpLE
	JumpSLT64 OpCode = OpClassJump64 | ALUSrcReg | JumpOpSLT
	JumpSLE64 OpCode = OpClassJump64 | ALUSrcReg | JumpOpSLE

	// 64-bit comparison operations.  These do a 64-bit ALU operation between
	// a register and the immediate and then do a relative jump to the offset in
	// the instruction. The offset is relative to the next instruction (due to
	// PC auto-increment).
	JumpEqImm64  OpCode = OpClassJump64 | ALUSrcImm | JumpOpEq
	JumpGTImm64  OpCode = OpClassJump64 | ALUSrcImm | JumpOpGT
	JumpGEImm64  OpCode = OpClassJump64 | ALUSrcImm | JumpOpGE
	JumpSetImm64 OpCode = OpClassJump64 | ALUSrcImm | JumpOpSet
	JumpNEImm64  OpCode = OpClassJump64 | ALUSrcImm | JumpOpNE
	JumpSGTImm64 OpCode = OpClassJump64 | ALUSrcImm | JumpOpSGT
	JumpSGEImm64 OpCode = OpClassJump64 | ALUSrcImm | JumpOpSGE
	JumpLTImm64  OpCode = OpClassJump64 | ALUSrcImm | JumpOpLT
	JumpLEImm64  OpCode = OpClassJump64 | ALUSrcImm | JumpOpLE
	JumpSLTImm64 OpCode = OpClassJump64 | ALUSrcImm | JumpOpSLT
	JumpSLEImm64 OpCode = OpClassJump64 | ALUSrcImm | JumpOpSLE

	// JumpA: Unconditional jump.
	JumpA OpCode = OpClassJump64 | ALUSrcImm | JumpOpA

	// Call calls the helper function with ID stored in the immediate.
	Call OpCode = OpClassJump64 | ALUSrcImm | JumpOpCall
	// Exit exits the program, has no arguments, the return value is in R0.
	Exit OpCode = OpClassJump64 | ALUSrcImm | JumpOpExit

	// 32-bit comparison operations.  These do a 32-bit ALU operation between
	// two registers and then do a relative jump to the offset in the instruction.
	// The offset is relative to the next instruction (due to PC auto-increment).
	JumpEq32  OpCode = OpClassJump32 | ALUSrcReg | JumpOpEq
	JumpGT32  OpCode = OpClassJump32 | ALUSrcReg | JumpOpGT
	JumpGE32  OpCode = OpClassJump32 | ALUSrcReg | JumpOpGE
	JumpSet32 OpCode = OpClassJump32 | ALUSrcReg | JumpOpSet
	JumpNE32  OpCode = OpClassJump32 | ALUSrcReg | JumpOpNE
	JumpSGT32 OpCode = OpClassJump32 | ALUSrcReg | JumpOpSGT
	JumpSGE32 OpCode = OpClassJump32 | ALUSrcReg | JumpOpSGE
	JumpLT32  OpCode = OpClassJump32 | ALUSrcReg | JumpOpLT
	JumpLE32  OpCode = OpClassJump32 | ALUSrcReg | JumpOpLE
	JumpSLT32 OpCode = OpClassJump32 | ALUSrcReg | JumpOpSLT
	JumpSLE32 OpCode = OpClassJump32 | ALUSrcReg | JumpOpSLE

	// 32-bit comparison operations.  These do a 32-bit ALU operation between
	// a register and the immediate and then do a relative jump to the offset in
	// the instruction. The offset is relative to the next instruction (due to
	// PC auto-increment).
	JumpEqImm32  OpCode = OpClassJump32 | ALUSrcImm | JumpOpEq
	JumpGTImm32  OpCode = OpClassJump32 | ALUSrcImm | JumpOpGT
	JumpGEImm32  OpCode = OpClassJump32 | ALUSrcImm | JumpOpGE
	JumpSetImm32 OpCode = OpClassJump32 | ALUSrcImm | JumpOpSet
	JumpNEImm32  OpCode = OpClassJump32 | ALUSrcImm | JumpOpNE
	JumpSGTImm32 OpCode = OpClassJump32 | ALUSrcImm | JumpOpSGT
	JumpSGEImm32 OpCode = OpClassJump32 | ALUSrcImm | JumpOpSGE
	JumpLTImm32  OpCode = OpClassJump32 | ALUSrcImm | JumpOpLT
	JumpLEImm32  OpCode = OpClassJump32 | ALUSrcImm | JumpOpLE
	JumpSLTImm32 OpCode = OpClassJump32 | ALUSrcImm | JumpOpSLT
	JumpSLEImm32 OpCode = OpClassJump32 | ALUSrcImm | JumpOpSLE

	// 64-bit ALU operations between a pair of registers, specified as src and dst,
	// the result of the operation is stored in dst.
	Add64     OpCode = OpClassALU64 | ALUSrcReg | ALUOpAdd
	Sub64     OpCode = OpClassALU64 | ALUSrcReg | ALUOpSub
	Mul64     OpCode = OpClassALU64 | ALUSrcReg | ALUOpMul
	Div64     OpCode = OpClassALU64 | ALUSrcReg | ALUOpDiv
	Or64      OpCode = OpClassALU64 | ALUSrcReg | ALUOpOr
	And64     OpCode = OpClassALU64 | ALUSrcReg | ALUOpAnd
	ShiftL64  OpCode = OpClassALU64 | ALUSrcReg | ALUOpShiftL
	ShiftR64  OpCode = OpClassALU64 | ALUSrcReg | ALUOpShiftR
	Negate64  OpCode = OpClassALU64 | ALUSrcReg | ALUOpNegate
	Mod64     OpCode = OpClassALU64 | ALUSrcReg | ALUOpMod
	XOR64     OpCode = OpClassALU64 | ALUSrcReg | ALUOpXOR
	Mov64     OpCode = OpClassALU64 | ALUSrcReg | ALUOpMov
	AShiftR64 OpCode = OpClassALU64 | ALUSrcReg | ALUOpAShiftR
	Endian64  OpCode = OpClassALU64 | ALUSrcReg | ALUOpEndian

	// 32-bit ALU operations between a pair of registers, specified as src and dst,
	// the result of the operation is stored in dst.
	Add32     OpCode = OpClassALU32 | ALUSrcReg | ALUOpAdd
	Sub32     OpCode = OpClassALU32 | ALUSrcReg | ALUOpSub
	Mul32     OpCode = OpClassALU32 | ALUSrcReg | ALUOpMul
	Div32     OpCode = OpClassALU32 | ALUSrcReg | ALUOpDiv
	Or32      OpCode = OpClassALU32 | ALUSrcReg | ALUOpOr
	And32     OpCode = OpClassALU32 | ALUSrcReg | ALUOpAnd
	ShiftL32  OpCode = OpClassALU32 | ALUSrcReg | ALUOpShiftL
	ShiftR32  OpCode = OpClassALU32 | ALUSrcReg | ALUOpShiftR
	Negate32  OpCode = OpClassALU32 | ALUSrcReg | ALUOpNegate
	Mod32     OpCode = OpClassALU32 | ALUSrcReg | ALUOpMod
	XOR32     OpCode = OpClassALU32 | ALUSrcReg | ALUOpXOR
	Mov32     OpCode = OpClassALU32 | ALUSrcReg | ALUOpMov
	AShiftR32 OpCode = OpClassALU32 | ALUSrcReg | ALUOpAShiftR
	Endian32  OpCode = OpClassALU32 | ALUSrcReg | ALUOpEndian

	// 64-bit ALU operations between a register and immediate value. Note: immediate is only
	// 32-bit.
	AddImm64     OpCode = OpClassALU64 | ALUSrcImm | ALUOpAdd
	SubImm64     OpCode = OpClassALU64 | ALUSrcImm | ALUOpSub
	MulImm64     OpCode = OpClassALU64 | ALUSrcImm | ALUOpMul
	DivImm64     OpCode = OpClassALU64 | ALUSrcImm | ALUOpDiv
	OrImm64      OpCode = OpClassALU64 | ALUSrcImm | ALUOpOr
	AndImm64     OpCode = OpClassALU64 | ALUSrcImm | ALUOpAnd
	ShiftLImm64  OpCode = OpClassALU64 | ALUSrcImm | ALUOpShiftL
	ShiftRImm64  OpCode = OpClassALU64 | ALUSrcImm | ALUOpShiftR
	ModImm64     OpCode = OpClassALU64 | ALUSrcImm | ALUOpMod
	XORImm64     OpCode = OpClassALU64 | ALUSrcImm | ALUOpXOR
	MovImm64     OpCode = OpClassALU64 | ALUSrcImm | ALUOpMov
	AShiftRImm64 OpCode = OpClassALU64 | ALUSrcImm | ALUOpAShiftR
	EndianImm64  OpCode = OpClassALU64 | ALUSrcImm | ALUOpEndian

	// 32-bit ALU operations between a register and immediate value.
	AddImm32     OpCode = OpClassALU32 | ALUSrcImm | ALUOpAdd
	SubImm32     OpCode = OpClassALU32 | ALUSrcImm | ALUOpSub
	MulImm32     OpCode = OpClassALU32 | ALUSrcImm | ALUOpMul
	DivImm32     OpCode = OpClassALU32 | ALUSrcImm | ALUOpDiv
	OrImm32      OpCode = OpClassALU32 | ALUSrcImm | ALUOpOr
	AndImm32     OpCode = OpClassALU32 | ALUSrcImm | ALUOpAnd
	ShiftLImm32  OpCode = OpClassALU32 | ALUSrcImm | ALUOpShiftL
	ShiftRImm32  OpCode = OpClassALU32 | ALUSrcImm | ALUOpShiftR
	ModImm32     OpCode = OpClassALU32 | ALUSrcImm | ALUOpMod
	XORImm32     OpCode = OpClassALU32 | ALUSrcImm | ALUOpXOR
	MovImm32     OpCode = OpClassALU32 | ALUSrcImm | ALUOpMov
	AShiftRImm32 OpCode = OpClassALU32 | ALUSrcImm | ALUOpAShiftR
	EndianImm32  OpCode = OpClassALU32 | ALUSrcImm | ALUOpEndian
)

noinspection GoUnusedConst

View Source
const InstructionSize = 8

Variables

View Source
var (
	SkbuffOffsetLen     = FieldOffset{0 * 4, "skb->len"}
	SkbuffOffsetData    = FieldOffset{19 * 4, "skb->data"}
	SkbuffOffsetDataEnd = FieldOffset{20 * 4, "skb->data_end"}
)
View Source
var HelperString = []string{
	"",
	"bpf_map_lookup_elem",
	"bpf_map_update_elem",
	"bpf_map_delete_elem",
	"bpf_probe_read",
	"bpf_ktime_get_ns",
	"bpf_trace_printk",
	"bpf_get_prandom_u32",
	"bpf_get_smp_processor_id",
	"bpf_skb_store_bytes",
	"bpf_l3_csum_replace",
	"bpf_l4_csum_replace",
	"bpf_tail_call",
	"bpf_clone_redirect",
	"bpf_get_current_pid_tgid",
	"bpf_get_current_uid_gid",
	"bpf_get_current_comm",
	"bpf_get_cgroup_classid",
	"bpf_skb_vlan_push",
	"bpf_skb_vlan_pop",
	"",
	"",
	"",
	"",
	"",
	"",
	"",
	"",
	"",
	"",
	"",
	"",
	"",
	"",
	"",
	"",
	"",
	"",
	"",
	"bpf_skb_pull_data",
}

Functions

This section is empty.

Types

type Block

type Block struct {
	// contains filtered or unexported fields
}
Example
b := NewBlock(false)
b.MovImm64(R1, 10)         // R1 = 10
b.MovImm64(R2, 20)         // R2 = 20
b.JumpLE64(1, 2, "target") // if R1 < R2 jump to label "target"

b.MovImm64(R0, 1) // Instruction will be jumped over.
b.Jump("exit")

b.LabelNextInsn("target") // Label the next instruction as "target"
b.MovImm64(R0, 2)         //

b.LabelNextInsn("exit") // Label the next instruction as "exit"
b.Exit()                // Return from the BPF program (result is in R0).

// Assemble the program; this resolves the jumps and returns the bytecode.
insns, err := b.Assemble()
if err != nil {
	panic(err)
}

fmt.Println("Instructions:")
for _, i := range insns {
	fmt.Println(i)
}
Output:

Instructions:
MovImm64 dst=R1 src=R0 off=0 imm=0x0000000a/10
MovImm64 dst=R2 src=R0 off=0 imm=0x00000014/20
JumpLE64 dst=R1 src=R2 off=2 imm=0x00000000/0
MovImm64 dst=R0 src=R0 off=0 imm=0x00000001/1
JumpA dst=R0 src=R0 off=1 imm=0x00000000/0
MovImm64 dst=R0 src=R0 off=0 imm=0x00000002/2
Exit dst=R0 src=R0 off=0 imm=0x00000000/0

func NewBlock

func NewBlock(policyDebugEnabled bool) *Block

func (*Block) Add64

func (b *Block) Add64(dst, src Reg)

func (*Block) AddComment

func (b *Block) AddComment(comment string)

func (*Block) AddImm64

func (b *Block) AddImm64(dst Reg, imm int32)

func (*Block) And32

func (b *Block) And32(dst, src Reg)

func (*Block) AndImm32

func (b *Block) AndImm32(dst Reg, imm int32)

func (*Block) AndImm64

func (b *Block) AndImm64(dst Reg, imm int32)

func (*Block) Assemble

func (b *Block) Assemble() (Insns, error)

func (*Block) Call

func (b *Block) Call(helperID Helper)
Example
// Made up map file descriptor, this needs to be loaded form the kernel.
var mapFD maps.FD = 5

b := NewBlock(false)

// Store 64-bit 0 on the stack at offset -8 (stack grows down).
b.MovImm64(R1, 0)
b.StoreStack64(R1, -8)

// Get the address of the value we put on the stack in R2.
b.Mov64(R2, R10)
b.AddImm64(R2, -8)

// Special instruction to load a map file descriptor (obtained from bpf.Map.MapFD())
b.LoadMapFD(R1, uint32(mapFD))

// Call the helper, this clobbers R1-R5 and returns the result in R0.
b.Call(HelperMapLookupElem)

// Check the return value (in R0) for NULL.
b.JumpEqImm64(R0, 0, "miss")

// If we fall through, the value wasn't NULL, return 1.
b.MovImm64(R0, 1)
b.Exit()

b.LabelNextInsn("miss")
// If we get here, the value was NULL, return 2.
b.MovImm64(R0, 2)
b.Exit()

// Assemble the program; this resolves the jumps and returns the bytecode.
insns, err := b.Assemble()
if err != nil {
	panic(err)
}

fmt.Println("Instructions:")
for _, i := range insns {
	fmt.Println(i)
}
Output:

Instructions:
MovImm64 dst=R1 src=R0 off=0 imm=0x00000000/0
StoreReg64 dst=R10 src=R1 off=-8 imm=0x00000000/0
Mov64 dst=R2 src=R10 off=0 imm=0x00000000/0
AddImm64 dst=R2 src=R0 off=0 imm=0xfffffff8/-8
LoadImm64 dst=R1 src=R1 off=0 imm=0x00000005/5
LoadImm64Pt2 dst=R0 src=R0 off=0 imm=0x00000000/0
Call dst=R0 src=R0 off=0 imm=0x00000001/1
JumpEqImm64 dst=R0 src=R0 off=2 imm=0x00000000/0
MovImm64 dst=R0 src=R0 off=0 imm=0x00000001/1
Exit dst=R0 src=R0 off=0 imm=0x00000000/0
MovImm64 dst=R0 src=R0 off=0 imm=0x00000002/2
Exit dst=R0 src=R0 off=0 imm=0x00000000/0

func (*Block) Exit

func (b *Block) Exit()

func (*Block) FromBE

func (b *Block) FromBE(dst Reg, size int32)

func (*Block) Instr

func (b *Block) Instr(opcode OpCode, dst, src Reg, offset int16, imm int32, annotation string) Insn

func (*Block) InstrWithOffsetFixup

func (b *Block) InstrWithOffsetFixup(opcode OpCode, dst, src Reg, offsetLabel string, imm int32) Insn

func (*Block) Jump

func (b *Block) Jump(label string)

func (*Block) JumpEq32

func (b *Block) JumpEq32(ra, rb Reg, label string)

func (*Block) JumpEq64

func (b *Block) JumpEq64(ra, rb Reg, label string)

func (*Block) JumpEqImm32

func (b *Block) JumpEqImm32(ra Reg, imm int32, label string)

func (*Block) JumpEqImm64

func (b *Block) JumpEqImm64(ra Reg, imm int32, label string)

func (*Block) JumpGE32

func (b *Block) JumpGE32(ra, rb Reg, label string)

func (*Block) JumpGE64

func (b *Block) JumpGE64(ra, rb Reg, label string)

func (*Block) JumpGEImm64

func (b *Block) JumpGEImm64(ra Reg, imm int32, label string)

func (*Block) JumpGT32

func (b *Block) JumpGT32(ra, rb Reg, label string)

func (*Block) JumpGT64

func (b *Block) JumpGT64(ra, rb Reg, label string)

func (*Block) JumpLE32

func (b *Block) JumpLE32(ra, rb Reg, label string)

func (*Block) JumpLE64

func (b *Block) JumpLE64(ra, rb Reg, label string)

func (*Block) JumpLEImm64

func (b *Block) JumpLEImm64(ra Reg, imm int32, label string)

func (*Block) JumpLT32

func (b *Block) JumpLT32(ra, rb Reg, label string)

func (*Block) JumpLT64

func (b *Block) JumpLT64(ra, rb Reg, label string)

func (*Block) JumpLTImm64

func (b *Block) JumpLTImm64(ra Reg, imm int32, label string)

func (*Block) JumpNEImm32

func (b *Block) JumpNEImm32(ra Reg, imm int32, label string)

func (*Block) JumpNEImm64

func (b *Block) JumpNEImm64(ra Reg, imm int32, label string)

func (*Block) LabelNextInsn

func (b *Block) LabelNextInsn(label string)

func (*Block) Load

func (b *Block) Load(dst Reg, ptrReg Reg, fo FieldOffset, size OpCode)

func (*Block) Load16

func (b *Block) Load16(dst Reg, ptrReg Reg, fo FieldOffset)

func (*Block) Load32

func (b *Block) Load32(dst Reg, ptrReg Reg, fo FieldOffset)

func (*Block) Load64

func (b *Block) Load64(dst Reg, ptrReg Reg, fo FieldOffset)

func (*Block) Load8

func (b *Block) Load8(dst Reg, ptrReg Reg, fo FieldOffset)

func (*Block) LoadImm64

func (b *Block) LoadImm64(dst Reg, imm int64)

LoadImm64 loads a 64-bit immediate into a register. Double-length instruction.

func (*Block) LoadMapFD

func (b *Block) LoadMapFD(dst Reg, fd uint32)

LoadMapFD special variant of LoadImm64 for loading map FDs.

func (*Block) LoadStack16

func (b *Block) LoadStack16(dst Reg, fo FieldOffset)

func (*Block) LoadStack32

func (b *Block) LoadStack32(dst Reg, fo FieldOffset)

func (*Block) LoadStack64

func (b *Block) LoadStack64(dst Reg, fo FieldOffset)

func (*Block) LoadStack8

func (b *Block) LoadStack8(dst Reg, fo FieldOffset)

func (*Block) Mov64

func (b *Block) Mov64(dst, src Reg)

func (*Block) MovImm32

func (b *Block) MovImm32(dst Reg, imm int32)

func (*Block) MovImm64

func (b *Block) MovImm64(dst Reg, imm int32)

func (*Block) ShiftLImm64

func (b *Block) ShiftLImm64(dst Reg, imm int32)

func (*Block) ShiftRImm64

func (b *Block) ShiftRImm64(dst Reg, imm int32)

func (*Block) Store16

func (b *Block) Store16(dst Reg, ptrReg Reg, fo FieldOffset)

func (*Block) Store32

func (b *Block) Store32(dst Reg, ptrReg Reg, fo FieldOffset)

func (*Block) Store64

func (b *Block) Store64(dst Reg, ptrReg Reg, fo FieldOffset)

func (*Block) Store8

func (b *Block) Store8(dst Reg, ptrReg Reg, fo FieldOffset)

func (*Block) StoreStack16

func (b *Block) StoreStack16(src Reg, offset int16)

func (*Block) StoreStack32

func (b *Block) StoreStack32(src Reg, offset int16)

func (*Block) StoreStack64

func (b *Block) StoreStack64(src Reg, offset int16)

func (*Block) StoreStack8

func (b *Block) StoreStack8(src Reg, offset int16)

func (*Block) TargetIsUsed

func (b *Block) TargetIsUsed(label string) bool

type FieldOffset

type FieldOffset struct {
	Offset int16
	Field  string
}

type Helper

type Helper int32
const (
	HelperUnspec                 Helper = 0
	HelperMapLookupElem          Helper = 1
	HelperMapUpdateElem          Helper = 2
	HelperMapDeleteElem          Helper = 3
	HelperProbeRead              Helper = 4
	HelperKtimeGetNs             Helper = 5
	HelperTracePrintk            Helper = 6
	HelperGetPrandomU32          Helper = 7
	HelperGetSmpProcessorId      Helper = 8
	HelperSkbStoreBytes          Helper = 9
	HelperL3CsumReplace          Helper = 10
	HelperL4CsumReplace          Helper = 11
	HelperTailCall               Helper = 12
	HelperCloneRedirect          Helper = 13
	HelperGetCurrentPidTgid      Helper = 14
	HelperGetCurrentUidGid       Helper = 15
	HelperGetCurrentComm         Helper = 16
	HelperGetCgroupClassid       Helper = 17
	HelperSkbVlanPush            Helper = 18
	HelperSkbVlanPop             Helper = 19
	HelperSkbGetTunnelKey        Helper = 20
	HelperSkbSetTunnelKey        Helper = 21
	HelperPerfEventRead          Helper = 22
	HelperRedirect               Helper = 23
	HelperGetRouteRealm          Helper = 24
	HelperPerfEventOutput        Helper = 25
	HelperSkbLoadBytes           Helper = 26
	HelperGetStackid             Helper = 27
	HelperCsumDiff               Helper = 28
	HelperSkbGetTunnelOpt        Helper = 29
	HelperSkbSetTunnelOpt        Helper = 30
	HelperSkbChangeProto         Helper = 31
	HelperSkbChangeType          Helper = 32
	HelperSkbUnderCgroup         Helper = 33
	HelperGetHashRecalc          Helper = 34
	HelperGetCurrentTask         Helper = 35
	HelperProbeWriteUser         Helper = 36
	HelperCurrentTaskUnderCgroup Helper = 37
	HelperSkbChangeTail          Helper = 38
	HelperSkbPullData            Helper = 39
	HelperCsumUpdate             Helper = 40
	HelperSetHashInvalid         Helper = 41
	HelperGetNumaNodeId          Helper = 42
	HelperSkbChangeHead          Helper = 43
	HelperXdpAdjustHead          Helper = 44
	HelperProbeReadStr           Helper = 45
	HelperGetSocketCookie        Helper = 46
	HelperGetSocketUid           Helper = 47
	HelperSetHash                Helper = 48
	HelperSetsockopt             Helper = 49
	HelperSkbAdjustRoom          Helper = 50
	HelperRedirectMap            Helper = 51
	HelperSkRedirectMap          Helper = 52
	HelperSockMapUpdate          Helper = 53
	HelperXdpAdjustMeta          Helper = 54
	HelperPerfEventReadValue     Helper = 55
	HelperPerfProgReadValue      Helper = 56
	HelperGetsockopt             Helper = 57
	HelperOverrideReturn         Helper = 58
	HelperSockOpsCbFlagsSet      Helper = 59
	HelperMsgRedirectMap         Helper = 60
	HelperMsgApplyBytes          Helper = 61
	HelperMsgCorkBytes           Helper = 62
	HelperMsgPullData            Helper = 63
	HelperBind                   Helper = 64
	HelperXdpAdjustTail          Helper = 65
	HelperSkbGetXfrmState        Helper = 66
	HelperGetStack               Helper = 67
	HelperSkbLoadBytesRelative   Helper = 68
	HelperFibLookup              Helper = 69
	HelperSockHashUpdate         Helper = 70
	HelperMsgRedirectHash        Helper = 71
	HelperSkRedirectHash         Helper = 72
	HelperLwtPushEncap           Helper = 73
	HelperLwtSeg6StoreBytes      Helper = 74
	HelperLwtSeg6AdjustSrh       Helper = 75
	HelperLwtSeg6Action          Helper = 76
	HelperRcRepeat               Helper = 77
	HelperRcKeydown              Helper = 78
	HelperSkbCgroupId            Helper = 79
	HelperGetCurrentCgroupId     Helper = 80
	HelperGetLocalStorage        Helper = 81
	HelperSkSelectReuseport      Helper = 82
	HelperSkbAncestorCgroupId    Helper = 83
	HelperSkLookupTcp            Helper = 84
	HelperSkLookupUdp            Helper = 85
	HelperSkRelease              Helper = 86
	HelperMapPushElem            Helper = 87
	HelperMapPopElem             Helper = 88
	HelperMapPeekElem            Helper = 89
	HelperMsgPushData            Helper = 90
	HelperMsgPopData             Helper = 91
	HelperRcPointerRel           Helper = 92
	HelperSpinLock               Helper = 93
	HelperSpinUnlock             Helper = 94
	HelperSkFullsock             Helper = 95
	HelperTcpSock                Helper = 96
	HelperSkbEcnSetCe            Helper = 97
	HelperGetListenerSock        Helper = 98
	HelperSkcLookupTcp           Helper = 99
	HelperTcpCheckSyncookie      Helper = 100
	HelperSysctlGetName          Helper = 101
	HelperSysctlGetCurrentValue  Helper = 102
	HelperSysctlGetNewValue      Helper = 103
	HelperSysctlSetNewValue      Helper = 104
	HelperStrtol                 Helper = 105
	HelperStrtoul                Helper = 106
	HelperSkStorageGet           Helper = 107
	HelperSkStorageDelete        Helper = 108
	HelperSendSignal             Helper = 109
	HelperTcpGenSyncookie        Helper = 110
	HelperSkbOutput              Helper = 111
	HelperProbeReadUser          Helper = 112
	HelperProbeReadKernel        Helper = 113
	HelperProbeReadUserStr       Helper = 114
	HelperProbeReadKernelStr     Helper = 115
)

noinspection GoUnusedConst

type Insn

type Insn struct {
	Instruction [InstructionSize]uint8 `json:"inst"`
	Labels      []string               `json:"labels,omitempty"`
	Comments    []string               `json:"comments,omitempty"`
	Annotation  string                 `json:"annotation,omitempty"`
}

func MakeInsn

func MakeInsn(opcode OpCode, dst, src Reg, offset int16, imm int32) Insn

func (Insn) Dst

func (n Insn) Dst() Reg

func (Insn) Imm

func (n Insn) Imm() int32

func (Insn) Off

func (n Insn) Off() int16

func (Insn) OpCode

func (n Insn) OpCode() OpCode

func (Insn) Src

func (n Insn) Src() Reg

func (Insn) String

func (n Insn) String() string

type Insns

type Insns []Insn

func (Insns) AsBytes

func (ns Insns) AsBytes() []byte

type OffsetFixer

type OffsetFixer func(origInsn Insn) Insn

type OpCode

type OpCode uint8

func (OpCode) String

func (i OpCode) String() string

type Reg

type Reg int

func (Reg) String

func (i Reg) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL