baloum

package
v0.0.0-...-cc302cb Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// static void *(*baloum_malloc)(__u32 size) = (void *) 0xffff;
	FnMalloc = asm.BuiltinFunc(0xffff)

	// static int (*baloum_call)(struct baloum_ctx *ctx, const char *section) = (void *) 0xfffe;
	FnCall = asm.BuiltinFunc(0xfffe)

	// static int (*baloum_strcmp)(const char *s1, const char *s2) = (void *)0xfffd;
	FnStrCmp = asm.BuiltinFunc(0xfffd)

	// static int (*baloum_memcmp)(const void *b1, const void *b2, __u32 size) = (void *)0xfffc;
	FnMemCmp = asm.BuiltinFunc(0xfffc)

	// static int (*baloum_sleep)(__u64 ns) = (void *)0xfffb;
	FnSleep = asm.BuiltinFunc(0xfffb)
)
View Source
const (

	// HEAP_ADDR_MASK identifying heap address
	HEAP_ADDR_MASK uint64 = 0xff00000000000000
	// ADDR_MASK
	ADDR_MASK uint64 = 0xffffffff
	// IDX_MASK
	IDX_MASK uint64 = 0xffff
)
View Source
const (
	REGS_NUM  = 11
	REGS_SIZE = REGS_NUM * 8
)
View Source
const (
	CTX_SIZE = 5 * 8 // 5 argument
)
View Source
const (
	DEFAULT_STACK_SIZE = 512
)
View Source
const (
	ErrorCode = int(-1)
)

Variables

View Source
var ByteOrder binary.ByteOrder

Functions

func Bytes2String

func Bytes2String(data []byte) string

func FnCallImpl

func FnCallImpl(vm *VM, inst *asm.Instruction) error

func FnGetCurrentPidTgidImpl

func FnGetCurrentPidTgidImpl(vm *VM, inst *asm.Instruction) error

func FnGetSmpProcessorIdImpl

func FnGetSmpProcessorIdImpl(vm *VM, inst *asm.Instruction) error

func FnKtimeGetNsImpl

func FnKtimeGetNsImpl(vm *VM, inst *asm.Instruction) error

func FnMallocImpl

func FnMallocImpl(vm *VM, inst *asm.Instruction) error

func FnMapDeleteElemImpl

func FnMapDeleteElemImpl(vm *VM, inst *asm.Instruction) error

func FnMapLookupElemImpl

func FnMapLookupElemImpl(vm *VM, inst *asm.Instruction) error

func FnMapUpdateElemImpl

func FnMapUpdateElemImpl(vm *VM, inst *asm.Instruction) error

func FnMemCmpImpl

func FnMemCmpImpl(vm *VM, inst *asm.Instruction) error

func FnPerfEventOutputImpl

func FnPerfEventOutputImpl(vm *VM, inst *asm.Instruction) error

func FnProbeReadImpl

func FnProbeReadImpl(vm *VM, inst *asm.Instruction) error

func FnProbeReadStrImpl

func FnProbeReadStrImpl(vm *VM, inst *asm.Instruction) error

func FnSleepImpl

func FnSleepImpl(vm *VM, inst *asm.Instruction) error

func FnStrCmpImpl

func FnStrCmpImpl(vm *VM, inst *asm.Instruction) error

func FnTailCallImpl

func FnTailCallImpl(vm *VM, inst *asm.Instruction) error

func FnTracePrintkImpl

func FnTracePrintkImpl(vm *VM, inst *asm.Instruction) error

func GetHostByteOrder

func GetHostByteOrder() binary.ByteOrder

GetHostByteOrder guesses the hosts byte order

func Instructions

func Instructions(insts ...interface{}) asm.Instructions

func JumpOpCode

func JumpOpCode(class asm.Class, jumpOp asm.JumpOp, source asm.Source) asm.OpCode

func ResolveReferences

func ResolveReferences(insts asm.Instructions) error

func ToBytes

func ToBytes(data interface{}, size int) ([]byte, error)

func UnmarshalCtx

func UnmarshalCtx(data []byte) [16]uint16

Types

type BTInst

type BTInst struct {
	PC   int
	Inst asm.Instruction
}

type Context

type Context interface {
	SetRegs(vm *VM)
}

type DebugCommand

type DebugCommand string
const (
	NextCommand           DebugCommand = "n"
	ContinueCommand       DebugCommand = "c"
	PrintStackCommand     DebugCommand = "ps"
	PrintRegistersCommand DebugCommand = "pr"
	PrintVariableCommand  DebugCommand = "pv"
	PrintMap              DebugCommand = "pm"
	PrintCommand          DebugCommand = "p"
	PrintBacktraceCommand DebugCommand = "bt"
)

type Debugger

type Debugger struct {
	Enabled        bool
	VariableReader map[string]VariableReader
	// contains filtered or unexported fields
}

func NewDebugger

func NewDebugger(enabled bool, variableReaders map[string]VariableReader) *Debugger

func (*Debugger) Close

func (d *Debugger) Close()

func (*Debugger) ObserveInst

func (d *Debugger) ObserveInst(vm *VM, pc int, inst *asm.Instruction)

type Fncs

type Fncs struct {
	GetCurrentPidTgid func(vm *VM) (uint64, error)
	KtimeGetNS        func(vm *VM) (uint64, error)
	TracePrintk       func(vm *VM, format string, args ...interface{}) error
	GetSmpProcessorId func(vm *VM) (uint64, error)
	Sleep             func(vm *VM, duration time.Duration) error
}

type Heap

type Heap struct {
	// contains filtered or unexported fields
}

func NewHeap

func NewHeap() *Heap

func (*Heap) Alloc

func (h *Heap) Alloc(size int) uint64

func (*Heap) AllocWith

func (h *Heap) AllocWith(data []byte) uint64

func (*Heap) Free

func (h *Heap) Free(addr uint64)

func (*Heap) GetMem

func (h *Heap) GetMem(addr uint64) ([]byte, uint64, error)

type Logger

type Logger interface {
	Info(params ...interface{})
	Infof(format string, params ...interface{})

	Debug(params ...interface{})
	Debugf(format string, params ...interface{})

	Error(params ...interface{})
	Errorf(format string, params ...interface{})
}

type Map

type Map struct {
	// contains filtered or unexported fields
}

func (*Map) Delete

func (m *Map) Delete(key interface{}) (bool, error)

func (*Map) FD

func (m *Map) FD() int

func (*Map) Iterator

func (m *Map) Iterator() (*MapIterator, error)

func (*Map) KeySize

func (m *Map) KeySize() uint32

func (*Map) Keys

func (m *Map) Keys() ([][]byte, error)

func (*Map) Lookup

func (m *Map) Lookup(key interface{}) ([]byte, error)

func (*Map) LookupAddr

func (m *Map) LookupAddr(key interface{}) (uint64, error)

func (*Map) Read

func (m *Map) Read() (<-chan []byte, error)

func (*Map) Update

func (m *Map) Update(key interface{}, value interface{}, kind MapUpdateType) (bool, error)

func (*Map) ValueSize

func (m *Map) ValueSize() uint32

func (*Map) Write

func (m *Map) Write(data interface{}, size uint64) error

type MapArrayStorage

type MapArrayStorage struct {
	// contains filtered or unexported fields
}

func (*MapArrayStorage) Delete

func (m *MapArrayStorage) Delete(key []byte) (bool, error)

func (*MapArrayStorage) Keys

func (m *MapArrayStorage) Keys() ([][]byte, error)

func (*MapArrayStorage) Lookup

func (m *MapArrayStorage) Lookup(key []byte) (uint64, error)

func (*MapArrayStorage) Read

func (m *MapArrayStorage) Read() (<-chan []byte, error)

func (*MapArrayStorage) Update

func (m *MapArrayStorage) Update(key []byte, value []byte, kind MapUpdateType) (bool, error)

func (*MapArrayStorage) Write

func (m *MapArrayStorage) Write(data []byte) error

type MapCollection

type MapCollection struct {
	// contains filtered or unexported fields
}

func NewMapCollection

func NewMapCollection(vm *VM) *MapCollection

func (*MapCollection) GetMapById

func (mc *MapCollection) GetMapById(id int) *Map

func (*MapCollection) GetMapByName

func (mc *MapCollection) GetMapByName(name string) *Map

func (*MapCollection) LoadMap

func (mc *MapCollection) LoadMap(spec *ebpf.CollectionSpec, name string) error

func (*MapCollection) LoadMaps

func (mc *MapCollection) LoadMaps(spec *ebpf.CollectionSpec, sections ...string) error

type MapHashStorage

type MapHashStorage struct {
	// contains filtered or unexported fields
}

func (*MapHashStorage) Delete

func (m *MapHashStorage) Delete(key []byte) (bool, error)

func (*MapHashStorage) Keys

func (m *MapHashStorage) Keys() ([][]byte, error)

func (*MapHashStorage) Lookup

func (m *MapHashStorage) Lookup(key []byte) (uint64, error)

func (*MapHashStorage) Read

func (m *MapHashStorage) Read() (<-chan []byte, error)

func (*MapHashStorage) Update

func (m *MapHashStorage) Update(key []byte, value []byte, kind MapUpdateType) (bool, error)

func (*MapHashStorage) Write

func (m *MapHashStorage) Write(data []byte) error

type MapIterator

type MapIterator struct {
	// contains filtered or unexported fields
}

func (*MapIterator) Next

func (mi *MapIterator) Next() ([]byte, []byte, bool)

type MapLRUStorage

type MapLRUStorage struct {
	// contains filtered or unexported fields
}

func (*MapLRUStorage) Delete

func (m *MapLRUStorage) Delete(key []byte) (bool, error)

func (*MapLRUStorage) Keys

func (m *MapLRUStorage) Keys() ([][]byte, error)

func (*MapLRUStorage) Lookup

func (m *MapLRUStorage) Lookup(key []byte) (uint64, error)

func (*MapLRUStorage) Read

func (m *MapLRUStorage) Read() (<-chan []byte, error)

func (*MapLRUStorage) Update

func (m *MapLRUStorage) Update(key []byte, value []byte, kind MapUpdateType) (bool, error)

func (*MapLRUStorage) Write

func (m *MapLRUStorage) Write(data []byte) error

type MapPerCPUArrayStorage

type MapPerCPUArrayStorage struct {
	// contains filtered or unexported fields
}

func (*MapPerCPUArrayStorage) Delete

func (m *MapPerCPUArrayStorage) Delete(key []byte) (bool, error)

func (*MapPerCPUArrayStorage) Keys

func (m *MapPerCPUArrayStorage) Keys() ([][]byte, error)

func (*MapPerCPUArrayStorage) Lookup

func (m *MapPerCPUArrayStorage) Lookup(key []byte) (uint64, error)

func (*MapPerCPUArrayStorage) Read

func (m *MapPerCPUArrayStorage) Read() (<-chan []byte, error)

func (*MapPerCPUArrayStorage) Update

func (m *MapPerCPUArrayStorage) Update(key []byte, value []byte, kind MapUpdateType) (bool, error)

func (*MapPerCPUArrayStorage) Write

func (m *MapPerCPUArrayStorage) Write(data []byte) error

type MapPerfStorage

type MapPerfStorage struct {
	// contains filtered or unexported fields
}

func (*MapPerfStorage) Delete

func (m *MapPerfStorage) Delete(key []byte) (bool, error)

func (*MapPerfStorage) Keys

func (m *MapPerfStorage) Keys() ([][]byte, error)

func (*MapPerfStorage) Lookup

func (m *MapPerfStorage) Lookup(key []byte) (uint64, error)

func (*MapPerfStorage) Read

func (m *MapPerfStorage) Read() (<-chan []byte, error)

func (*MapPerfStorage) Update

func (m *MapPerfStorage) Update(key []byte, value []byte, kind MapUpdateType) (bool, error)

func (*MapPerfStorage) Write

func (m *MapPerfStorage) Write(data []byte) error

type MapProgArrayStorage

type MapProgArrayStorage struct {
	// contains filtered or unexported fields
}

func (*MapProgArrayStorage) Delete

func (m *MapProgArrayStorage) Delete(key []byte) (bool, error)

func (*MapProgArrayStorage) Keys

func (m *MapProgArrayStorage) Keys() ([][]byte, error)

func (*MapProgArrayStorage) Lookup

func (m *MapProgArrayStorage) Lookup(key []byte) (uint64, error)

func (*MapProgArrayStorage) Read

func (m *MapProgArrayStorage) Read() (<-chan []byte, error)

func (*MapProgArrayStorage) Update

func (m *MapProgArrayStorage) Update(key []byte, value []byte, kind MapUpdateType) (bool, error)

func (*MapProgArrayStorage) Write

func (m *MapProgArrayStorage) Write(data []byte) error

type MapStorage

type MapStorage interface {
	Lookup(key []byte) (uint64, error)
	Update(key []byte, value []byte, kind MapUpdateType) (bool, error)
	Delete(key []byte) (bool, error)
	Keys() ([][]byte, error)
	Read() (<-chan []byte, error)
	Write(data []byte) error
}

func NewMapArrayStorage

func NewMapArrayStorage(vm *VM, keySize, valueSize, maxEntries, flags uint32) (MapStorage, error)

func NewMapHashStorage

func NewMapHashStorage(vm *VM, keySize, valueSize, maxEntries, flags uint32) (MapStorage, error)

func NewMapLRUStorage

func NewMapLRUStorage(vm *VM, keySize, valueSize, maxEntries, flags uint32) (MapStorage, error)

func NewMapPerCPUArrayStorage

func NewMapPerCPUArrayStorage(vm *VM, keySize, valueSize, maxEntries, flags uint32) (MapStorage, error)

func NewMapPerfStorage

func NewMapPerfStorage(vm *VM, keySize, valueSize, maxEntries, flags uint32) (MapStorage, error)

func NewMapProgArrayStorage

func NewMapProgArrayStorage(vm *VM, keySize, valueSize, maxEntries, flags uint32) (MapStorage, error)

type MapUpdateType

type MapUpdateType int
const (
	BPF_ANY MapUpdateType = iota
	BPF_NOEXIST
	BPF_EXIST
	BPF_F_LOCK
)

type MemBlock

type MemBlock struct {
	// contains filtered or unexported fields
}

type NullLogger

type NullLogger struct{}

func (NullLogger) Debug

func (l NullLogger) Debug(params ...interface{})

func (NullLogger) Debugf

func (l NullLogger) Debugf(format string, params ...interface{})

func (NullLogger) Error

func (l NullLogger) Error(params ...interface{})

func (NullLogger) Errorf

func (l NullLogger) Errorf(format string, params ...interface{})

func (NullLogger) Info

func (l NullLogger) Info(params ...interface{})

func (NullLogger) Infof

func (l NullLogger) Infof(format string, params ...interface{})

type Observer

type Observer interface {
	ObserveInst(vm *VM, pc int, inst *asm.Instruction)
}

type Opts

type Opts struct {
	StackSize int
	Fncs      Fncs
	RawFncs   map[asm.BuiltinFunc]func(*VM, *asm.Instruction) error
	Logger    Logger
	CPUs      int
	Observer  Observer
}

type Printk

type Printk struct {
	// contains filtered or unexported fields
}

func (Printk) Call

func (p Printk) Call() asm.Instructions

type Program

type Program struct {
	// contains filtered or unexported fields
}

func (*Program) Append

func (p *Program) Append(insts ...interface{})

func (*Program) Instructions

func (p *Program) Instructions() asm.Instructions

func (*Program) NewPrintk

func (p *Program) NewPrintk(format string) (*Printk, error)

func (*Program) StackAlloc

func (p *Program) StackAlloc(size int16) (int16, error)

func (*Program) StackFree

func (p *Program) StackFree(addr int16)

type RawContext

type RawContext struct {
	Regs Regs
}

func (*RawContext) SetRegs

func (ctx *RawContext) SetRegs(vm *VM)

type Regs

type Regs [REGS_NUM]uint64

func (*Regs) Bytes

func (r *Regs) Bytes() []byte

func (*Regs) Parse

func (r *Regs) Parse(data []byte) error

type StdContext

type StdContext struct {
	Arg0 uint64
	Arg1 uint64
	Arg2 uint64
	Arg3 uint64
	Arg4 uint64
}
struct baloum_ctx {
	u64 arg0;
	u64 arg1;
	u64 arg2;
	u64 arg3;
	u64 arg4;
};

func (*StdContext) Bytes

func (ctx *StdContext) Bytes() []byte

func (*StdContext) Parse

func (ctx *StdContext) Parse(data []byte) error

func (*StdContext) SetRegs

func (ctx *StdContext) SetRegs(vm *VM)

type VM

type VM struct {
	Spec *ebpf.CollectionSpec
	Opts Opts
	// contains filtered or unexported fields
}

func NewVM

func NewVM(spec *ebpf.CollectionSpec, opts Opts) *VM

func (*VM) AddProgram

func (vm *VM) AddProgram(program *ebpf.ProgramSpec) uint32

func (*VM) Heap

func (vm *VM) Heap() *Heap

func (*VM) LoadMap

func (vm *VM) LoadMap(name string) error

func (*VM) LoadMaps

func (vm *VM) LoadMaps(section ...string) error

func (*VM) LoadProgram

func (vm *VM) LoadProgram(section string) (uint32, error)

func (*VM) Map

func (vm *VM) Map(name string) *Map

func (*VM) RunInstructions

func (vm *VM) RunInstructions(ctx Context, insts []asm.Instruction) (int, error)

func (*VM) RunProgram

func (vm *VM) RunProgram(ctx Context, section string) (int, error)

type VariableReader

type VariableReader struct {
	Size uint64
	Read func(bytes []byte) interface{}
}

Jump to

Keyboard shortcuts

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