Documentation
¶
Overview ¶
Package platform includes runtime-specific code needed for the compiler or otherwise.
Note: This is a dependency-free alternative to depending on parts of Go's x/sys. See /RATIONALE.md for more context.
Index ¶
- Constants
- Variables
- func CompilerSupported() bool
- func CompilerSupports(features api.CoreFeatures) bool
- func MmapCodeSegment(size int) ([]byte, error)
- func MprotectRX(b []byte) (err error)
- func MunmapCodeSegment(code []byte) error
- func Nanosleep(ns int64)
- func Nanotime() int64
- func NewFakeNanotime() sys.Nanotime
- func NewFakeRandSource() io.Reader
- func NewFakeWalltime() sys.Walltime
- func ToPosixPath(in string) string
- func Walltime() (sec int64, nsec int32)
- type CpuFeature
- type CpuFeatureFlags
Constants ¶
const (
// FakeEpochNanos is midnight UTC 2022-01-01 and exposed for testing
FakeEpochNanos = 1640995200000 * ms
)
Variables ¶
var CpuFeatures = loadCpuFeatureFlags()
CpuFeatures exposes the capabilities for this CPU, queried via the Has, HasExtra methods.
var FakeNanosleep = sys.Nanosleep(func(int64) {})
FakeNanosleep implements sys.Nanosleep by returning without sleeping.
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 ¶ added in v1.9.0
func CompilerSupports(features api.CoreFeatures) bool
func MmapCodeSegment ¶
MmapCodeSegment copies the code into the executable region and returns the byte slice of the region.
See https://man7.org/linux/man-pages/man2/mmap.2.html for mmap API and flags.
func MprotectRX ¶ added in v1.0.2
MprotectRX is like syscall.Mprotect with RX permission.
func MunmapCodeSegment ¶
MunmapCodeSegment unmaps the given memory region.
func Nanotime ¶
func Nanotime() int64
Nanotime implements sys.Nanotime with runtime.nanotime() if CGO is available and time.Since if not.
func NewFakeNanotime ¶
NewFakeNanotime implements sys.Nanotime that increases by 1ms each reading. See /RATIONALE.md
func NewFakeRandSource ¶
NewFakeRandSource returns a deterministic source of random values.
func NewFakeWalltime ¶
NewFakeWalltime implements sys.Walltime with FakeEpochNanos that increases by 1ms each reading. See /RATIONALE.md
func ToPosixPath ¶
ToPosixPath returns the input, as only windows might return backslashes.
func Walltime ¶
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 CpuFeature ¶ added in v1.7.0
type CpuFeature uint64
const ( // CpuFeatureAmd64SSE3 is the flag to query CpuFeatureFlags.Has for SSEv3 capabilities on amd64 CpuFeatureAmd64SSE3 CpuFeature = 1 // CpuFeatureAmd64SSE4_1 is the flag to query CpuFeatureFlags.Has for SSEv4.1 capabilities on amd64 CpuFeatureAmd64SSE4_1 CpuFeature = 1 << 19 // CpuFeatureAmd64SSE4_2 is the flag to query CpuFeatureFlags.Has for SSEv4.2 capabilities on amd64 CpuFeatureAmd64SSE4_2 CpuFeature = 1 << 20 )
const ( // CpuExtraFeatureAmd64ABM is the flag to query CpuFeatureFlags.HasExtra for Advanced Bit Manipulation capabilities (e.g. LZCNT) on amd64 CpuExtraFeatureAmd64ABM CpuFeature = 1 << 5 )
const ( // CpuFeatureArm64Atomic is the flag to query CpuFeatureFlags.Has for Large System Extensions capabilities on arm64 CpuFeatureArm64Atomic CpuFeature = 1 << 21 )
type CpuFeatureFlags ¶
type CpuFeatureFlags interface { // Has returns true when the specified flag (represented as uint64) is supported Has(cpuFeature CpuFeature) bool // HasExtra returns true when the specified extraFlag (represented as uint64) is supported HasExtra(cpuFeature CpuFeature) bool // Raw returns the raw bitset that represents CPU features used by wazero. This can be used for cache keying. // For now, we only use four features, so uint64 is enough. Raw() uint64 }
CpuFeatureFlags exposes methods for querying CPU capabilities