sys

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2024 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoInterpreter is returned if no interpreter is found in an ELF file.
	ErrNoInterpreter = errors.New("no interpreter in ELF file")

	// 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")
)
View Source
var ErrArchNotSupported = errors.New("architecture not supported")

Functions

func AssertContainsPaths added in v0.12.0

func AssertContainsPaths(tb testing.TB, actual, expected []string) bool

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. The path must point to an ELF file. ErrNotELFFile is returned if it is not an ELF file. ErrNoInterpreter is returned if no interpreter path is found in the ELF file. This is the case if the binary was statically linked.

The objects are searched for in the usual search paths of the file's interpreter. Note that the dynamic linker consumes the environment variable LD_LIBRARY_PATH, so it can be used to add additional search paths.

Since this implementation executes the ELF interpreter of the given file, it should be run only for trusted binaries!

Until version 2.27 the glibc provided ldd worked like this implementation and executed the binaries ELF interpreter directly. Since this has some security implications and may lead to unintended execution of arbitrary code it was changed with version 2.27. With newer versions, ldd tries a set of fixed known ELF interpreters. Since they are specific to the glibc build, thus Linux distribution specific, it is not feasible for this implementation. Because of this the former procedure is used, so use with great care!

func MustAbsPath added in v0.12.0

func MustAbsPath(tb testing.TB, path string) string

Types

type Arch

type Arch string
const (
	AMD64   Arch = "amd64"
	ARM64   Arch = "arm64"
	RISCV64 Arch = "riscv64"
	Native  Arch = Arch(runtime.GOARCH)
)

func ReadELFArch added in v0.12.0

func ReadELFArch(fileName string) (Arch, error)

ReadELFArch returns the sys.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

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

func (*Arch) String

func (a *Arch) String() string

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]

func (*LibCollection) SearchPaths added in v0.12.0

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

Jump to

Keyboard shortcuts

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