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
- Variables
- func CompilerSupported() bool
- func FakeNanosleep(int64)
- func FakeOsyield()
- func Fdatasync(f fs.File) (err error)
- func IsTerminal(fd uintptr) bool
- func Lstat(path string, st *Stat_t) error
- func MmapCodeSegment(code io.Reader, size int) ([]byte, 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 OpenFile(name string, flag int, perm fs.FileMode) (f *os.File, err error)
- func Readdirnames(f fs.File, n int) (names []string, err error)
- func Rename(from, to string) error
- func SanitizeSeparator([]byte)
- func Stat(path string, st *Stat_t) error
- func StatFile(f fs.File, st *Stat_t) (err error)
- func Unlink(name string) error
- func UnwrapOSError(err error) error
- func Walltime() (sec int64, nsec int32)
- type Dirent
- func Readdir(f fs.File, n int) (dirents []*Dirent, err error)
- func (d *Dirent) IsDir() bool
- func (d *Dirent) String() string
- type File
- type PathFile
- type ReadFile
- type Stat_t
Constants ¶
const ( O_DIRECTORY = 1 << 29 O_NOFOLLOW = 1 << 30 )
See the comments on the same constants in open_file_windows.go
const ( // FakeEpochNanos is midnight UTC 2022-01-01 and exposed for testing FakeEpochNanos = 1640995200000 * ms )
Variables ¶
TODO: IsAtLeastGo120
Functions ¶
func CompilerSupported ¶
func CompilerSupported() bool
CompilerSupported is exported for tests and includes constraints here and also the assembler.
func FakeNanosleep ¶
func FakeNanosleep(int64)
FakeNanosleep implements sys.Nanosleep by returning without sleeping.
func FakeOsyield ¶
func FakeOsyield()
FakeOsyield implements sys.Osyield by returning without yielding.
func Fdatasync ¶
Fdatasync is like syscall.Fdatasync except that's only defined in linux.
Note: This returns with no error instead of syscall.ENOSYS when unimplemented. This prevents fake filesystems from erring.
func IsTerminal ¶
IsTerminal returns true if the given file descriptor is a terminal.
func Lstat ¶
Lstat is like syscall.Lstat. This returns syscall.ENOENT if the path doesn't exist.
Notes
The primary difference between this and Stat is, when the path is a symbolic link, the stat is about the link, not its target, such as directory listings.
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 MunmapCodeSegment ¶
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 ¶
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 OpenFile ¶
func Readdirnames ¶
Readdirnames reads the names of the directory associated with file and returns a slice of up to n strings in an arbitrary order. This is a stateful function, so subsequent calls return any next values.
If n > 0, Readdirnames returns at most n entries or an error. If n <= 0, Readdirnames returns all remaining entries or an error.
Errors
If the error is non-nil, it is a syscall.Errno. io.EOF is not returned because implementations return that value inconsistently.
For portability reasons, no error is returned when the file is closed or removed while open. See https://github.com/ziglang/zig/blob/0.10.1/lib/std/fs.zig#L635-L637
func Rename ¶
func SanitizeSeparator ¶
func SanitizeSeparator([]byte)
SanitizeSeparator sanitizes the path separator in the given buffer. This does nothing on the non-windows platforms.
func Stat ¶
Stat is like syscall.Stat. This returns syscall.ENOENT if the path doesn't exist.
func StatFile ¶
StatFile is like syscall.Fstat, but for fs.File instead of a file descriptor. This returns syscall.EBADF if the file or directory was closed. Note: windows allows you to stat a closed directory.
func Unlink ¶
func UnwrapOSError ¶
UnwrapOSError returns a syscall.Errno or nil if the input is nil.
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 Dirent ¶
type Dirent struct { // Name is the base name of the directory entry. Name string // Ino is the file serial number, or zero if not available. Ino uint64 // Type is fs.FileMode masked on fs.ModeType. For example, zero is a // regular file, fs.ModeDir is a directory and fs.ModeIrregular is unknown. Type fs.FileMode }
Dirent is an entry read from a directory.
This is a portable variant of syscall.Dirent containing fields needed for WebAssembly ABI including WASI snapshot-01 and wasi-filesystem. Unlike fs.DirEntry, this may include the Ino.
func Readdir ¶
Readdir reads the contents of the directory associated with file and returns a slice of up to n Dirent values in an arbitrary order. This is a stateful function, so subsequent calls return any next values.
If n > 0, Readdir returns at most n entries or an error. If n <= 0, Readdir returns all remaining entries or an error.
Errors
If the error is non-nil, it is a syscall.Errno. io.EOF is not returned because implementations return that value inconsistently.
For portability reasons, no error is returned when the file is closed or removed while open. See https://github.com/ziglang/zig/blob/0.10.1/lib/std/fs.zig#L635-L637
func (*Dirent) IsDir ¶
IsDir returns true if the Type is fs.ModeDir.
func (*Dirent) String ¶
type File ¶
type File interface { ReadFile io.Writer io.WriterAt // for pwrite // contains filtered or unexported methods }
File declares all interfaces defined on os.File used by wazero.
type PathFile ¶
type PathFile interface { Path() string }
PathFile is implemented on files that retain the path to their pre-open.
type ReadFile ¶
type ReadFile interface { fs.ReadDirFile io.ReaderAt // for pread io.Seeker // fallback for ReaderAt for embed:fs // contains filtered or unexported methods }
ReadFile declares all read interfaces defined on os.File used by wazero.
type Stat_t ¶
type Stat_t struct { // Dev is the device ID of device containing the file. Dev uint64 // Ino is the file serial number. Ino uint64 // Mode is the same as Mode on fs.FileInfo containing bits to identify the // type of the file (fs.ModeType) and its permissions (fs.ModePerm). Mode fs.FileMode /// Nlink is the number of hard links to the file. Nlink uint64 // Size is the length in bytes for regular files. For symbolic links, this // is length in bytes of the pathname contained in the symbolic link. Size int64 // Atim is the last data access timestamp in epoch nanoseconds. Atim int64 // Mtim is the last data modification timestamp in epoch nanoseconds. Mtim int64 // Ctim is the last file status change timestamp in epoch nanoseconds. Ctim int64 }
Stat_t is similar to syscall.Stat_t, and fields frequently used by WebAssembly ABI including WASI snapshot-01, GOOS=js and wasi-filesystem.
Note
Zero values may be returned where not available. For example, fs.FileInfo implementations may not be able to provide Ino values.
Source Files ¶
buf_writer.go crypto.go dir.go errno.go error.go file.go mmap_unsupported.go open_file_js.go platform.go rename.go separator.go stat.go stat_unsupported.go sync.go sync_unsupported.go terminal_unsupported.go time.go time_cgo.go unlink.go
- Version
- v1.0.0-rc.1
- Published
- Mar 1, 2023
- Platform
- js/wasm
- Imports
- 13 packages
- Last checked
- 3 hours ago –
Tools for package owners.