Files
wazero/internal/platform/platform.go
Crypt Keeper 4d90a5c364 platform: Allows sysfs to implement utimens natively (#1215)
platform: Allows sysfs to implement utimesns natively

This moves away from `syscall.UtimesNano` as it has intentionally
avoided common features in POSIX, such as handling UTIME_NOW and
UTIME_OMIT. When we eventually expose this API, users will be free to
override `UTIME_NOW` with a fake clock, possibly the same that was
supplied to wazero's `ModuleConfig`.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
Co-authored-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
2023-03-09 13:14:09 +08:00

59 lines
1.6 KiB
Go

// 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.
package platform
import (
"errors"
"io"
"runtime"
"strings"
)
// TODO: IsAtLeastGo120
var IsGo120 = strings.Contains(runtime.Version(), "go1.20")
// archRequirementsVerified is set by platform-specific init to true if the platform is supported
var archRequirementsVerified bool
var _zero uintptr
// CompilerSupported is exported for tests and includes constraints here and also the assembler.
func CompilerSupported() bool {
switch runtime.GOOS {
case "darwin", "windows", "linux", "freebsd":
default:
return false
}
return archRequirementsVerified
}
// 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 MmapCodeSegment(code io.Reader, size int) ([]byte, error) {
if size == 0 {
panic(errors.New("BUG: MmapCodeSegment with zero length"))
}
if runtime.GOARCH == "amd64" {
return mmapCodeSegmentAMD64(code, size)
} else {
return mmapCodeSegmentARM64(code, size)
}
}
// MunmapCodeSegment unmaps the given memory region.
func MunmapCodeSegment(code []byte) error {
if len(code) == 0 {
panic(errors.New("BUG: MunmapCodeSegment with zero length"))
}
return munmapCodeSegment(code)
}
// IsTerminal returns true if the given file descriptor is a terminal.
func IsTerminal(fd uintptr) bool {
return isTerminal(fd)
}