syscall: add more stubs as needed for Go 1.20 support

Этот коммит содержится в:
Ayke van Laethem 2023-02-02 20:29:06 +01:00 коммит произвёл Ayke
родитель 1996fad075
коммит d8b1fac690
6 изменённых файлов: 117 добавлений и 0 удалений

Просмотреть файл

@ -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)

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -210,3 +210,11 @@ func Getpagesize() int {
// common assumption when pagesize is unknown
return 4096
}
type RawSockaddrInet4 struct {
// stub
}
type RawSockaddrInet6 struct {
// stub
}

Просмотреть файл

@ -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
}