package btf
import "github.com/cilium/ebpf/internal/btf"
Package btf handles data encoded according to the BPF Type Format.
The canonical documentation lives in the Linux kernel repository and is available at https://www.kernel.org/doc/html/latest/bpf/btf.html
The API is very much unstable. You should only use this via the main ebpf library.
Index ¶
- Variables
- func Sizeof(typ Type) (int, error)
- type Array
- type COREFixup
- type COREFixups
- type COREKind
- type Const
- type Datasec
- type Enum
- type EnumValue
- type Float
- type Func
- type FuncLinkage
- type FuncParam
- type FuncProto
- type Fwd
- type FwdKind
- type Handle
- func NewHandle(spec *Spec) (*Handle, error)
- func NewHandleFromID(id ID) (*Handle, error)
- func (h *Handle) Close() error
- func (h *Handle) FD() int
- func (h *Handle) Spec() *Spec
- type ID
- type Int
- type IntEncoding
- type Map
- type Member
- type NamedType
- type Pointer
- type Program
- func (p *Program) Append(other *Program) error
- func (p *Program) Fixups(target *Spec) (COREFixups, error)
- func (p *Program) FuncInfos() (recordSize uint32, bytes []byte, err error)
- func (p *Program) LineInfos() (recordSize uint32, bytes []byte, err error)
- func (p *Program) Spec() *Spec
- type Restrict
- type Spec
- func LoadKernelSpec() (*Spec, error)
- func LoadRawSpec(btf io.Reader, bo binary.ByteOrder) (*Spec, error)
- func LoadSpecFromReader(rd io.ReaderAt) (*Spec, error)
- func (s *Spec) Copy() *Spec
- func (s *Spec) FindType(name string, typ interface{}) error
- func (s *Spec) Program(name string, length uint64) (*Program, error)
- type Struct
- type Type
- type TypeID
- type Typedef
- type Union
- type Var
- type VarLinkage
- type VarSecinfo
- type Void
- type Volatile
Examples ¶
Variables ¶
var ( ErrNotSupported = internal.ErrNotSupported ErrNotFound = errors.New("not found") ErrNoExtendedInfo = errors.New("no extended info") )
Errors returned by BTF functions.
Functions ¶
func Sizeof ¶
Sizeof returns the size of a type in bytes.
Returns an error if the size can't be computed.
Types ¶
type Array ¶
Array is an array with a fixed number of elements.
func (*Array) String ¶
type COREFixup ¶
COREFixup is the result of computing a CO-RE relocation for a target.
func (COREFixup) String ¶
type COREFixups ¶
func (COREFixups) Apply ¶
func (fs COREFixups) Apply(insns asm.Instructions) (asm.Instructions, error)
Apply a set of CO-RE relocations to a BPF program.
type COREKind ¶
type COREKind uint32
COREKind is the type of CO-RE relocation
func (COREKind) String ¶
type Const ¶
Const is a qualifier.
func (*Const) String ¶
type Datasec ¶
type Datasec struct { TypeID Name string Size uint32 Vars []VarSecinfo }
Datasec is a global program section containing data.
func (*Datasec) String ¶
func (*Datasec) TypeName ¶
type Enum ¶
Enum lists possible values.
func (*Enum) String ¶
func (*Enum) TypeName ¶
type EnumValue ¶
EnumValue is part of an Enum
Is is not a valid Type
type Float ¶
Float is a float of a given length.
func (*Float) String ¶
func (*Float) TypeName ¶
type Func ¶
type Func struct { TypeID Name string Type Type Linkage FuncLinkage }
Func is a function definition.
func (*Func) String ¶
func (*Func) TypeName ¶
type FuncLinkage ¶
type FuncLinkage int
FuncLinkage describes BTF function linkage metadata.
const ( StaticFunc FuncLinkage = iota // static GlobalFunc // global ExternFunc // extern )
Equivalent of enum btf_func_linkage.
func (FuncLinkage) String ¶
func (i FuncLinkage) String() string
type FuncParam ¶
type FuncProto ¶
FuncProto is a function declaration.
func (*FuncProto) String ¶
type Fwd ¶
Fwd is a forward declaration of a Type.
func (*Fwd) String ¶
func (*Fwd) TypeName ¶
type FwdKind ¶
type FwdKind int
FwdKind is the type of forward declaration.
Valid types of forward declaration.
func (FwdKind) String ¶
type Handle ¶
type Handle struct {
// contains filtered or unexported fields
}
Handle is a reference to BTF loaded into the kernel.
func NewHandle ¶
NewHandle loads BTF into the kernel.
Returns ErrNotSupported if BTF is not supported.
func NewHandleFromID ¶
NewHandleFromID returns the BTF handle for a given id.
Returns ErrNotExist, if there is no BTF with the given id.
Requires CAP_SYS_ADMIN.
func (*Handle) Close ¶
Close destroys the handle.
Subsequent calls to FD will return an invalid value.
func (*Handle) FD ¶
FD returns the file descriptor for the handle.
func (*Handle) Spec ¶
Spec returns the Spec that defined the BTF loaded into the kernel.
type ID ¶
type ID uint32
ID represents the unique ID of a BTF object.
type Int ¶
type Int struct { TypeID Name string // The size of the integer in bytes. Size uint32 Encoding IntEncoding // OffsetBits is the starting bit offset. Currently always 0. // See https://www.kernel.org/doc/html/latest/bpf/btf.html#btf-kind-int OffsetBits uint32 Bits byte }
Int is an integer of a given length.
func (*Int) String ¶
func (*Int) TypeName ¶
type IntEncoding ¶
type IntEncoding byte
const ( Signed IntEncoding = 1 << iota Char Bool )
type Map ¶
Map is the BTF for a map.
type Member ¶
type Member struct { Name string Type Type // OffsetBits is the bit offset of this member. OffsetBits uint32 BitfieldSize uint32 }
Member is part of a Struct or Union.
It is not a valid Type.
type NamedType ¶
NamedType is a type with a name.
type Pointer ¶
Pointer is a pointer to another type.
func (*Pointer) String ¶
type Program ¶
type Program struct {
// contains filtered or unexported fields
}
Program is the BTF information for a stream of instructions.
func (*Program) Append ¶
Append the information from other to the Program.
func (*Program) Fixups ¶
func (p *Program) Fixups(target *Spec) (COREFixups, error)
Fixups returns the changes required to adjust the program to the target.
Passing a nil target will relocate against the running kernel.
func (*Program) FuncInfos ¶
FuncInfos returns the binary form of BTF function infos.
func (*Program) LineInfos ¶
LineInfos returns the binary form of BTF line infos.
func (*Program) Spec ¶
Spec returns the BTF spec of this program.
type Restrict ¶
Restrict is a qualifier.
func (*Restrict) String ¶
type Spec ¶
type Spec struct {
// contains filtered or unexported fields
}
Spec represents decoded BTF.
func LoadKernelSpec ¶
LoadKernelSpec returns the current kernel's BTF information.
Requires a >= 5.5 kernel with CONFIG_DEBUG_INFO_BTF enabled. Returns ErrNotSupported if BTF is not enabled.
func LoadRawSpec ¶
LoadRawSpec reads a blob of BTF data that isn't wrapped in an ELF file.
Prefer using LoadSpecFromReader, since this function only supports a subset of BTF.
func LoadSpecFromReader ¶
LoadSpecFromReader reads BTF sections from an ELF.
Returns ErrNotFound if the reader contains no BTF.
func (*Spec) Copy ¶
Copy creates a copy of Spec.
func (*Spec) FindType ¶
FindType searches for a type with a specific name.
Called T a type that satisfies Type, typ must be a non-nil **T. On success, the address of the found type will be copied in typ.
Returns an error wrapping ErrNotFound if no matching
type exists in spec.
Code:
Example¶
{
// Acquire a Spec via one of its constructors.
spec := new(Spec)
// Declare a variable of the desired type
var foo *Struct
if err := spec.FindType("foo", &foo); err != nil {
// There is no struct with name foo, or there
// are multiple possibilities.
}
// We've found struct foo
fmt.Println(foo.Name)
}
func (*Spec) Program ¶
Program finds the BTF for a specific section.
Length is the number of bytes in the raw BPF instruction stream.
Returns an error which may wrap ErrNoExtendedInfo if the Spec doesn't contain extended BTF info.
type Struct ¶
type Struct struct { TypeID Name string // The size of the struct including padding, in bytes Size uint32 Members []Member }
Struct is a compound type of consecutive members.
func (*Struct) String ¶
func (*Struct) TypeName ¶
type Type ¶
Type represents a type described by BTF.
The following are valid Types.
There currently is no better way to document which
types implement an interface.
Code:
Example (ValidTypes)¶
{
var _ Type = &Void{}
var _ Type = &Int{}
var _ Type = &Pointer{}
var _ Type = &Array{}
var _ Type = &Struct{}
var _ Type = &Union{}
var _ Type = &Enum{}
var _ Type = &Fwd{}
var _ Type = &Typedef{}
var _ Type = &Volatile{}
var _ Type = &Const{}
var _ Type = &Restrict{}
var _ Type = &Func{}
var _ Type = &FuncProto{}
var _ Type = &Var{}
var _ Type = &Datasec{}
}
type TypeID ¶
type TypeID uint32
TypeID identifies a type in a BTF section.
func (TypeID) ID ¶
ID implements part of the Type interface.
type Typedef ¶
Typedef is an alias of a Type.
func (*Typedef) String ¶
func (*Typedef) TypeName ¶
type Union ¶
type Union struct { TypeID Name string // The size of the union including padding, in bytes. Size uint32 Members []Member }
Union is a compound type where members occupy the same memory.
func (*Union) String ¶
func (*Union) TypeName ¶
type Var ¶
type Var struct { TypeID Name string Type Type Linkage VarLinkage }
Var is a global variable.
func (*Var) String ¶
func (*Var) TypeName ¶
type VarLinkage ¶
type VarLinkage int
VarLinkage describes BTF variable linkage metadata.
const ( StaticVar VarLinkage = iota // static GlobalVar // global ExternVar // extern )
func (VarLinkage) String ¶
func (i VarLinkage) String() string
type VarSecinfo ¶
VarSecinfo describes variable in a Datasec.
It is not a valid Type.
type Void ¶
type Void struct{}
Void is the unit type of BTF.
func (*Void) ID ¶
func (*Void) String ¶
type Volatile ¶
Volatile is a qualifier.
func (*Volatile) String ¶
Source Files ¶
btf.go btf_types.go btf_types_string.go core.go doc.go ext_info.go info.go strings.go syscalls.go types.go
- Version
- v0.7.0
- Published
- Oct 8, 2021
- Platform
- js/wasm
- Imports
- 18 packages
- Last checked
- 1 hour ago –
Tools for package owners.