diff --git a/src/syscall/syscall_libc.go b/src/syscall/syscall_libc.go index 5c701710..313ae36f 100644 --- a/src/syscall/syscall_libc.go +++ b/src/syscall/syscall_libc.go @@ -146,6 +146,8 @@ func Unlink(path string) (err error) { return } +func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) + func Kill(pid int, sig Signal) (err error) { return ENOSYS // TODO } @@ -290,6 +292,18 @@ func Environ() []string { return envs } +// BytePtrFromString returns a pointer to a NUL-terminated array of +// bytes containing the text of s. If s contains a NUL byte at any +// location, it returns (nil, EINVAL). +func BytePtrFromString(s string) (*byte, error) { + for i := 0; i < len(s); i++ { + if s[i] == 0 { + return nil, EINVAL + } + } + return &cstring(s)[0], nil +} + // cstring converts a Go string to a C string. func cstring(s string) []byte { data := make([]byte, len(s)+1) diff --git a/src/syscall/syscall_libc_darwin.go b/src/syscall/syscall_libc_darwin.go index 2628185d..2a0dd206 100644 --- a/src/syscall/syscall_libc_darwin.go +++ b/src/syscall/syscall_libc_darwin.go @@ -52,6 +52,9 @@ const ( DT_SOCK = 0xc DT_UNKNOWN = 0x0 DT_WHT = 0xe + F_GETFL = 0x3 + F_SETFL = 0x4 + O_NONBLOCK = 0x4 ) // Source: https://opensource.apple.com/source/xnu/xnu-7195.81.3/bsd/sys/errno.h.auto.html @@ -62,6 +65,7 @@ const ( EEXIST Errno = 17 EINTR Errno = 4 ENOTDIR Errno = 20 + EISDIR Errno = 21 EINVAL Errno = 22 EMFILE Errno = 24 EPIPE Errno = 32 @@ -271,6 +275,32 @@ func Getpagesize() int { return int(libc_getpagesize()) } +// The following RawSockAddr* types have been copied from the Go source tree and +// are here purely to fix build errors. + +type RawSockaddr struct { + Len uint8 + Family uint8 + Data [14]int8 +} + +type RawSockaddrInet4 struct { + Len uint8 + Family uint8 + Port uint16 + Addr [4]byte /* in_addr */ + Zero [8]int8 +} + +type RawSockaddrInet6 struct { + Len uint8 + Family uint8 + Port uint16 + Flowinfo uint32 + Addr [16]byte /* in6_addr */ + Scope_id uint32 +} + // int pipe(int32 *fds); // //export pipe diff --git a/src/syscall/syscall_libc_nintendoswitch.go b/src/syscall/syscall_libc_nintendoswitch.go index 698a7e43..707650d3 100644 --- a/src/syscall/syscall_libc_nintendoswitch.go +++ b/src/syscall/syscall_libc_nintendoswitch.go @@ -71,6 +71,14 @@ func Getpagesize() int { return 4096 // TODO } +type RawSockaddrInet4 struct { + // stub +} + +type RawSockaddrInet6 struct { + // stub +} + // int open(const char *pathname, int flags, mode_t mode); // //export open diff --git a/src/syscall/syscall_libc_wasi.go b/src/syscall/syscall_libc_wasi.go index 12959238..18118ab4 100644 --- a/src/syscall/syscall_libc_wasi.go +++ b/src/syscall/syscall_libc_wasi.go @@ -87,6 +87,22 @@ const ( PROT_READ = 1 PROT_WRITE = 2 PROT_EXEC = 4 + + // ../../lib/wasi-libc/expected/wasm32-wasi/predefined-macros.txt + F_GETFL = 3 + F_SETFL = 4 +) + +// These values are needed as a stub until Go supports WASI as a full target. +// The constant values don't have a meaning and don't correspond to anything +// real. +const ( + _ = iota + SYS_FCNTL + SYS_FCNTL64 + SYS_FSTATAT64 + SYS_OPENAT + SYS_UNLINKAT ) //go:extern errno @@ -308,6 +324,32 @@ func Getpagesize() int { return 65536 } +type Utsname struct { + Sysname [65]int8 + Nodename [65]int8 + Release [65]int8 + Version [65]int8 + Machine [65]int8 + Domainname [65]int8 +} + +// Stub Utsname, needed because WASI pretends to be linux/arm. +func Uname(buf *Utsname) (err error) + +type RawSockaddrInet4 struct { + // stub +} + +type RawSockaddrInet6 struct { + // stub +} + +// This is a stub, it is not functional. +func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) + +// This is a stub, it is not functional. +func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) + // int stat(const char *path, struct stat * buf); // //export stat diff --git a/src/syscall/syscall_nonhosted.go b/src/syscall/syscall_nonhosted.go index 04a77680..87d4d9d7 100644 --- a/src/syscall/syscall_nonhosted.go +++ b/src/syscall/syscall_nonhosted.go @@ -210,3 +210,11 @@ func Getpagesize() int { // common assumption when pagesize is unknown return 4096 } + +type RawSockaddrInet4 struct { + // stub +} + +type RawSockaddrInet6 struct { + // stub +} diff --git a/src/syscall/syscall_unix.go b/src/syscall/syscall_unix.go index 0cd8f286..23d81fb8 100644 --- a/src/syscall/syscall_unix.go +++ b/src/syscall/syscall_unix.go @@ -1,3 +1,18 @@ package syscall func Exec(argv0 string, argv []string, envv []string) (err error) + +// The two SockaddrInet* structs have been copied from the Go source tree. + +type SockaddrInet4 struct { + Port int + Addr [4]byte + raw RawSockaddrInet4 +} + +type SockaddrInet6 struct { + Port int + ZoneId uint32 + Addr [16]byte + raw RawSockaddrInet6 +}