emulator

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2022 License: MIT Imports: 9 Imported by: 1

Documentation

Overview

package emulator contains a userspace emulator/runtime for eBPF.

The primary use cases I can currently think of are:

  • Debugging, we can't debug eBPF programs when they run in the kernel, it would be nice if we have the option to start a debugger session for an eBPF program just like we do with dlv or gdb for userspace applications.
  • Dynamic program extension, ultimately eBPF was made as a sort of plugin language for the kernel, but it doesn't have to be limited to that. We could create a plugin system for go programs based on eBPF code, much like how some people use lua or javascript.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MapDeleteElement

func MapDeleteElement(vm *VM) error

MapDeleteElement implements the bpf_map_delete_element helper

func MapLookupElement

func MapLookupElement(vm *VM) error

MapLookupElement implements the bpf_map_lookup_element helper

func MapUpdateElement

func MapUpdateElement(vm *VM) error

MapUpdateElement implements the bpf_map_update_element helper

Types

type ARSH32

type ARSH32 struct {
	ebpf.ARSH32
}

func (*ARSH32) Clone

func (i *ARSH32) Clone() Instruction

func (*ARSH32) Execute

func (i *ARSH32) Execute(vm *VM) error

type ARSH32Register

type ARSH32Register struct {
	ebpf.ARSH32Register
}

func (*ARSH32Register) Clone

func (i *ARSH32Register) Clone() Instruction

func (*ARSH32Register) Execute

func (i *ARSH32Register) Execute(vm *VM) error

type ARSH64

type ARSH64 struct {
	ebpf.ARSH64
}

func (*ARSH64) Clone

func (i *ARSH64) Clone() Instruction

func (*ARSH64) Execute

func (i *ARSH64) Execute(vm *VM) error

type ARSH64Register

type ARSH64Register struct {
	ebpf.ARSH64Register
}

func (*ARSH64Register) Clone

func (i *ARSH64Register) Clone() Instruction

func (*ARSH64Register) Execute

func (i *ARSH64Register) Execute(vm *VM) error

type Add32

type Add32 struct {
	ebpf.Add32
}

func (*Add32) Clone

func (i *Add32) Clone() Instruction

func (*Add32) Execute

func (i *Add32) Execute(vm *VM) error

type Add32Register

type Add32Register struct {
	ebpf.Add32Register
}

func (*Add32Register) Clone

func (i *Add32Register) Clone() Instruction

func (*Add32Register) Execute

func (i *Add32Register) Execute(vm *VM) error

type Add64

type Add64 struct {
	ebpf.Add64
}

func (*Add64) Clone

func (i *Add64) Clone() Instruction

func (*Add64) Execute

func (i *Add64) Execute(vm *VM) error

type Add64Register

type Add64Register struct {
	ebpf.Add64Register
}

func (*Add64Register) Clone

func (i *Add64Register) Clone() Instruction

func (*Add64Register) Execute

func (i *Add64Register) Execute(vm *VM) error

type And32

type And32 struct {
	ebpf.And32
}

func (*And32) Clone

func (i *And32) Clone() Instruction

func (*And32) Execute

func (i *And32) Execute(vm *VM) error

type And32Register

type And32Register struct {
	ebpf.And32Register
}

func (*And32Register) Clone

func (i *And32Register) Clone() Instruction

func (*And32Register) Execute

func (i *And32Register) Execute(vm *VM) error

type And64

type And64 struct {
	ebpf.And64
}

func (*And64) Clone

func (i *And64) Clone() Instruction

func (*And64) Execute

func (i *And64) Execute(vm *VM) error

type And64Register

type And64Register struct {
	ebpf.And64Register
}

func (*And64Register) Clone

func (i *And64Register) Clone() Instruction

func (*And64Register) Execute

func (i *And64Register) Execute(vm *VM) error

type ArrayMap

type ArrayMap struct {
	Name          string
	Def           gobpfld.BPFMapDef
	Memory        ByteMemory
	InitialDataBO binary.ByteOrder
	InitialData   map[interface{}]interface{}
}

func (*ArrayMap) Delete

func (m *ArrayMap) Delete(key RegisterValue, flags bpfsys.BPFAttrMapElemFlags) error

func (*ArrayMap) GetDef

func (m *ArrayMap) GetDef() gobpfld.BPFMapDef

func (*ArrayMap) GetName

func (m *ArrayMap) GetName() string

func (*ArrayMap) Init

func (m *ArrayMap) Init() error

func (*ArrayMap) Lookup

func (m *ArrayMap) Lookup(key RegisterValue) (RegisterValue, error)

func (*ArrayMap) Update

func (m *ArrayMap) Update(
	key RegisterValue,
	value RegisterValue,
	flags bpfsys.BPFAttrMapElemFlags,
) (
	RegisterValue,
	error,
)

type AtomicAdd

type AtomicAdd struct {
	ebpf.AtomicAdd
}

func (*AtomicAdd) Clone

func (i *AtomicAdd) Clone() Instruction

func (*AtomicAdd) Execute

func (i *AtomicAdd) Execute(vm *VM) error

type ByteMemory

type ByteMemory struct {
	ByteOrder binary.ByteOrder
	Backing   []byte
}

ByteMemory is a type of memory which is backed by a []byte with no type info, all values read will be IMM. Since the bytes may be directly loaded from ELF files with a byte order different from the host, reads and writes will happen according to the given byte order.

func (*ByteMemory) Clone

func (bm *ByteMemory) Clone() Memory

func (*ByteMemory) Read

func (bm *ByteMemory) Read(offset int, size ebpf.Size) (RegisterValue, error)

func (*ByteMemory) Size

func (bm *ByteMemory) Size() int

func (*ByteMemory) Write

func (bm *ByteMemory) Write(offset int, value RegisterValue, size ebpf.Size) error

type CallBPF

type CallBPF struct {
	ebpf.CallBPF
}

func (*CallBPF) Clone

func (i *CallBPF) Clone() Instruction

func (*CallBPF) Execute

func (i *CallBPF) Execute(vm *VM) error

type CallHelper

type CallHelper struct {
	ebpf.CallHelper
}

func (*CallHelper) Clone

func (i *CallHelper) Clone() Instruction

func (*CallHelper) Execute

func (i *CallHelper) Execute(vm *VM) error

type CallHelperIndirect

type CallHelperIndirect struct {
	ebpf.CallHelperIndirect
}

func (*CallHelperIndirect) Clone

func (i *CallHelperIndirect) Clone() Instruction

func (*CallHelperIndirect) Execute

func (i *CallHelperIndirect) Execute(vm *VM) error

type Div32

type Div32 struct {
	ebpf.Div32
}

func (*Div32) Clone

func (i *Div32) Clone() Instruction

func (*Div32) Execute

func (i *Div32) Execute(vm *VM) error

type Div32Register

type Div32Register struct {
	ebpf.Div32Register
}

func (*Div32Register) Clone

func (i *Div32Register) Clone() Instruction

func (*Div32Register) Execute

func (i *Div32Register) Execute(vm *VM) error

type Div64

type Div64 struct {
	ebpf.Div64
}

func (*Div64) Clone

func (i *Div64) Clone() Instruction

func (*Div64) Execute

func (i *Div64) Execute(vm *VM) error

type Div64Register

type Div64Register struct {
	ebpf.Div64Register
}

func (*Div64Register) Clone

func (i *Div64Register) Clone() Instruction

func (*Div64Register) Execute

func (i *Div64Register) Execute(vm *VM) error

type End16ToBE

type End16ToBE struct {
	ebpf.End16ToBE
}

func (*End16ToBE) Clone

func (i *End16ToBE) Clone() Instruction

func (*End16ToBE) Execute

func (i *End16ToBE) Execute(vm *VM) error

type End16ToLE

type End16ToLE struct {
	ebpf.End16ToLE
}

func (*End16ToLE) Clone

func (i *End16ToLE) Clone() Instruction

func (*End16ToLE) Execute

func (i *End16ToLE) Execute(vm *VM) error

type End32ToBE

type End32ToBE struct {
	ebpf.End32ToBE
}

func (*End32ToBE) Clone

func (i *End32ToBE) Clone() Instruction

func (*End32ToBE) Execute

func (i *End32ToBE) Execute(vm *VM) error

type End32ToLE

type End32ToLE struct {
	ebpf.End32ToLE
}

func (*End32ToLE) Clone

func (i *End32ToLE) Clone() Instruction

func (*End32ToLE) Execute

func (i *End32ToLE) Execute(vm *VM) error

type End64ToBE

type End64ToBE struct {
	ebpf.End64ToBE
}

func (*End64ToBE) Clone

func (i *End64ToBE) Clone() Instruction

func (*End64ToBE) Execute

func (i *End64ToBE) Execute(vm *VM) error

type End64ToLE

type End64ToLE struct {
	ebpf.End64ToLE
}

func (*End64ToLE) Clone

func (i *End64ToLE) Clone() Instruction

func (*End64ToLE) Execute

func (i *End64ToLE) Execute(vm *VM) error

type Exit

type Exit struct {
	ebpf.Exit
}

func (*Exit) Clone

func (i *Exit) Clone() Instruction

func (*Exit) Execute

func (i *Exit) Execute(vm *VM) error

type FramePointer

type FramePointer struct {
	// Slice of the actual underlying memory
	Memory Memory
	// The index of the current stack frame
	Index int
	// Offset into the stack frame
	Offset int64
	// If true, the offset may not be modified
	Readonly bool
}

FramePointer is a memory pointer just like the MemoryPointer, the major difference is that a FramePointer will always point to a Piece of memory which is part of the stack frame. We have a distinct type for two reasons, first is that the frame pointer at R10 is read-only, only copies are writable. Second is that frame pointers always point at the end of a block of memory instread of the start.

func (*FramePointer) Assign

func (mp *FramePointer) Assign(v int64) error

func (*FramePointer) Clone

func (mp *FramePointer) Clone() RegisterValue

func (*FramePointer) Copy

func (mp *FramePointer) Copy() RegisterValue

func (*FramePointer) Deref

func (mp *FramePointer) Deref(offset int, size ebpf.Size) (RegisterValue, error)

func (*FramePointer) String

func (mp *FramePointer) String() string

func (*FramePointer) Value

func (mp *FramePointer) Value() int64

type HelperFunc

type HelperFunc func(vm *VM) error

HelperFunc are functions in go space which can be called from the eBPF VM. They are used expand eBPF capabilities without giving the VM direct access, much like a syscall in an OS context. A helper function by convention will return a single value in R0, is passed R1-R5 as arguments and should never touch R6-R9. A helper can gracefully return an error via R0, returning an error from the Go function means there is no graceful way to handle the error and will cause the VM to abort execution.

func LinuxHelperFunctions

func LinuxHelperFunctions() []HelperFunc

LinuxHelperFunctions returns a helper function array of helper functions which are compatible with the linux helper functions as defined in https://github.com/libbpf/libbpf/blob/master/src/bpf_helper_defs.h

type IMMValue

type IMMValue int64

IMMValue is an immediate value, has no special meaning

func (*IMMValue) Assign

func (iv *IMMValue) Assign(v int64) error

func (*IMMValue) Clone

func (iv *IMMValue) Clone() RegisterValue

func (*IMMValue) Copy

func (iv *IMMValue) Copy() RegisterValue

func (*IMMValue) String

func (iv *IMMValue) String() string

func (*IMMValue) Value

func (iv *IMMValue) Value() int64

type Instruction

type Instruction interface {
	ebpf.Instruction

	Clone() Instruction
	Execute(vm *VM) error
}

Instruction represents an eBPF instruction, as apposed to the ebpf.Instruction interface, these instruction can actually be executed by an emulator VM.

func Translate

func Translate(prog []ebpf.Instruction) ([]Instruction, error)

Translate translates the High level instructions of the ebpf package and embeds them into instructions defined by the emulator package. The emulator instructions contain the logic to actually execute them.

type Jump

type Jump struct {
	ebpf.Jump
}

func (*Jump) Clone

func (i *Jump) Clone() Instruction

func (*Jump) Execute

func (i *Jump) Execute(vm *VM) error

type JumpAnd

type JumpAnd struct {
	ebpf.JumpAnd
}

func (*JumpAnd) Clone

func (i *JumpAnd) Clone() Instruction

func (*JumpAnd) Execute

func (i *JumpAnd) Execute(vm *VM) error

type JumpAnd32

type JumpAnd32 struct {
	ebpf.JumpAnd32
}

func (*JumpAnd32) Clone

func (i *JumpAnd32) Clone() Instruction

func (*JumpAnd32) Execute

func (i *JumpAnd32) Execute(vm *VM) error

type JumpAndRegister

type JumpAndRegister struct {
	ebpf.JumpAndRegister
}

func (*JumpAndRegister) Clone

func (i *JumpAndRegister) Clone() Instruction

func (*JumpAndRegister) Execute

func (i *JumpAndRegister) Execute(vm *VM) error

type JumpAndRegister32

type JumpAndRegister32 struct {
	ebpf.JumpAndRegister32
}

func (*JumpAndRegister32) Clone

func (i *JumpAndRegister32) Clone() Instruction

func (*JumpAndRegister32) Execute

func (i *JumpAndRegister32) Execute(vm *VM) error

type JumpEqual

type JumpEqual struct {
	ebpf.JumpEqual
}

func (*JumpEqual) Clone

func (i *JumpEqual) Clone() Instruction

func (*JumpEqual) Execute

func (i *JumpEqual) Execute(vm *VM) error

type JumpEqual32

type JumpEqual32 struct {
	ebpf.JumpEqual32
}

func (*JumpEqual32) Clone

func (i *JumpEqual32) Clone() Instruction

func (*JumpEqual32) Execute

func (i *JumpEqual32) Execute(vm *VM) error

type JumpEqualRegister

type JumpEqualRegister struct {
	ebpf.JumpEqualRegister
}

func (*JumpEqualRegister) Clone

func (i *JumpEqualRegister) Clone() Instruction

func (*JumpEqualRegister) Execute

func (i *JumpEqualRegister) Execute(vm *VM) error

type JumpEqualRegister32

type JumpEqualRegister32 struct {
	ebpf.JumpEqualRegister32
}

func (*JumpEqualRegister32) Clone

func (i *JumpEqualRegister32) Clone() Instruction

func (*JumpEqualRegister32) Execute

func (i *JumpEqualRegister32) Execute(vm *VM) error

type JumpGreaterThan

type JumpGreaterThan struct {
	ebpf.JumpGreaterThan
}

func (*JumpGreaterThan) Clone

func (i *JumpGreaterThan) Clone() Instruction

func (*JumpGreaterThan) Execute

func (i *JumpGreaterThan) Execute(vm *VM) error

type JumpGreaterThan32

type JumpGreaterThan32 struct {
	ebpf.JumpGreaterThan32
}

func (*JumpGreaterThan32) Clone

func (i *JumpGreaterThan32) Clone() Instruction

func (*JumpGreaterThan32) Execute

func (i *JumpGreaterThan32) Execute(vm *VM) error

type JumpGreaterThanEqual

type JumpGreaterThanEqual struct {
	ebpf.JumpGreaterThanEqual
}

func (*JumpGreaterThanEqual) Clone

func (i *JumpGreaterThanEqual) Clone() Instruction

func (*JumpGreaterThanEqual) Execute

func (i *JumpGreaterThanEqual) Execute(vm *VM) error

type JumpGreaterThanEqual32

type JumpGreaterThanEqual32 struct {
	ebpf.JumpGreaterThanEqual32
}

func (*JumpGreaterThanEqual32) Clone

func (*JumpGreaterThanEqual32) Execute

func (i *JumpGreaterThanEqual32) Execute(vm *VM) error

type JumpGreaterThanEqualRegister

type JumpGreaterThanEqualRegister struct {
	ebpf.JumpGreaterThanEqualRegister
}

func (*JumpGreaterThanEqualRegister) Clone

func (*JumpGreaterThanEqualRegister) Execute

func (i *JumpGreaterThanEqualRegister) Execute(vm *VM) error

type JumpGreaterThanEqualRegister32

type JumpGreaterThanEqualRegister32 struct {
	ebpf.JumpGreaterThanEqualRegister32
}

func (*JumpGreaterThanEqualRegister32) Clone

func (*JumpGreaterThanEqualRegister32) Execute

func (i *JumpGreaterThanEqualRegister32) Execute(vm *VM) error

type JumpGreaterThanRegister

type JumpGreaterThanRegister struct {
	ebpf.JumpGreaterThanRegister
}

func (*JumpGreaterThanRegister) Clone

func (*JumpGreaterThanRegister) Execute

func (i *JumpGreaterThanRegister) Execute(vm *VM) error

type JumpGreaterThanRegister32

type JumpGreaterThanRegister32 struct {
	ebpf.JumpGreaterThanRegister32
}

func (*JumpGreaterThanRegister32) Clone

func (*JumpGreaterThanRegister32) Execute

func (i *JumpGreaterThanRegister32) Execute(vm *VM) error

type JumpNotEqual

type JumpNotEqual struct {
	ebpf.JumpNotEqual
}

func (*JumpNotEqual) Clone

func (i *JumpNotEqual) Clone() Instruction

func (*JumpNotEqual) Execute

func (i *JumpNotEqual) Execute(vm *VM) error

type JumpNotEqual32

type JumpNotEqual32 struct {
	ebpf.JumpNotEqual32
}

func (*JumpNotEqual32) Clone

func (i *JumpNotEqual32) Clone() Instruction

func (*JumpNotEqual32) Execute

func (i *JumpNotEqual32) Execute(vm *VM) error

type JumpNotEqualRegister

type JumpNotEqualRegister struct {
	ebpf.JumpNotEqualRegister
}

func (*JumpNotEqualRegister) Clone

func (i *JumpNotEqualRegister) Clone() Instruction

func (*JumpNotEqualRegister) Execute

func (i *JumpNotEqualRegister) Execute(vm *VM) error

type JumpNotEqualRegister32

type JumpNotEqualRegister32 struct {
	ebpf.JumpNotEqualRegister32
}

func (*JumpNotEqualRegister32) Clone

func (*JumpNotEqualRegister32) Execute

func (i *JumpNotEqualRegister32) Execute(vm *VM) error

type JumpSignedGreaterThan

type JumpSignedGreaterThan struct {
	ebpf.JumpSignedGreaterThan
}

func (*JumpSignedGreaterThan) Clone

func (*JumpSignedGreaterThan) Execute

func (i *JumpSignedGreaterThan) Execute(vm *VM) error

type JumpSignedGreaterThan32

type JumpSignedGreaterThan32 struct {
	ebpf.JumpSignedGreaterThan32
}

func (*JumpSignedGreaterThan32) Clone

func (*JumpSignedGreaterThan32) Execute

func (i *JumpSignedGreaterThan32) Execute(vm *VM) error

type JumpSignedGreaterThanOrEqual

type JumpSignedGreaterThanOrEqual struct {
	ebpf.JumpSignedGreaterThanOrEqual
}

func (*JumpSignedGreaterThanOrEqual) Clone

func (*JumpSignedGreaterThanOrEqual) Execute

func (i *JumpSignedGreaterThanOrEqual) Execute(vm *VM) error

type JumpSignedGreaterThanOrEqual32

type JumpSignedGreaterThanOrEqual32 struct {
	ebpf.JumpSignedGreaterThanOrEqual32
}

func (*JumpSignedGreaterThanOrEqual32) Clone

func (*JumpSignedGreaterThanOrEqual32) Execute

func (i *JumpSignedGreaterThanOrEqual32) Execute(vm *VM) error

type JumpSignedGreaterThanOrEqualRegister

type JumpSignedGreaterThanOrEqualRegister struct {
	ebpf.JumpSignedGreaterThanOrEqualRegister
}

func (*JumpSignedGreaterThanOrEqualRegister) Clone

func (*JumpSignedGreaterThanOrEqualRegister) Execute

type JumpSignedGreaterThanOrEqualRegister32

type JumpSignedGreaterThanOrEqualRegister32 struct {
	ebpf.JumpSignedGreaterThanOrEqualRegister32
}

func (*JumpSignedGreaterThanOrEqualRegister32) Clone

func (*JumpSignedGreaterThanOrEqualRegister32) Execute

type JumpSignedGreaterThanRegister

type JumpSignedGreaterThanRegister struct {
	ebpf.JumpSignedGreaterThanRegister
}

func (*JumpSignedGreaterThanRegister) Clone

func (*JumpSignedGreaterThanRegister) Execute

func (i *JumpSignedGreaterThanRegister) Execute(vm *VM) error

type JumpSignedGreaterThanRegister32

type JumpSignedGreaterThanRegister32 struct {
	ebpf.JumpSignedGreaterThanRegister32
}

func (*JumpSignedGreaterThanRegister32) Clone

func (*JumpSignedGreaterThanRegister32) Execute

func (i *JumpSignedGreaterThanRegister32) Execute(vm *VM) error

type JumpSignedSmallerThan

type JumpSignedSmallerThan struct {
	ebpf.JumpSignedSmallerThan
}

func (*JumpSignedSmallerThan) Clone

func (*JumpSignedSmallerThan) Execute

func (i *JumpSignedSmallerThan) Execute(vm *VM) error

type JumpSignedSmallerThan32

type JumpSignedSmallerThan32 struct {
	ebpf.JumpSignedSmallerThan32
}

func (*JumpSignedSmallerThan32) Clone

func (*JumpSignedSmallerThan32) Execute

func (i *JumpSignedSmallerThan32) Execute(vm *VM) error

type JumpSignedSmallerThanOrEqual

type JumpSignedSmallerThanOrEqual struct {
	ebpf.JumpSignedSmallerThanOrEqual
}

func (*JumpSignedSmallerThanOrEqual) Clone

func (*JumpSignedSmallerThanOrEqual) Execute

func (i *JumpSignedSmallerThanOrEqual) Execute(vm *VM) error

type JumpSignedSmallerThanOrEqual32

type JumpSignedSmallerThanOrEqual32 struct {
	ebpf.JumpSignedSmallerThanOrEqual32
}

func (*JumpSignedSmallerThanOrEqual32) Clone

func (*JumpSignedSmallerThanOrEqual32) Execute

func (i *JumpSignedSmallerThanOrEqual32) Execute(vm *VM) error

type JumpSignedSmallerThanOrEqualRegister

type JumpSignedSmallerThanOrEqualRegister struct {
	ebpf.JumpSignedSmallerThanOrEqualRegister
}

func (*JumpSignedSmallerThanOrEqualRegister) Clone

func (*JumpSignedSmallerThanOrEqualRegister) Execute

type JumpSignedSmallerThanOrEqualRegister32

type JumpSignedSmallerThanOrEqualRegister32 struct {
	ebpf.JumpSignedSmallerThanOrEqualRegister32
}

func (*JumpSignedSmallerThanOrEqualRegister32) Clone

func (*JumpSignedSmallerThanOrEqualRegister32) Execute

type JumpSignedSmallerThanRegister

type JumpSignedSmallerThanRegister struct {
	ebpf.JumpSignedSmallerThanRegister
}

func (*JumpSignedSmallerThanRegister) Clone

func (*JumpSignedSmallerThanRegister) Execute

func (i *JumpSignedSmallerThanRegister) Execute(vm *VM) error

type JumpSignedSmallerThanRegister32

type JumpSignedSmallerThanRegister32 struct {
	ebpf.JumpSignedSmallerThanRegister32
}

func (*JumpSignedSmallerThanRegister32) Clone

func (*JumpSignedSmallerThanRegister32) Execute

func (i *JumpSignedSmallerThanRegister32) Execute(vm *VM) error

type JumpSmallerThan

type JumpSmallerThan struct {
	ebpf.JumpSmallerThan
}

func (*JumpSmallerThan) Clone

func (i *JumpSmallerThan) Clone() Instruction

func (*JumpSmallerThan) Execute

func (i *JumpSmallerThan) Execute(vm *VM) error

type JumpSmallerThan32

type JumpSmallerThan32 struct {
	ebpf.JumpSmallerThan32
}

func (*JumpSmallerThan32) Clone

func (i *JumpSmallerThan32) Clone() Instruction

func (*JumpSmallerThan32) Execute

func (i *JumpSmallerThan32) Execute(vm *VM) error

type JumpSmallerThanEqual

type JumpSmallerThanEqual struct {
	ebpf.JumpSmallerThanEqual
}

func (*JumpSmallerThanEqual) Clone

func (i *JumpSmallerThanEqual) Clone() Instruction

func (*JumpSmallerThanEqual) Execute

func (i *JumpSmallerThanEqual) Execute(vm *VM) error

type JumpSmallerThanEqual32

type JumpSmallerThanEqual32 struct {
	ebpf.JumpSmallerThanEqual32
}

func (*JumpSmallerThanEqual32) Clone

func (*JumpSmallerThanEqual32) Execute

func (i *JumpSmallerThanEqual32) Execute(vm *VM) error

type JumpSmallerThanEqualRegister

type JumpSmallerThanEqualRegister struct {
	ebpf.JumpSmallerThanEqualRegister
}

func (*JumpSmallerThanEqualRegister) Clone

func (*JumpSmallerThanEqualRegister) Execute

func (i *JumpSmallerThanEqualRegister) Execute(vm *VM) error

type JumpSmallerThanEqualRegister32

type JumpSmallerThanEqualRegister32 struct {
	ebpf.JumpSmallerThanEqualRegister32
}

func (*JumpSmallerThanEqualRegister32) Clone

func (*JumpSmallerThanEqualRegister32) Execute

func (i *JumpSmallerThanEqualRegister32) Execute(vm *VM) error

type JumpSmallerThanRegister

type JumpSmallerThanRegister struct {
	ebpf.JumpSmallerThanRegister
}

func (*JumpSmallerThanRegister) Clone

func (*JumpSmallerThanRegister) Execute

func (i *JumpSmallerThanRegister) Execute(vm *VM) error

type JumpSmallerThanRegister32

type JumpSmallerThanRegister32 struct {
	ebpf.JumpSmallerThanRegister32
}

func (*JumpSmallerThanRegister32) Clone

func (*JumpSmallerThanRegister32) Execute

func (i *JumpSmallerThanRegister32) Execute(vm *VM) error

type LoadConstant64bit

type LoadConstant64bit struct {
	ebpf.LoadConstant64bit
}

func (*LoadConstant64bit) Clone

func (i *LoadConstant64bit) Clone() Instruction

func (*LoadConstant64bit) Execute

func (i *LoadConstant64bit) Execute(vm *VM) error

type LoadMemory

type LoadMemory struct {
	ebpf.LoadMemory
}

func (*LoadMemory) Clone

func (i *LoadMemory) Clone() Instruction

func (*LoadMemory) Execute

func (i *LoadMemory) Execute(vm *VM) error

type LoadSocketBuf

type LoadSocketBuf struct {
	ebpf.LoadSocketBuf
}

func (*LoadSocketBuf) Clone

func (i *LoadSocketBuf) Clone() Instruction

func (*LoadSocketBuf) Execute

func (i *LoadSocketBuf) Execute(vm *VM) error

type LoadSocketBufConstant

type LoadSocketBufConstant struct {
	ebpf.LoadSocketBufConstant
}

func (*LoadSocketBufConstant) Clone

func (*LoadSocketBufConstant) Execute

func (i *LoadSocketBufConstant) Execute(vm *VM) error

type Lsh32

type Lsh32 struct {
	ebpf.Lsh32
}

func (*Lsh32) Clone

func (i *Lsh32) Clone() Instruction

func (*Lsh32) Execute

func (i *Lsh32) Execute(vm *VM) error

type Lsh32Register

type Lsh32Register struct {
	ebpf.Lsh32Register
}

func (*Lsh32Register) Clone

func (i *Lsh32Register) Clone() Instruction

func (*Lsh32Register) Execute

func (i *Lsh32Register) Execute(vm *VM) error

type Lsh64

type Lsh64 struct {
	ebpf.Lsh64
}

func (*Lsh64) Clone

func (i *Lsh64) Clone() Instruction

func (*Lsh64) Execute

func (i *Lsh64) Execute(vm *VM) error

type Lsh64Register

type Lsh64Register struct {
	ebpf.Lsh64Register
}

func (*Lsh64Register) Clone

func (i *Lsh64Register) Clone() Instruction

func (*Lsh64Register) Execute

func (i *Lsh64Register) Execute(vm *VM) error

type Map

type Map interface {
	Init() error

	GetName() string

	GetDef() gobpfld.BPFMapDef

	// Lookup looks up a value in the map for a given key and return a pointer to the value or NULL/0 if it can't find
	// it.
	Lookup(key RegisterValue) (RegisterValue, error)

	// Update sets or updates a map with value at the given key, it returns 0 on success or a negative value
	// on error.
	Update(key RegisterValue, value RegisterValue, flags bpfsys.BPFAttrMapElemFlags) (RegisterValue, error)

	// Delete deletes the value at the given key from the map
	Delete(key RegisterValue, flags bpfsys.BPFAttrMapElemFlags) error
}

Map represents an emulated eBPF map

func AbstractMapToVM

func AbstractMapToVM(am gobpfld.AbstractMap) (Map, error)

AbstractMapToVM converts an AbstractMap to an emulated version

type Memory

type Memory interface {
	Read(offset int, size ebpf.Size) (RegisterValue, error)
	Write(offset int, value RegisterValue, size ebpf.Size) error
	Size() int
	Clone() Memory
}

Memory represents memory which can be accessed by the eBPF VM.

type MemoryPtr

type MemoryPtr struct {
	Name   string
	Memory Memory
	Offset int64
}

MemoryPtr is a pointer to a particular piece of memory. The eBPF program can't manipulate this pointer once gotten, it can only manipulate to offset from the start of the memory. When the pointer is dereferenced a lookup into the memory happens at the offset param + the offset property.

func (*MemoryPtr) Assign

func (mp *MemoryPtr) Assign(v int64) error

func (*MemoryPtr) Clone

func (mp *MemoryPtr) Clone() RegisterValue

func (*MemoryPtr) Copy

func (mp *MemoryPtr) Copy() RegisterValue

func (*MemoryPtr) Deref

func (mp *MemoryPtr) Deref(offset int, size ebpf.Size) (RegisterValue, error)

func (*MemoryPtr) String

func (mp *MemoryPtr) String() string

func (*MemoryPtr) Value

func (mp *MemoryPtr) Value() int64

type Mod32

type Mod32 struct {
	ebpf.Mod32
}

func (*Mod32) Clone

func (i *Mod32) Clone() Instruction

func (*Mod32) Execute

func (i *Mod32) Execute(vm *VM) error

type Mod32Register

type Mod32Register struct {
	ebpf.Mod32Register
}

func (*Mod32Register) Clone

func (i *Mod32Register) Clone() Instruction

func (*Mod32Register) Execute

func (i *Mod32Register) Execute(vm *VM) error

type Mod64

type Mod64 struct {
	ebpf.Mod64
}

func (*Mod64) Clone

func (i *Mod64) Clone() Instruction

func (*Mod64) Execute

func (i *Mod64) Execute(vm *VM) error

type Mod64Register

type Mod64Register struct {
	ebpf.Mod64Register
}

func (*Mod64Register) Clone

func (i *Mod64Register) Clone() Instruction

func (*Mod64Register) Execute

func (i *Mod64Register) Execute(vm *VM) error

type Mov32

type Mov32 struct {
	ebpf.Mov32
}

func (*Mov32) Clone

func (i *Mov32) Clone() Instruction

func (*Mov32) Execute

func (i *Mov32) Execute(vm *VM) error

type Mov32Register

type Mov32Register struct {
	ebpf.Mov32Register
}

func (*Mov32Register) Clone

func (i *Mov32Register) Clone() Instruction

func (*Mov32Register) Execute

func (i *Mov32Register) Execute(vm *VM) error

type Mov64

type Mov64 struct {
	ebpf.Mov64
}

func (*Mov64) Clone

func (i *Mov64) Clone() Instruction

func (*Mov64) Execute

func (i *Mov64) Execute(vm *VM) error

type Mov64Register

type Mov64Register struct {
	ebpf.Mov64Register
}

func (*Mov64Register) Clone

func (i *Mov64Register) Clone() Instruction

func (*Mov64Register) Execute

func (i *Mov64Register) Execute(vm *VM) error

type Mul32

type Mul32 struct {
	ebpf.Mul32
}

func (*Mul32) Clone

func (i *Mul32) Clone() Instruction

func (*Mul32) Execute

func (i *Mul32) Execute(vm *VM) error

type Mul32Register

type Mul32Register struct {
	ebpf.Mul32Register
}

func (*Mul32Register) Clone

func (i *Mul32Register) Clone() Instruction

func (*Mul32Register) Execute

func (i *Mul32Register) Execute(vm *VM) error

type Mul64

type Mul64 struct {
	ebpf.Mul64
}

func (*Mul64) Clone

func (i *Mul64) Clone() Instruction

func (*Mul64) Execute

func (i *Mul64) Execute(vm *VM) error

type Mul64Register

type Mul64Register struct {
	ebpf.Mul64Register
}

func (*Mul64Register) Clone

func (i *Mul64Register) Clone() Instruction

func (*Mul64Register) Execute

func (i *Mul64Register) Execute(vm *VM) error

type Neg32

type Neg32 struct {
	ebpf.Neg32
}

func (*Neg32) Clone

func (i *Neg32) Clone() Instruction

func (*Neg32) Execute

func (i *Neg32) Execute(vm *VM) error

type Neg64

type Neg64 struct {
	ebpf.Neg64
}

func (*Neg64) Clone

func (i *Neg64) Clone() Instruction

func (*Neg64) Execute

func (i *Neg64) Execute(vm *VM) error

type Nop

type Nop struct {
	ebpf.Nop
}

func (*Nop) Clone

func (i *Nop) Clone() Instruction

func (*Nop) Execute

func (i *Nop) Execute(vm *VM) error

type Or32

type Or32 struct {
	ebpf.Or32
}

func (*Or32) Clone

func (i *Or32) Clone() Instruction

func (*Or32) Execute

func (i *Or32) Execute(vm *VM) error

type Or32Register

type Or32Register struct {
	ebpf.Or32Register
}

func (*Or32Register) Clone

func (i *Or32Register) Clone() Instruction

func (*Or32Register) Execute

func (i *Or32Register) Execute(vm *VM) error

type Or64

type Or64 struct {
	ebpf.Or64
}

func (*Or64) Clone

func (i *Or64) Clone() Instruction

func (*Or64) Execute

func (i *Or64) Execute(vm *VM) error

type Or64Register

type Or64Register struct {
	ebpf.Or64Register
}

func (*Or64Register) Clone

func (i *Or64Register) Clone() Instruction

func (*Or64Register) Execute

func (i *Or64Register) Execute(vm *VM) error

type PointerValue

type PointerValue interface {
	Deref(offset int, size ebpf.Size) (RegisterValue, error)
}

PointerValue is a type of RegisterValue which can be dereferenced.

type RegisterValue

type RegisterValue interface {
	// Value returns the integer value of the register
	Value() int64
	// Copy returns a copy of the register.
	// A copy can have different properties, like being modifyable while the original was not, the stack pointer for
	// example.
	Copy() RegisterValue
	// Clone makes an exact copy of the register, with no differences.
	Clone() RegisterValue
	Assign(int64) error
	String() string
}

RegisterValue represents the contents of a single register. Depending on the implementation a register type might carry additional information which is not directly accessible to the eBPF program. The additional type information is created and changed depending on where he eBPF program gets the value and what it does with it.

type Registers

type Registers struct {
	// Program counter, keeps track of which instruction to execute next, can't be read, only be modified
	// via branching instructions.
	PC int
	// Program index, keeps track of which program we are executing.
	PI int
	// Stack frame number of the current stack frame, increments when we tailcall or do a bpf-to-bpf function call
	// and decrements after we return from a bpf-to-bpf function call.
	SF int

	// return value from function calls, and exit value for eBPF programs
	R0 RegisterValue

	// arguments for function calls
	R1 RegisterValue
	R2 RegisterValue
	R3 RegisterValue
	R4 RegisterValue
	R5 RegisterValue

	// callee saved registers that function calls will preserve
	R6 RegisterValue
	R7 RegisterValue
	R8 RegisterValue
	R9 RegisterValue

	// read-only frame pointer to access stack
	R10 FramePointer
}

Registers the registers of the eBPF VM https://github.com/torvalds/linux/blob/master/Documentation/bpf/instruction-set.rst#Registers-and-calling-convention

R0 - R5 are scratch Registers and eBPF programs needs to spill/fill them if necessary across calls.

func (*Registers) Assign

func (r *Registers) Assign(reg ebpf.Register, value RegisterValue) error

Assign is used to assign a value to a register directly

func (*Registers) Clone

func (r *Registers) Clone() Registers

func (*Registers) Copy

func (r *Registers) Copy(reg ebpf.Register) (RegisterValue, error)

func (*Registers) Get

func (r *Registers) Get(reg ebpf.Register) (RegisterValue, error)

type Rsh32

type Rsh32 struct {
	ebpf.Rsh32
}

func (*Rsh32) Clone

func (i *Rsh32) Clone() Instruction

func (*Rsh32) Execute

func (i *Rsh32) Execute(vm *VM) error

type Rsh32Register

type Rsh32Register struct {
	ebpf.Rsh32Register
}

func (*Rsh32Register) Clone

func (i *Rsh32Register) Clone() Instruction

func (*Rsh32Register) Execute

func (i *Rsh32Register) Execute(vm *VM) error

type Rsh64

type Rsh64 struct {
	ebpf.Rsh64
}

func (*Rsh64) Clone

func (i *Rsh64) Clone() Instruction

func (*Rsh64) Execute

func (i *Rsh64) Execute(vm *VM) error

type Rsh64Register

type Rsh64Register struct {
	ebpf.Rsh64Register
}

func (*Rsh64Register) Clone

func (i *Rsh64Register) Clone() Instruction

func (*Rsh64Register) Execute

func (i *Rsh64Register) Execute(vm *VM) error

type StoreMemoryConstant

type StoreMemoryConstant struct {
	ebpf.StoreMemoryConstant
}

func (*StoreMemoryConstant) Clone

func (i *StoreMemoryConstant) Clone() Instruction

func (*StoreMemoryConstant) Execute

func (i *StoreMemoryConstant) Execute(vm *VM) error

type StoreMemoryRegister

type StoreMemoryRegister struct {
	ebpf.StoreMemoryRegister
}

func (*StoreMemoryRegister) Clone

func (i *StoreMemoryRegister) Clone() Instruction

func (*StoreMemoryRegister) Execute

func (i *StoreMemoryRegister) Execute(vm *VM) error

type Sub32

type Sub32 struct {
	ebpf.Sub32
}

func (*Sub32) Clone

func (i *Sub32) Clone() Instruction

func (*Sub32) Execute

func (i *Sub32) Execute(vm *VM) error

type Sub32Register

type Sub32Register struct {
	ebpf.Sub32Register
}

func (*Sub32Register) Clone

func (i *Sub32Register) Clone() Instruction

func (*Sub32Register) Execute

func (i *Sub32Register) Execute(vm *VM) error

type Sub64

type Sub64 struct {
	ebpf.Sub64
}

func (*Sub64) Clone

func (i *Sub64) Clone() Instruction

func (*Sub64) Execute

func (i *Sub64) Execute(vm *VM) error

type Sub64Register

type Sub64Register struct {
	ebpf.Sub64Register
}

func (*Sub64Register) Clone

func (i *Sub64Register) Clone() Instruction

func (*Sub64Register) Execute

func (i *Sub64Register) Execute(vm *VM) error

type VM

type VM struct {
	Registers Registers
	// A slice of frames, each frame is represented by a byte slice
	StackFrames []ValueMemory
	// A stack of program counter values, each time a function bpf-to-bpf function call is made, we push the current PC.
	// Each time we hit an exit, we pop a value, if no values are left, we exit.
	CallStack       []int
	HelperFunctions []HelperFunc

	// A slice of eBPF programs
	Programs [][]Instruction
	Maps     []Map
	// contains filtered or unexported fields
}

VM is a virtual machine which can run eBPF code.

func NewVM

func NewVM(settings VMSettings) (*VM, error)

func (*VM) AddAbstractMap

func (vm *VM) AddAbstractMap(am gobpfld.AbstractMap) (int, error)

func (*VM) AddMap

func (vm *VM) AddMap(m Map) (int, error)

func (*VM) AddProgram

func (vm *VM) AddProgram(prog []ebpf.Instruction) error

func (*VM) AddRawProgram

func (vm *VM) AddRawProgram(prog []ebpf.RawInstruction) error

func (*VM) Clone

func (vm *VM) Clone() *VM

Clone clones the whole VM, this includes the current state of the VM. This feature can be used to create snapshots of the VM.

func (*VM) Reset

func (vm *VM) Reset()

func (*VM) Run

func (vm *VM) Run() error

func (*VM) RunContext

func (vm *VM) RunContext(ctx context.Context) error

func (*VM) SetEntrypoint

func (vm *VM) SetEntrypoint(index int) error

func (*VM) Step

func (vm *VM) Step() (stop bool, err error)

Step executes a single instruction, allowing us to "step" through the program

func (*VM) String

func (vm *VM) String() string

type VMError

type VMError struct {
	VMSnapshot *VM
	Original   error
}

A VMError is thrown by the VM and contain a copy of the state of the VM at the time of the error

func (*VMError) Error

func (e *VMError) Error() string

type VMSettings

type VMSettings struct {
	// StackFrameSize is the allocated size of a single stack frame
	StackFrameSize int
	// MaxStackFrames is the maximum number of stack frames
	MaxStackFrames int
}

func DefaultVMSettings

func DefaultVMSettings() VMSettings

DefaultVMSettings returns good default settings for the VM, they are based on the limitations of the Linux eBPF implementation

type ValueMemory

type ValueMemory struct {
	Mapping []RegisterValue
}

ValueMemory perserves type information, this is important for the functioning of the VM. Our VM implementation has no addessable memory slab in which pointers are assigned, rather in the type information we store pointers to actual memory blocks. Therefor, it is important to not lose type information when pointers are written to the stack.

func (*ValueMemory) Clone

func (vm *ValueMemory) Clone() Memory

func (*ValueMemory) Read

func (vm *ValueMemory) Read(offset int, size ebpf.Size) (RegisterValue, error)

func (*ValueMemory) Size

func (vm *ValueMemory) Size() int

func (*ValueMemory) Write

func (vm *ValueMemory) Write(offset int, value RegisterValue, size ebpf.Size) error

type Xor32

type Xor32 struct {
	ebpf.Xor32
}

func (*Xor32) Clone

func (i *Xor32) Clone() Instruction

func (*Xor32) Execute

func (i *Xor32) Execute(vm *VM) error

type Xor32Register

type Xor32Register struct {
	ebpf.Xor32Register
}

func (*Xor32Register) Clone

func (i *Xor32Register) Clone() Instruction

func (*Xor32Register) Execute

func (i *Xor32Register) Execute(vm *VM) error

type Xor64

type Xor64 struct {
	ebpf.Xor64
}

func (*Xor64) Clone

func (i *Xor64) Clone() Instruction

func (*Xor64) Execute

func (i *Xor64) Execute(vm *VM) error

type Xor64Register

type Xor64Register struct {
	ebpf.Xor64Register
}

func (*Xor64Register) Clone

func (i *Xor64Register) Clone() Instruction

func (*Xor64Register) Execute

func (i *Xor64Register) Execute(vm *VM) error

Jump to

Keyboard shortcuts

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