package platform

import "github.com/tetratelabs/wazero/internal/platform"

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

const (
	// CpuFeatureSSE3 is the flag to query CpuFeatureFlags.Has for SSEv3 capabilities
	CpuFeatureSSE3 = uint64(1)
	// CpuFeatureSSE4_1 is the flag to query CpuFeatureFlags.Has for SSEv4.1 capabilities
	CpuFeatureSSE4_1 = uint64(1) << 19
	// CpuFeatureSSE4_2 is the flag to query CpuFeatureFlags.Has for SSEv4.2 capabilities
	CpuFeatureSSE4_2 = uint64(1) << 20
)
const (
	// CpuExtraFeatureABM is the flag to query CpuFeatureFlags.HasExtra for Advanced Bit Manipulation capabilities (e.g. LZCNT)
	CpuExtraFeatureABM = uint64(1) << 5
)
const (

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

Variables

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.

var IsAtLeastGo120 = isAtLeastGo120(runtime.Version())

IsAtLeastGo120 checks features added in 1.20. We can remove this when Go 1.22 is out.

Functions

func CompilerSupported

func CompilerSupported() bool

CompilerSupported is exported for tests and includes constraints here and also the assembler.

func MmapCodeSegment

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

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

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

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.

func NewFakeWalltime

func NewFakeWalltime() sys.Walltime

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

func RemapCodeSegment

func RemapCodeSegment(code []byte, size int) ([]byte, error)

RemapCodeSegment reallocates the memory mapping of an existing code segment to increase its size. The previous code mapping is unmapped and must not be reused after the function returns.

This is similar to mremap(2) on linux, and emulated on platforms which do not have this syscall.

See https://man7.org/linux/man-pages/man2/mremap.2.html

func ToPosixPath

func ToPosixPath(in string) string

ToPosixPath returns the input, converting any backslashes to forward ones.

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 interface {
	// Has returns true when the specified flag (represented as uint64) is supported
	Has(cpuFeature uint64) bool
	// HasExtra returns true when the specified extraFlag (represented as uint64) is supported
	HasExtra(cpuFeature uint64) bool
}

CpuFeatureFlags exposes methods for querying CPU capabilities

var CpuFeatures CpuFeatureFlags = loadCpuFeatureFlags()

CpuFeatures exposes the capabilities for this CPU, queried via the Has, HasExtra methods

type FdSet

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

FdSet implements the same methods provided on other plaforms.

Note: the implementation is very different from POSIX; Windows provides POSIX select only for sockets. We emulate a select for other APIs in the sysfs package, but we still want to use the "real" select in the case of sockets. So, we keep separate FdSets for sockets, pipes and regular files, so that we can handle them separately. For instance sockets can be used directly in winsock select.

func (*FdSet) Clear

func (f *FdSet) Clear(fd int)

Clear removes the given fd from the set.

func (*FdSet) Copy

func (f *FdSet) Copy() *FdSet

Copy returns a copy of this FdSet. It returns nil, if the FdSet is nil.

func (*FdSet) Count

func (f *FdSet) Count() int

Zero clears the set. It returns 0 if the FdSet is nil.

func (*FdSet) IsSet

func (f *FdSet) IsSet(fd int) bool

IsSet returns true when fd is in the set.

func (*FdSet) Pipes

func (f *FdSet) Pipes() *WinSockFdSet

Pipes returns a WinSockFdSet containing the handles in this FdSet that are pipes.

func (*FdSet) Regular

func (f *FdSet) Regular() *WinSockFdSet

Regular returns a WinSockFdSet containing the handles in this FdSet that are regular files.

func (*FdSet) Set

func (f *FdSet) Set(fd int)

Set adds the given fd to the set.

func (*FdSet) SetAll

func (f *FdSet) SetAll(g *FdSet)

SetAll overwrites all the fields in f with the fields in g.

func (*FdSet) Sockets

func (f *FdSet) Sockets() *WinSockFdSet

Sockets returns a WinSockFdSet containing the handles in this FdSet that are sockets.

func (*FdSet) Zero

func (f *FdSet) Zero()

Zero clears the set.

type WinSockFdSet

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

WinSockFdSet implements the FdSet representation that is used internally by WinSock.

Note: this representation is quite different from the one used in most POSIX implementations where a bitfield is usually implemented; instead on Windows we have a simpler array+count pair. Notice that because it keeps a count of the inserted handles, the first argument of select in WinSock is actually ignored.

The implementation of the Set, Clear, IsSet, Zero, methods follows exactly the real implementation found in WinSock2.h, e.g. see: https://github.com/microsoft/win32metadata/blob/ef7725c75c6b39adfdc13ba26fb1d89ac954449a/generation/WinSDK/RecompiledIdlHeaders/um/WinSock2.h#L124-L175

func (*WinSockFdSet) Clear

func (f *WinSockFdSet) Clear(fd int)

Clear removes the given fd from the set.

func (*WinSockFdSet) Copy

func (f *WinSockFdSet) Copy() *WinSockFdSet

Copy returns a copy of the fd set or nil if it is nil.

func (*WinSockFdSet) Count

func (f *WinSockFdSet) Count() int

Count returns the number of values that are set in the fd set.

func (*WinSockFdSet) Get

func (f *WinSockFdSet) Get(index int) syscall.Handle

Get returns the handle at the given index.

func (*WinSockFdSet) IsSet

func (f *WinSockFdSet) IsSet(fd int) bool

IsSet returns true when fd is in the set.

func (*WinSockFdSet) Set

func (f *WinSockFdSet) Set(fd int)

Set adds the given fd to the set.

func (*WinSockFdSet) Zero

func (f *WinSockFdSet) Zero()

Zero clears the set.

Source Files

cpuid_amd64.go crypto.go fdset_windows.go mmap_windows.go mremap_other.go path_windows.go platform.go platform_amd64.go time.go time_windows.go

Version
v1.3.1
Published
Jul 22, 2023
Platform
windows/amd64
Imports
13 packages
Last checked
6 hours ago

Tools for package owners.