sys

package
v0.15.5 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package sys provides low level system utilities, like architecture information and handling, and shared object handling.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotELFFile is returned if the file does not have an ELF magic number.
	ErrNotELFFile = errors.New("is not an ELF file")

	// ErrOSABINotSupported is returned if the OS ABI of an ELF file is not
	// supported.
	ErrOSABINotSupported = errors.New("OSABI not supported")

	// ErrMachineNotSupported is returned if the machine type of an ELF file
	// is not supported.
	ErrMachineNotSupported = errors.New("machine type not supported")

	// ErrEmptyPath is returned if an empty path is given.
	ErrEmptyPath = errors.New("path must not be empty")

	// ErrArchNotSupported is returned if the requested architecture is not
	// supported for the requested operation.
	ErrArchNotSupported = errors.New("architecture not supported")
)

Functions

func AbsolutePath added in v0.15.0

func AbsolutePath(path string) (string, error)

AbsolutePath returns the absolute path as resolved by filepath.Abs.

It returns ErrEmptyPath if the given path is empty.

func Ldd added in v0.12.0

func Ldd(ctx context.Context, path string) ([]string, error)

Ldd gathers the required shared objects of the ELF file with the given path.

It invokes the "ldd" executable which is expected to be present on the system. It returns an LDDExecError in case "ldd" is not available or it returned with a non-zero exit code. This might be the case if the binary is not dynamically linked.

func MustAbsolutePath added in v0.15.0

func MustAbsolutePath(path string) string

MustAbsolutePath calls AbsolutePath and panics in case of errors.

Types

type Arch

type Arch string

Arch is the name of a supported system architecture.

const (
	AMD64   Arch = "amd64"
	ARM64   Arch = "arm64"
	RISCV64 Arch = "riscv64"
)

Supported guest architectures.

const Native Arch = Arch(runtime.GOARCH)

Native is the architecture of the host. Using the same architecture for the guest allows using KVM, if available. Use [KVMAvailable] to check.

func ReadELFArch added in v0.12.0

func ReadELFArch(fileName string) (Arch, error)

ReadELFArch returns the Arch of the given ELF file.

It returns an error if the ELF file is not for Linux or is for an unsupported architecture.

func (*Arch) IsNative

func (a *Arch) IsNative() bool

IsNative returns true if the Arch is the native architecture of the host.

func (*Arch) KVMAvailable

func (a *Arch) KVMAvailable() bool

KVMAvailable checks if KVM support is available for the given architecture.

func (*Arch) Set added in v0.12.0

func (a *Arch) Set(s string) error

Set sets Arch to the given architecture, if valid.

func (*Arch) String

func (a *Arch) String() string

type LDDExecError added in v0.15.3

type LDDExecError struct {
	Err    error
	Stderr string
}

LDDExecError wraps errors that result when executing the "ldd" command. Along with the error the output received on stdout is added to the error message.

func (*LDDExecError) Error added in v0.15.3

func (e *LDDExecError) Error() string

Error implements the [error] interface.

func (*LDDExecError) Is added in v0.15.3

func (*LDDExecError) Is(other error) bool

Is implements the errors.Is interface.

func (*LDDExecError) Unwrap added in v0.15.3

func (e *LDDExecError) Unwrap() error

Unwrap implements the errors.Unwrap interface.

type LibCollection added in v0.12.0

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

LibCollection is a deduplicated collection of dynamically linked libraries and paths they are found at.

func CollectLibsFor added in v0.12.0

func CollectLibsFor(
	ctx context.Context,
	files ...string,
) (LibCollection, error)

CollectLibsFor recursively resolves the dynamically linked shared objects of all given ELF files.

The dynamic linker consumed LD_LIBRARY_PATH from the environment.

func (*LibCollection) Libs added in v0.12.0

func (c *LibCollection) Libs() iter.Seq[string]

Libs returns an iterator that iterates all libraries sorted by path.

func (*LibCollection) SearchPaths added in v0.12.0

func (c *LibCollection) SearchPaths() iter.Seq[string]

SearchPaths returns an iterator that iterates all search paths sorted by path.

Jump to

Keyboard shortcuts

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