From 38efca1e2d6e76d524eab42b92e52b98eb37953f Mon Sep 17 00:00:00 2001 From: Dan Kegel Date: Sat, 19 Mar 2022 11:22:09 -0700 Subject: [PATCH] syscall: stub mmap(), munmap(), MAP_SHARED, PROT_READ, SIGBUS, etc. on nonhosted targets Makes 1.18 tests a little happier. Works around this error: $ make test GOTESTFLAGS="-run TestTest/EmulatedCortexM3/Pass" ... main_test.go:520: test error: could not compile: /usr/local/go/src/internal/fuzz/sys_posix.go:19:18: PROT_READ not declared by package syscall --- src/syscall/syscall_nonhosted.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/syscall/syscall_nonhosted.go b/src/syscall/syscall_nonhosted.go index b63dc0b6..4a558550 100644 --- a/src/syscall/syscall_nonhosted.go +++ b/src/syscall/syscall_nonhosted.go @@ -27,6 +27,12 @@ const ( SIGTRAP SIGQUIT SIGTERM + SIGILL + SIGABRT + SIGBUS + SIGFPE + SIGSEGV + SIGPIPE ) func (s Signal) Signal() {} @@ -66,6 +72,22 @@ const ( O_CLOEXEC = 0 ) +// Dummy values to allow compiling tests +// Dummy source: https://opensource.apple.com/source/xnu/xnu-7195.81.3/bsd/sys/mman.h.auto.html +const ( + PROT_NONE = 0x00 // no permissions + PROT_READ = 0x01 // pages can be read + PROT_WRITE = 0x02 // pages can be written + PROT_EXEC = 0x04 // pages can be executed + + MAP_SHARED = 0x0001 // share changes + MAP_PRIVATE = 0x0002 // changes are private + + MAP_FILE = 0x0000 // map from file (default) + MAP_ANON = 0x1000 // allocated from memory, swap space + MAP_ANONYMOUS = MAP_ANON +) + func runtime_envs() []string func Getenv(key string) (value string, found bool) { @@ -168,6 +190,14 @@ func Wait4(pid int, wstatus *WaitStatus, options int, rusage *Rusage) (wpid int, return 0, ENOSYS } +func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error) { + return nil, ENOSYS +} + +func Munmap(b []byte) (err error) { + return ENOSYS +} + type Timeval struct { Sec int64 Usec int64