Skip to content

Commit 38efca1

Browse files
dkegel-fastlyaykevl
authored andcommitted
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
1 parent 0a75dd8 commit 38efca1

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/syscall/syscall_nonhosted.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ const (
2727
SIGTRAP
2828
SIGQUIT
2929
SIGTERM
30+
SIGILL
31+
SIGABRT
32+
SIGBUS
33+
SIGFPE
34+
SIGSEGV
35+
SIGPIPE
3036
)
3137

3238
func (s Signal) Signal() {}
@@ -66,6 +72,22 @@ const (
6672
O_CLOEXEC = 0
6773
)
6874

75+
// Dummy values to allow compiling tests
76+
// Dummy source: https://opensource.apple.com/source/xnu/xnu-7195.81.3/bsd/sys/mman.h.auto.html
77+
const (
78+
PROT_NONE = 0x00 // no permissions
79+
PROT_READ = 0x01 // pages can be read
80+
PROT_WRITE = 0x02 // pages can be written
81+
PROT_EXEC = 0x04 // pages can be executed
82+
83+
MAP_SHARED = 0x0001 // share changes
84+
MAP_PRIVATE = 0x0002 // changes are private
85+
86+
MAP_FILE = 0x0000 // map from file (default)
87+
MAP_ANON = 0x1000 // allocated from memory, swap space
88+
MAP_ANONYMOUS = MAP_ANON
89+
)
90+
6991
func runtime_envs() []string
7092

7193
func Getenv(key string) (value string, found bool) {
@@ -168,6 +190,14 @@ func Wait4(pid int, wstatus *WaitStatus, options int, rusage *Rusage) (wpid int,
168190
return 0, ENOSYS
169191
}
170192

193+
func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error) {
194+
return nil, ENOSYS
195+
}
196+
197+
func Munmap(b []byte) (err error) {
198+
return ENOSYS
199+
}
200+
171201
type Timeval struct {
172202
Sec int64
173203
Usec int64

0 commit comments

Comments
 (0)