package internal
import "github.com/cilium/ebpf/internal"
Index ¶
- Constants
- Variables
- func Align(n, alignment int) int
- func ErrorWithLog(err error, log []byte, logErr error) error
- func FeatureTest(name, version string, fn FeatureTestFn) func() error
- func Identifier(str string) string
- func NewBufferedSectionReader(ra io.ReaderAt, off, n int64) io.Reader
- func Pin(currentPath, newPath string, fd *sys.FD) error
- func PossibleCPUs() (int, error)
- func ReadAllCompressed(file string) ([]byte, error)
- func Unpin(pinnedPath string) error
- func WriteFormatted(src []byte, out io.Writer) error
- type DiscardZeroes
- type FeatureTestFn
- type SafeELFFile
- func NewSafeELFFile(r io.ReaderAt) (safe *SafeELFFile, err error)
- func (se *SafeELFFile) DynamicSymbols() (syms []elf.Symbol, err error)
- func (se *SafeELFFile) Symbols() (syms []elf.Symbol, err error)
- type UnsupportedFeatureError
- func (ufe *UnsupportedFeatureError) Error() string
- func (ufe *UnsupportedFeatureError) Is(target error) bool
- type VerifierError
- type Version
Constants ¶
const ( // Version constant used in ELF binaries indicating that the loader needs to // substitute the eBPF program's version with the value of the kernel's // KERNEL_VERSION compile-time macro. Used for compatibility with BCC, gobpf // and RedSift. MagicKernelVersion = 0xFFFFFFFE )
Variables ¶
var ClangEndian string
Clang is set to either "el" or "eb" depending on the host's endianness.
ErrNotSupported indicates that a feature is not supported by the current kernel.
NativeEndian is set to either binary.BigEndian or binary.LittleEndian, depending on the host's endianness.
Functions ¶
func Align ¶
Align returns 'n' updated to 'alignment' boundary.
func ErrorWithLog ¶
ErrorWithLog returns an error that includes logs from the kernel verifier.
logErr should be the error returned by the syscall that generated the log. It is used to check for truncation of the output.
func FeatureTest ¶
func FeatureTest(name, version string, fn FeatureTestFn) func() error
FeatureTest wraps a function so that it is run at most once.
name should identify the tested feature, while version must be in the form Major.Minor[.Patch].
Returns an error wrapping ErrNotSupported if the feature is not supported.
func Identifier ¶
Identifier turns a C style type or field name into an exportable Go equivalent.
func NewBufferedSectionReader ¶
NewBufferedSectionReader wraps an io.ReaderAt in an appropriately-sized buffered reader. It is a convenience function for reading subsections of ELF sections while minimizing the amount of read() syscalls made.
Syscall overhead is non-negligible in continuous integration context where ELFs might be accessed over virtual filesystems with poor random access performance. Buffering reads makes sense because (sub)sections end up being read completely anyway.
Use instead of the r.Seek() + io.LimitReader() pattern.
func Pin ¶
func PossibleCPUs ¶
PossibleCPUs returns the max number of CPUs a system may possibly have Logical CPU numbers must be of the form 0-n
func ReadAllCompressed ¶
ReadAllCompressed decompresses a gzipped file into memory.
func Unpin ¶
func WriteFormatted ¶
WriteFormatted outputs a formatted src into out.
If formatting fails it returns an informative error message.
Types ¶
type DiscardZeroes ¶
type DiscardZeroes struct{}
DiscardZeroes makes sure that all written bytes are zero before discarding them.
func (DiscardZeroes) Write ¶
func (DiscardZeroes) Write(p []byte) (int, error)
type FeatureTestFn ¶
type FeatureTestFn func() error
FeatureTestFn is used to determine whether the kernel supports a certain feature.
The return values have the following semantics:
err == ErrNotSupported: the feature is not available err == nil: the feature is available err != nil: the test couldn't be executed
type SafeELFFile ¶
func NewSafeELFFile ¶
func NewSafeELFFile(r io.ReaderAt) (safe *SafeELFFile, err error)
NewSafeELFFile reads an ELF safely.
Any panic during parsing is turned into an error. This is necessary since there are a bunch of unfixed bugs in debug/elf.
https://github.com/golang/go/issues?q=is%3Aissue+is%3Aopen+debug%2Felf+in%3Atitle
func (*SafeELFFile) DynamicSymbols ¶
func (se *SafeELFFile) DynamicSymbols() (syms []elf.Symbol, err error)
DynamicSymbols is the safe version of elf.File.DynamicSymbols.
func (*SafeELFFile) Symbols ¶
func (se *SafeELFFile) Symbols() (syms []elf.Symbol, err error)
Symbols is the safe version of elf.File.Symbols.
type UnsupportedFeatureError ¶
type UnsupportedFeatureError struct { // The minimum Linux mainline version required for this feature. // Used for the error string, and for sanity checking during testing. MinimumVersion Version // The name of the feature that isn't supported. Name string }
UnsupportedFeatureError is returned by FeatureTest() functions.
func (*UnsupportedFeatureError) Error ¶
func (ufe *UnsupportedFeatureError) Error() string
func (*UnsupportedFeatureError) Is ¶
func (ufe *UnsupportedFeatureError) Is(target error) bool
Is indicates that UnsupportedFeatureError is ErrNotSupported.
type VerifierError ¶
type VerifierError struct {
// contains filtered or unexported fields
}
VerifierError includes information from the eBPF verifier.
func (*VerifierError) Error ¶
func (le *VerifierError) Error() string
func (*VerifierError) Unwrap ¶
func (le *VerifierError) Unwrap() error
type Version ¶
type Version [3]uint16
A Version in the form Major.Minor.Patch.
func KernelVersion ¶
KernelVersion returns the version of the currently running kernel.
func NewVersion ¶
NewVersion creates a version from a string like "Major.Minor.Patch".
Patch is optional.
func NewVersionFromCode ¶
NewVersionFromCode creates a version from a LINUX_VERSION_CODE.
func (Version) Kernel ¶
Kernel implements the kernel's KERNEL_VERSION macro from linux/version.h. It represents the kernel version and patch level as a single value.
func (Version) Less ¶
Less returns true if the version is less than another version.
func (Version) String ¶
func (Version) Unspecified ¶
Unspecified returns true if the version is all zero.
Source Files ¶
align.go cpu.go elf.go endian.go errors.go feature.go io.go output.go pinning.go vdso.go version.go
Directories ¶
Path | Synopsis |
---|---|
internal/btf | Package btf handles data encoded according to the BPF Type Format. |
internal/cmd | |
internal/cmd/gentypes | Program gentypes reads a compressed vmlinux .BTF section and generates syscall bindings from it. |
internal/epoll | |
internal/sys | Package sys contains bindings for the BPF syscall. |
internal/testutils | |
internal/unix |
- Version
- v0.8.0
- Published
- Jan 21, 2022
- Platform
- js/wasm
- Imports
- 20 packages
- Last checked
- 4 hours ago –
Tools for package owners.