platform

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: Apache-2.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package platform includes runtime-specific code needed for the compiler or otherwise.

Index

Constants

View Source
const (
	// CpuFeatureAmd64SSE4_1 is the flag to query CpuFeatureFlags.Has for SSEv4.1 capabilities on amd64
	CpuFeatureAmd64SSE4_1 = 1 << iota
	// CpuFeatureAmd64BMI1 is the flag to query CpuFeatureFlags.Has for Bit Manipulation Instruction Set 1 (e.g. TZCNT) on amd64
	CpuFeatureAmd64BMI1
	// CpuExtraFeatureABM is the flag to query CpuFeatureFlags.Has for Advanced Bit Manipulation capabilities (e.g. LZCNT) on amd64
	CpuFeatureAmd64ABM
)
View Source
const (

	// FakeEpochNanos is midnight UTC 2022-01-01 and exposed for testing
	FakeEpochNanos = 1640995200000 * ms
)

Variables

View Source
var CpuFeatures = loadCpuFeatureFlags()

CpuFeatures exposes the capabilities for this CPU, queried via the Has method.

View Source
var FakeNanosleep = sys.Nanosleep(func(int64) {})

FakeNanosleep implements sys.Nanosleep by returning without sleeping.

View Source
var FakeOsyield = sys.Osyield(func() {})

FakeOsyield implements sys.Osyield by returning without yielding.

Functions

func CompilerSupported

func CompilerSupported() bool

CompilerSupported includes constraints here and also the assembler.

func CompilerSupports

func CompilerSupports(features api.CoreFeatures) bool

func MmapCodeSegment

func MmapCodeSegment(size int) ([]byte, error)

MmapCodeSegment allocates and returns a byte slice to copy executable code into.

See https://man7.org/linux/man-pages/man2/mmap.2.html for mmap API and flags.

func MprotectCodeSegment

func MprotectCodeSegment(b []byte) (err error)

MprotectCodeSegment is like unix.Mprotect with RX permission.

func MunmapCodeSegment

func MunmapCodeSegment(code []byte) error

MunmapCodeSegment unmaps the given memory region.

func Nanosleep

func Nanosleep(ns int64)

Nanosleep implements sys.Nanosleep with time.Sleep.

func Nanotime

func Nanotime() int64

Nanotime implements sys.Nanotime with runtime.nanotime() if CGO is available and time.Since if not.

func NewFakeNanotime

func NewFakeNanotime() sys.Nanotime

NewFakeNanotime implements sys.Nanotime that increases by 1ms each reading. See /RATIONALE.md

func NewFakeRandSource

func NewFakeRandSource() io.Reader

NewFakeRandSource returns a deterministic source of random values.

Construction is lazy: math/rand's generator seeds a 607-int64 lagged-Fibonacci array (~4.9 KB + ~1800 iterations), and this source is created on *every* instantiate that doesn't set WithRandSource -- yet the common guest never reads random bytes at all. Deferring the generator to the first Read makes those instantiations pay nothing while keeping the output byte-identical (same algorithm, same seed) for guests that do read.

func NewFakeWalltime

func NewFakeWalltime() sys.Walltime

NewFakeWalltime implements sys.Walltime with FakeEpochNanos that increases by 1ms each reading. See /RATIONALE.md

func ToPosixPath

func ToPosixPath(in string) string

ToPosixPath returns the input, as only windows might return backslashes.

func Walltime

func Walltime() (sec int64, nsec int32)

Walltime implements sys.Walltime with time.Now.

Note: This is only notably less efficient than it could be is reading runtime.walltime(). time.Now defensively reads nanotime also, just in case time.Since is used. This doubles the performance impact. However, wall time is likely to be read less frequently than Nanotime. Also, doubling the cost matters less on fast platforms that can return both in <=100ns.

Types

type CpuFeatureFlags

type CpuFeatureFlags uint64

CpuFeatureFlags exposes methods for querying CPU capabilities

const (
	// CpuFeatureArm64Atomic is the flag to query CpuFeatureFlags.Has for Large System Extensions capabilities on arm64
	CpuFeatureArm64Atomic CpuFeatureFlags = 1 << iota
)

func (CpuFeatureFlags) Has

func (CpuFeatureFlags) Raw

func (c CpuFeatureFlags) Raw() uint64

Jump to

Keyboard shortcuts

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