fix(verify): make the executable mapping build on FreeBSD
Assisted-by: GLM 5.3 Flash
This commit is contained in:
+5
-2
@@ -19,6 +19,8 @@ import (
|
||||
"fmt"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
// Executable maps a copy of code into a read-execute memory region suitable
|
||||
@@ -49,8 +51,9 @@ func Map(code []byte) (*Executable, error) {
|
||||
}
|
||||
copy(mem, code)
|
||||
|
||||
// Remove write permission (W^X).
|
||||
if err := syscall.Mprotect(mem, syscall.PROT_READ|syscall.PROT_EXEC); err != nil {
|
||||
// Remove write permission (W^X). x/sys carries Mprotect on every
|
||||
// platform the package builds for; the stdlib syscall one is Linux-only.
|
||||
if err := unix.Mprotect(mem, syscall.PROT_READ|syscall.PROT_EXEC); err != nil {
|
||||
syscall.Munmap(mem)
|
||||
return nil, fmt.Errorf("verify: mprotect: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user