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 ¶
- func MapDeleteElement(vm *VM) error
- func MapLookupElement(vm *VM) error
- func MapUpdateElement(vm *VM) error
- type ARSH32
- type ARSH32Register
- type ARSH64
- type ARSH64Register
- type Add32
- type Add32Register
- type Add64
- type Add64Register
- type And32
- type And32Register
- type And64
- type And64Register
- type ArrayMap
- func (m *ArrayMap) Delete(key RegisterValue, flags bpfsys.BPFAttrMapElemFlags) error
- func (m *ArrayMap) GetDef() gobpfld.BPFMapDef
- func (m *ArrayMap) GetName() string
- func (m *ArrayMap) Init() error
- func (m *ArrayMap) Lookup(key RegisterValue) (RegisterValue, error)
- func (m *ArrayMap) Update(key RegisterValue, value RegisterValue, flags bpfsys.BPFAttrMapElemFlags) (RegisterValue, error)
- type AtomicAdd
- type ByteMemory
- type CallBPF
- type CallHelper
- type CallHelperIndirect
- type Div32
- type Div32Register
- type Div64
- type Div64Register
- type End16ToBE
- type End16ToLE
- type End32ToBE
- type End32ToLE
- type End64ToBE
- type End64ToLE
- type Exit
- type FramePointer
- type HelperFunc
- type IMMValue
- type Instruction
- type Jump
- type JumpAnd
- type JumpAnd32
- type JumpAndRegister
- type JumpAndRegister32
- type JumpEqual
- type JumpEqual32
- type JumpEqualRegister
- type JumpEqualRegister32
- type JumpGreaterThan
- type JumpGreaterThan32
- type JumpGreaterThanEqual
- type JumpGreaterThanEqual32
- type JumpGreaterThanEqualRegister
- type JumpGreaterThanEqualRegister32
- type JumpGreaterThanRegister
- type JumpGreaterThanRegister32
- type JumpNotEqual
- type JumpNotEqual32
- type JumpNotEqualRegister
- type JumpNotEqualRegister32
- type JumpSignedGreaterThan
- type JumpSignedGreaterThan32
- type JumpSignedGreaterThanOrEqual
- type JumpSignedGreaterThanOrEqual32
- type JumpSignedGreaterThanOrEqualRegister
- type JumpSignedGreaterThanOrEqualRegister32
- type JumpSignedGreaterThanRegister
- type JumpSignedGreaterThanRegister32
- type JumpSignedSmallerThan
- type JumpSignedSmallerThan32
- type JumpSignedSmallerThanOrEqual
- type JumpSignedSmallerThanOrEqual32
- type JumpSignedSmallerThanOrEqualRegister
- type JumpSignedSmallerThanOrEqualRegister32
- type JumpSignedSmallerThanRegister
- type JumpSignedSmallerThanRegister32
- type JumpSmallerThan
- type JumpSmallerThan32
- type JumpSmallerThanEqual
- type JumpSmallerThanEqual32
- type JumpSmallerThanEqualRegister
- type JumpSmallerThanEqualRegister32
- type JumpSmallerThanRegister
- type JumpSmallerThanRegister32
- type LoadConstant64bit
- type LoadMemory
- type LoadSocketBuf
- type LoadSocketBufConstant
- type Lsh32
- type Lsh32Register
- type Lsh64
- type Lsh64Register
- type Map
- type Memory
- type MemoryPtr
- type Mod32
- type Mod32Register
- type Mod64
- type Mod64Register
- type Mov32
- type Mov32Register
- type Mov64
- type Mov64Register
- type Mul32
- type Mul32Register
- type Mul64
- type Mul64Register
- type Neg32
- type Neg64
- type Nop
- type Or32
- type Or32Register
- type Or64
- type Or64Register
- type PointerValue
- type RegisterValue
- type Registers
- type Rsh32
- type Rsh32Register
- type Rsh64
- type Rsh64Register
- type StoreMemoryConstant
- type StoreMemoryRegister
- type Sub32
- type Sub32Register
- type Sub64
- type Sub64Register
- type VM
- func (vm *VM) AddAbstractMap(am gobpfld.AbstractMap) (int, error)
- func (vm *VM) AddMap(m Map) (int, error)
- func (vm *VM) AddProgram(prog []ebpf.Instruction) error
- func (vm *VM) AddRawProgram(prog []ebpf.RawInstruction) error
- func (vm *VM) Clone() *VM
- func (vm *VM) Reset()
- func (vm *VM) Run() error
- func (vm *VM) RunContext(ctx context.Context) error
- func (vm *VM) SetEntrypoint(index int) error
- func (vm *VM) Step() (stop bool, err error)
- func (vm *VM) String() string
- type VMError
- type VMSettings
- type ValueMemory
- type Xor32
- type Xor32Register
- type Xor64
- type Xor64Register
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MapDeleteElement ¶
MapDeleteElement implements the bpf_map_delete_element helper
func MapLookupElement ¶
MapLookupElement implements the bpf_map_lookup_element helper
func MapUpdateElement ¶
MapUpdateElement implements the bpf_map_update_element helper
Types ¶
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 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 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 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 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 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) 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 ByteMemory ¶
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 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 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 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 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 ¶
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) Clone ¶
func (iv *IMMValue) Clone() RegisterValue
func (*IMMValue) Copy ¶
func (iv *IMMValue) Copy() RegisterValue
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 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 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 (i *JumpGreaterThanEqual32) Clone() Instruction
func (*JumpGreaterThanEqual32) Execute ¶
func (i *JumpGreaterThanEqual32) Execute(vm *VM) error
type JumpGreaterThanEqualRegister ¶
type JumpGreaterThanEqualRegister struct {
ebpf.JumpGreaterThanEqualRegister
}
func (*JumpGreaterThanEqualRegister) Clone ¶
func (i *JumpGreaterThanEqualRegister) Clone() Instruction
func (*JumpGreaterThanEqualRegister) Execute ¶
func (i *JumpGreaterThanEqualRegister) Execute(vm *VM) error
type JumpGreaterThanEqualRegister32 ¶
type JumpGreaterThanEqualRegister32 struct {
ebpf.JumpGreaterThanEqualRegister32
}
func (*JumpGreaterThanEqualRegister32) Clone ¶
func (i *JumpGreaterThanEqualRegister32) Clone() Instruction
func (*JumpGreaterThanEqualRegister32) Execute ¶
func (i *JumpGreaterThanEqualRegister32) Execute(vm *VM) error
type JumpGreaterThanRegister ¶
type JumpGreaterThanRegister struct {
ebpf.JumpGreaterThanRegister
}
func (*JumpGreaterThanRegister) Clone ¶
func (i *JumpGreaterThanRegister) Clone() Instruction
func (*JumpGreaterThanRegister) Execute ¶
func (i *JumpGreaterThanRegister) Execute(vm *VM) error
type JumpGreaterThanRegister32 ¶
type JumpGreaterThanRegister32 struct {
ebpf.JumpGreaterThanRegister32
}
func (*JumpGreaterThanRegister32) Clone ¶
func (i *JumpGreaterThanRegister32) Clone() Instruction
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 (i *JumpNotEqualRegister32) Clone() Instruction
func (*JumpNotEqualRegister32) Execute ¶
func (i *JumpNotEqualRegister32) Execute(vm *VM) error
type JumpSignedGreaterThan ¶
type JumpSignedGreaterThan struct {
ebpf.JumpSignedGreaterThan
}
func (*JumpSignedGreaterThan) Clone ¶
func (i *JumpSignedGreaterThan) Clone() Instruction
func (*JumpSignedGreaterThan) Execute ¶
func (i *JumpSignedGreaterThan) Execute(vm *VM) error
type JumpSignedGreaterThan32 ¶
type JumpSignedGreaterThan32 struct {
ebpf.JumpSignedGreaterThan32
}
func (*JumpSignedGreaterThan32) Clone ¶
func (i *JumpSignedGreaterThan32) Clone() Instruction
func (*JumpSignedGreaterThan32) Execute ¶
func (i *JumpSignedGreaterThan32) Execute(vm *VM) error
type JumpSignedGreaterThanOrEqual ¶
type JumpSignedGreaterThanOrEqual struct {
ebpf.JumpSignedGreaterThanOrEqual
}
func (*JumpSignedGreaterThanOrEqual) Clone ¶
func (i *JumpSignedGreaterThanOrEqual) Clone() Instruction
func (*JumpSignedGreaterThanOrEqual) Execute ¶
func (i *JumpSignedGreaterThanOrEqual) Execute(vm *VM) error
type JumpSignedGreaterThanOrEqual32 ¶
type JumpSignedGreaterThanOrEqual32 struct {
ebpf.JumpSignedGreaterThanOrEqual32
}
func (*JumpSignedGreaterThanOrEqual32) Clone ¶
func (i *JumpSignedGreaterThanOrEqual32) Clone() Instruction
func (*JumpSignedGreaterThanOrEqual32) Execute ¶
func (i *JumpSignedGreaterThanOrEqual32) Execute(vm *VM) error
type JumpSignedGreaterThanOrEqualRegister ¶
type JumpSignedGreaterThanOrEqualRegister struct {
ebpf.JumpSignedGreaterThanOrEqualRegister
}
func (*JumpSignedGreaterThanOrEqualRegister) Clone ¶
func (i *JumpSignedGreaterThanOrEqualRegister) Clone() Instruction
func (*JumpSignedGreaterThanOrEqualRegister) Execute ¶
func (i *JumpSignedGreaterThanOrEqualRegister) Execute(vm *VM) error
type JumpSignedGreaterThanOrEqualRegister32 ¶
type JumpSignedGreaterThanOrEqualRegister32 struct {
ebpf.JumpSignedGreaterThanOrEqualRegister32
}
func (*JumpSignedGreaterThanOrEqualRegister32) Clone ¶
func (i *JumpSignedGreaterThanOrEqualRegister32) Clone() Instruction
func (*JumpSignedGreaterThanOrEqualRegister32) Execute ¶
func (i *JumpSignedGreaterThanOrEqualRegister32) Execute(vm *VM) error
type JumpSignedGreaterThanRegister ¶
type JumpSignedGreaterThanRegister struct {
ebpf.JumpSignedGreaterThanRegister
}
func (*JumpSignedGreaterThanRegister) Clone ¶
func (i *JumpSignedGreaterThanRegister) Clone() Instruction
func (*JumpSignedGreaterThanRegister) Execute ¶
func (i *JumpSignedGreaterThanRegister) Execute(vm *VM) error
type JumpSignedGreaterThanRegister32 ¶
type JumpSignedGreaterThanRegister32 struct {
ebpf.JumpSignedGreaterThanRegister32
}
func (*JumpSignedGreaterThanRegister32) Clone ¶
func (i *JumpSignedGreaterThanRegister32) Clone() Instruction
func (*JumpSignedGreaterThanRegister32) Execute ¶
func (i *JumpSignedGreaterThanRegister32) Execute(vm *VM) error
type JumpSignedSmallerThan ¶
type JumpSignedSmallerThan struct {
ebpf.JumpSignedSmallerThan
}
func (*JumpSignedSmallerThan) Clone ¶
func (i *JumpSignedSmallerThan) Clone() Instruction
func (*JumpSignedSmallerThan) Execute ¶
func (i *JumpSignedSmallerThan) Execute(vm *VM) error
type JumpSignedSmallerThan32 ¶
type JumpSignedSmallerThan32 struct {
ebpf.JumpSignedSmallerThan32
}
func (*JumpSignedSmallerThan32) Clone ¶
func (i *JumpSignedSmallerThan32) Clone() Instruction
func (*JumpSignedSmallerThan32) Execute ¶
func (i *JumpSignedSmallerThan32) Execute(vm *VM) error
type JumpSignedSmallerThanOrEqual ¶
type JumpSignedSmallerThanOrEqual struct {
ebpf.JumpSignedSmallerThanOrEqual
}
func (*JumpSignedSmallerThanOrEqual) Clone ¶
func (i *JumpSignedSmallerThanOrEqual) Clone() Instruction
func (*JumpSignedSmallerThanOrEqual) Execute ¶
func (i *JumpSignedSmallerThanOrEqual) Execute(vm *VM) error
type JumpSignedSmallerThanOrEqual32 ¶
type JumpSignedSmallerThanOrEqual32 struct {
ebpf.JumpSignedSmallerThanOrEqual32
}
func (*JumpSignedSmallerThanOrEqual32) Clone ¶
func (i *JumpSignedSmallerThanOrEqual32) Clone() Instruction
func (*JumpSignedSmallerThanOrEqual32) Execute ¶
func (i *JumpSignedSmallerThanOrEqual32) Execute(vm *VM) error
type JumpSignedSmallerThanOrEqualRegister ¶
type JumpSignedSmallerThanOrEqualRegister struct {
ebpf.JumpSignedSmallerThanOrEqualRegister
}
func (*JumpSignedSmallerThanOrEqualRegister) Clone ¶
func (i *JumpSignedSmallerThanOrEqualRegister) Clone() Instruction
func (*JumpSignedSmallerThanOrEqualRegister) Execute ¶
func (i *JumpSignedSmallerThanOrEqualRegister) Execute(vm *VM) error
type JumpSignedSmallerThanOrEqualRegister32 ¶
type JumpSignedSmallerThanOrEqualRegister32 struct {
ebpf.JumpSignedSmallerThanOrEqualRegister32
}
func (*JumpSignedSmallerThanOrEqualRegister32) Clone ¶
func (i *JumpSignedSmallerThanOrEqualRegister32) Clone() Instruction
func (*JumpSignedSmallerThanOrEqualRegister32) Execute ¶
func (i *JumpSignedSmallerThanOrEqualRegister32) Execute(vm *VM) error
type JumpSignedSmallerThanRegister ¶
type JumpSignedSmallerThanRegister struct {
ebpf.JumpSignedSmallerThanRegister
}
func (*JumpSignedSmallerThanRegister) Clone ¶
func (i *JumpSignedSmallerThanRegister) Clone() Instruction
func (*JumpSignedSmallerThanRegister) Execute ¶
func (i *JumpSignedSmallerThanRegister) Execute(vm *VM) error
type JumpSignedSmallerThanRegister32 ¶
type JumpSignedSmallerThanRegister32 struct {
ebpf.JumpSignedSmallerThanRegister32
}
func (*JumpSignedSmallerThanRegister32) Clone ¶
func (i *JumpSignedSmallerThanRegister32) Clone() Instruction
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 (i *JumpSmallerThanEqual32) Clone() Instruction
func (*JumpSmallerThanEqual32) Execute ¶
func (i *JumpSmallerThanEqual32) Execute(vm *VM) error
type JumpSmallerThanEqualRegister ¶
type JumpSmallerThanEqualRegister struct {
ebpf.JumpSmallerThanEqualRegister
}
func (*JumpSmallerThanEqualRegister) Clone ¶
func (i *JumpSmallerThanEqualRegister) Clone() Instruction
func (*JumpSmallerThanEqualRegister) Execute ¶
func (i *JumpSmallerThanEqualRegister) Execute(vm *VM) error
type JumpSmallerThanEqualRegister32 ¶
type JumpSmallerThanEqualRegister32 struct {
ebpf.JumpSmallerThanEqualRegister32
}
func (*JumpSmallerThanEqualRegister32) Clone ¶
func (i *JumpSmallerThanEqualRegister32) Clone() Instruction
func (*JumpSmallerThanEqualRegister32) Execute ¶
func (i *JumpSmallerThanEqualRegister32) Execute(vm *VM) error
type JumpSmallerThanRegister ¶
type JumpSmallerThanRegister struct {
ebpf.JumpSmallerThanRegister
}
func (*JumpSmallerThanRegister) Clone ¶
func (i *JumpSmallerThanRegister) Clone() Instruction
func (*JumpSmallerThanRegister) Execute ¶
func (i *JumpSmallerThanRegister) Execute(vm *VM) error
type JumpSmallerThanRegister32 ¶
type JumpSmallerThanRegister32 struct {
ebpf.JumpSmallerThanRegister32
}
func (*JumpSmallerThanRegister32) Clone ¶
func (i *JumpSmallerThanRegister32) Clone() Instruction
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 (i *LoadSocketBufConstant) Clone() Instruction
func (*LoadSocketBufConstant) Execute ¶
func (i *LoadSocketBufConstant) 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 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 ¶
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) Clone ¶
func (mp *MemoryPtr) Clone() RegisterValue
func (*MemoryPtr) Copy ¶
func (mp *MemoryPtr) Copy() RegisterValue
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 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 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 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 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 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 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 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.
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 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 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 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) AddProgram ¶
func (vm *VM) AddProgram(prog []ebpf.Instruction) error
func (*VM) AddRawProgram ¶
func (vm *VM) AddRawProgram(prog []ebpf.RawInstruction) error
func (*VM) Clone ¶
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) SetEntrypoint ¶
type VMError ¶
A VMError is thrown by the VM and contain a copy of the state of the VM at the time of the error
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 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 Xor64Register ¶
type Xor64Register struct {
ebpf.Xor64Register
}
func (*Xor64Register) Clone ¶
func (i *Xor64Register) Clone() Instruction
func (*Xor64Register) Execute ¶
func (i *Xor64Register) Execute(vm *VM) error
Source Files ¶
- doc.go
- helper_functions.go
- inst.go
- inst_add.go
- inst_and.go
- inst_arsh.go
- inst_atomic.go
- inst_call_bpf.go
- inst_call_helper.go
- inst_div.go
- inst_end.go
- inst_exit.go
- inst_ja.go
- inst_jeq.go
- inst_jge.go
- inst_jgt.go
- inst_jle.go
- inst_jlt.go
- inst_jne.go
- inst_jset.go
- inst_jsge.go
- inst_jsgt.go
- inst_jsle.go
- inst_jslt.go
- inst_load.go
- inst_lsh.go
- inst_mod.go
- inst_mov.go
- inst_mul.go
- inst_neg.go
- inst_nop.go
- inst_or.go
- inst_rsh.go
- inst_store.go
- inst_sub.go
- inst_xor.go
- maps.go
- maps_array.go
- memory.go
- registers.go
- vm.go