Skip to content

Commit d3ddacd

Browse files
authored
compiler/natives/src/syscall: support more Darwin syscalls
Go 1.12 has changed syscall on Darwin to start using libSystem for forward-compatibility. That means we need to add support for more signals to be able to run all supported tests and examples on macOS. Many of the mappings from libc_aaa_trampoline to SYS_AAA were based on golang/go@a3b0144. Improve error when an unsupported signal is called, by making the signal name visible in the error message. Regenerate natives: go generate github.com/gopherjs/gopherjs/compiler/natives GitHub-Pull-Request: gopherjs#940
1 parent 9d188e9 commit d3ddacd

File tree

3 files changed

+68
-11
lines changed

3 files changed

+68
-11
lines changed

compiler/natives/fs_vfsdata.go

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/natives/src/internal/syscall/unix/unix.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@
22

33
package unix
44

5+
import "syscall"
6+
57
const randomTrap = 0
68
const fstatatTrap = 0
79

810
func IsNonblock(fd int) (nonblocking bool, err error) {
911
return false, nil
1012
}
13+
14+
func unlinkat(dirfd int, path string, flags int) error {
15+
// There's no SYS_UNLINKAT defined in Go 1.12 for Darwin,
16+
// so just implement unlinkat using unlink for now.
17+
return syscall.Unlink(path)
18+
}

compiler/natives/src/syscall/syscall_darwin.go

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,70 @@
22

33
package syscall
44

5-
import (
6-
"github.com/gopherjs/gopherjs/js"
7-
)
5+
import "github.com/gopherjs/gopherjs/js"
86

97
func funcPC(f func()) uintptr {
10-
if js.InternalObject(f) == js.InternalObject(libc_write_trampoline) {
8+
switch js.InternalObject(f) {
9+
case js.InternalObject(libc_open_trampoline):
10+
return SYS_OPEN
11+
case js.InternalObject(libc_stat64_trampoline):
12+
return SYS_STAT64
13+
case js.InternalObject(libc_fstat64_trampoline):
14+
return SYS_FSTAT64
15+
case js.InternalObject(libc_lstat64_trampoline):
16+
return SYS_LSTAT64
17+
case js.InternalObject(libc_mkdir_trampoline):
18+
return SYS_MKDIR
19+
case js.InternalObject(libc_chdir_trampoline):
20+
return SYS_CHDIR
21+
case js.InternalObject(libc_rmdir_trampoline):
22+
return SYS_RMDIR
23+
case js.InternalObject(libc___getdirentries64_trampoline):
24+
return SYS_GETDIRENTRIES64
25+
case js.InternalObject(libc_getattrlist_trampoline):
26+
return SYS_GETATTRLIST
27+
case js.InternalObject(libc_symlink_trampoline):
28+
return SYS_SYMLINK
29+
case js.InternalObject(libc_readlink_trampoline):
30+
return SYS_READLINK
31+
case js.InternalObject(libc_fcntl_trampoline):
32+
return SYS_FCNTL
33+
case js.InternalObject(libc_read_trampoline):
34+
return SYS_READ
35+
case js.InternalObject(libc_pread_trampoline):
36+
return SYS_PREAD
37+
case js.InternalObject(libc_write_trampoline):
1138
return SYS_WRITE
39+
case js.InternalObject(libc_lseek_trampoline):
40+
return SYS_LSEEK
41+
case js.InternalObject(libc_close_trampoline):
42+
return SYS_CLOSE
43+
case js.InternalObject(libc_unlink_trampoline):
44+
return SYS_UNLINK
45+
case js.InternalObject(libc_getpid_trampoline):
46+
return SYS_GETPID
47+
case js.InternalObject(libc_getuid_trampoline):
48+
return SYS_GETUID
49+
case js.InternalObject(libc_getgid_trampoline):
50+
return SYS_GETGID
51+
default:
52+
// If we just return -1, the caller can only print an unhelpful generic error message, like
53+
// "signal: bad system call".
54+
// So, execute f() to get a more helpful error message that includes the syscall name, like
55+
// "runtime error: native function not implemented: syscall.libc_getpid_trampoline".
56+
f()
57+
return uintptr(minusOne)
1258
}
13-
return uintptr(minusOne)
1459
}
1560

1661
func syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) {
1762
return Syscall(trap, a1, a2, a3)
1863
}
1964

65+
func syscallX(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) {
66+
return Syscall(trap, a1, a2, a3)
67+
}
68+
2069
func syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) {
2170
return Syscall6(trap, a1, a2, a3, a4, a5, a6)
2271
}

0 commit comments

Comments
 (0)