Skip to content

Commit

Permalink
Enable compiler on NetBSD, DragonFly, illumos and Solaris (#2343)
Browse files Browse the repository at this point in the history
  • Loading branch information
ncruces authored Nov 15, 2024
1 parent e5ba948 commit 0a20795
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 24 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ We also test cross compilation for many `GOOS` and `GOARCH` combinations.
* macOS is tested only on arm64.
* Compiler
* Linux is tested on amd64 (native) as well arm64 via emulation.
* Windows and FreeBSD are only tested on amd64.
* Windows, FreeBSD, NetBSD, DragonFly BSD, illumos and Solaris are
tested only on amd64.
* macOS is tested only on arm64.

wazero has no dependencies and doesn't require CGO. This means it can also be
Expand Down
2 changes: 1 addition & 1 deletion config_supported.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//
// Meanwhile, users who know their runtime.GOOS can operate with the compiler
// may choose to use NewRuntimeConfigCompiler explicitly.
//go:build (amd64 || arm64) && (darwin || linux || freebsd || windows)
//go:build (amd64 || arm64) && (linux || darwin || freebsd || netbsd || dragonfly || solaris || windows)

package wazero

Expand Down
2 changes: 1 addition & 1 deletion config_unsupported.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This is the opposite constraint of config_supported.go
//go:build !(amd64 || arm64) || !(darwin || linux || freebsd || windows)
//go:build !(amd64 || arm64) || !(linux || darwin || freebsd || netbsd || dragonfly || solaris || windows)

package wazero

Expand Down
2 changes: 1 addition & 1 deletion internal/platform/mmap_other.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Separated from linux which has support for huge pages.
//go:build darwin || freebsd
//go:build darwin || freebsd || netbsd || dragonfly || solaris

package platform

Expand Down
17 changes: 1 addition & 16 deletions internal/platform/mmap_unix.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
//go:build (darwin || linux || freebsd) && !tinygo
//go:build (linux || darwin || freebsd || netbsd || dragonfly || solaris) && !tinygo

package platform

import (
"syscall"
"unsafe"
)

const (
Expand All @@ -31,17 +30,3 @@ func mmapCodeSegmentARM64(size int) ([]byte, error) {
// The region must be RW: RW for writing native codes.
return mmapCodeSegment(size, mmapProtARM64)
}

// MprotectRX is like syscall.Mprotect with RX permission, defined locally so that freebsd compiles.
func MprotectRX(b []byte) (err error) {
var _p0 unsafe.Pointer
if len(b) > 0 {
_p0 = unsafe.Pointer(&b[0])
}
const prot = syscall.PROT_READ | syscall.PROT_EXEC
_, _, e1 := syscall.Syscall(syscall.SYS_MPROTECT, uintptr(_p0), uintptr(len(b)), uintptr(prot))
if e1 != 0 {
err = syscall.Errno(e1)
}
return
}
2 changes: 1 addition & 1 deletion internal/platform/mmap_unsupported.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !(darwin || linux || freebsd || windows) || tinygo
//go:build !(linux || darwin || freebsd || netbsd || dragonfly || solaris || windows) || tinygo

package platform

Expand Down
22 changes: 22 additions & 0 deletions internal/platform/mprotect_bsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//go:build (freebsd || netbsd || dragonfly) && !tinygo

package platform

import (
"syscall"
"unsafe"
)

// MprotectRX is like syscall.Mprotect with RX permission, defined locally so that BSD compiles.
func MprotectRX(b []byte) (err error) {
var _p0 unsafe.Pointer
if len(b) > 0 {
_p0 = unsafe.Pointer(&b[0])
}
const prot = syscall.PROT_READ | syscall.PROT_EXEC
_, _, e1 := syscall.Syscall(syscall.SYS_MPROTECT, uintptr(_p0), uintptr(len(b)), uintptr(prot))
if e1 != 0 {
err = syscall.Errno(e1)
}
return
}
10 changes: 10 additions & 0 deletions internal/platform/mprotect_syscall.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//go:build (linux || darwin) && !tinygo

package platform

import "syscall"

// MprotectRX is like syscall.Mprotect with RX permission.
func MprotectRX(b []byte) (err error) {
return syscall.Mprotect(b, syscall.PROT_READ|syscall.PROT_EXEC)
}
9 changes: 9 additions & 0 deletions internal/platform/mprotect_unsupported.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build solaris && !tinygo

package platform

import "syscall"

func MprotectRX(b []byte) error {
return syscall.ENOTSUP
}
7 changes: 4 additions & 3 deletions internal/platform/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ var archRequirementsVerified bool
// CompilerSupported is exported for tests and includes constraints here and also the assembler.
func CompilerSupported() bool {
switch runtime.GOOS {
case "darwin", "windows", "linux", "freebsd":
case "linux", "darwin", "freebsd", "netbsd", "dragonfly", "windows":
return archRequirementsVerified
case "solaris", "illumos":
return runtime.GOARCH == "amd64" && archRequirementsVerified
default:
return false
}

return archRequirementsVerified
}

// MmapCodeSegment copies the code into the executable region and returns the byte slice of the region.
Expand Down

0 comments on commit 0a20795

Please sign in to comment.