tinygo/src/syscall/syscall_libc.go
Ayke van Laethem 86f8778748 darwin: use custom syscall pkg that uses libsystem
Go 1.12 switched to using libSystem.dylib for system calls, because
Apple recommends against doing direct system calls that Go 1.11 and
earlier did. For more information, see:
  https://github.com/golang/go/issues/17490
  https://developer.apple.com/library/archive/qa/qa1118/_index.html

While the old syscall package was relatively easy to support in TinyGo
(just implement syscall.Syscall*), this got a whole lot harder with Go
1.12 as all syscalls now go through CGo magic to call the underlying
libSystem functions. Therefore, this commit overrides the stdlib syscall
package with a custom package that performs calls with libc (libSystem).
This may be useful not just for darwin but for other platforms as well
that do not place the stable ABI at the syscall boundary like Linux but
at the libc boundary.

Only a very minimal part of the syscall package has been implemented, to
get the tests to pass. More calls can easily be added in the future.
2019-04-05 09:53:51 +02:00

57 строки
1,1 КиБ
Go

// +build darwin
package syscall
import (
"unsafe"
)
func Close(fd int) (err error) {
return ENOSYS // TODO
}
func Write(fd int, p []byte) (n int, err error) {
buf, count := splitSlice(p)
n = libc_write(int32(fd), buf, uint(count))
if n < 0 {
err = getErrno()
}
return
}
func Read(fd int, p []byte) (n int, err error) {
return 0, ENOSYS // TODO
}
func Seek(fd int, offset int64, whence int) (off int64, err error) {
return 0, ENOSYS // TODO
}
func Open(path string, mode int, perm uint32) (fd int, err error) {
return 0, ENOSYS // TODO
}
func Kill(pid int, sig Signal) (err error) {
return ENOSYS // TODO
}
func Getpid() (pid int) {
panic("unimplemented: getpid") // TODO
}
func Getenv(key string) (value string, found bool) {
return "", false // TODO
}
func splitSlice(p []byte) (buf *byte, len uintptr) {
slice := (*struct {
buf *byte
len uintptr
cap uintptr
})(unsafe.Pointer(&p))
return slice.buf, slice.len
}
// ssize_t write(int fd, const void *buf, size_t count)
//go:export write
func libc_write(fd int32, buf *byte, count uint) int