Skip to content

Commit d8b1fac

Browse files
committed
syscall: add more stubs as needed for Go 1.20 support
1 parent 1996fad commit d8b1fac

File tree

6 files changed

+117
-0
lines changed

6 files changed

+117
-0
lines changed

src/syscall/syscall_libc.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ func Unlink(path string) (err error) {
146146
return
147147
}
148148

149+
func Faccessat(dirfd int, path string, mode uint32, flags int) (err error)
150+
149151
func Kill(pid int, sig Signal) (err error) {
150152
return ENOSYS // TODO
151153
}
@@ -290,6 +292,18 @@ func Environ() []string {
290292
return envs
291293
}
292294

295+
// BytePtrFromString returns a pointer to a NUL-terminated array of
296+
// bytes containing the text of s. If s contains a NUL byte at any
297+
// location, it returns (nil, EINVAL).
298+
func BytePtrFromString(s string) (*byte, error) {
299+
for i := 0; i < len(s); i++ {
300+
if s[i] == 0 {
301+
return nil, EINVAL
302+
}
303+
}
304+
return &cstring(s)[0], nil
305+
}
306+
293307
// cstring converts a Go string to a C string.
294308
func cstring(s string) []byte {
295309
data := make([]byte, len(s)+1)

src/syscall/syscall_libc_darwin.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ const (
5252
DT_SOCK = 0xc
5353
DT_UNKNOWN = 0x0
5454
DT_WHT = 0xe
55+
F_GETFL = 0x3
56+
F_SETFL = 0x4
57+
O_NONBLOCK = 0x4
5558
)
5659

5760
// Source: https://opensource.apple.com/source/xnu/xnu-7195.81.3/bsd/sys/errno.h.auto.html
@@ -62,6 +65,7 @@ const (
6265
EEXIST Errno = 17
6366
EINTR Errno = 4
6467
ENOTDIR Errno = 20
68+
EISDIR Errno = 21
6569
EINVAL Errno = 22
6670
EMFILE Errno = 24
6771
EPIPE Errno = 32
@@ -271,6 +275,32 @@ func Getpagesize() int {
271275
return int(libc_getpagesize())
272276
}
273277

278+
// The following RawSockAddr* types have been copied from the Go source tree and
279+
// are here purely to fix build errors.
280+
281+
type RawSockaddr struct {
282+
Len uint8
283+
Family uint8
284+
Data [14]int8
285+
}
286+
287+
type RawSockaddrInet4 struct {
288+
Len uint8
289+
Family uint8
290+
Port uint16
291+
Addr [4]byte /* in_addr */
292+
Zero [8]int8
293+
}
294+
295+
type RawSockaddrInet6 struct {
296+
Len uint8
297+
Family uint8
298+
Port uint16
299+
Flowinfo uint32
300+
Addr [16]byte /* in6_addr */
301+
Scope_id uint32
302+
}
303+
274304
// int pipe(int32 *fds);
275305
//
276306
//export pipe

src/syscall/syscall_libc_nintendoswitch.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ func Getpagesize() int {
7171
return 4096 // TODO
7272
}
7373

74+
type RawSockaddrInet4 struct {
75+
// stub
76+
}
77+
78+
type RawSockaddrInet6 struct {
79+
// stub
80+
}
81+
7482
// int open(const char *pathname, int flags, mode_t mode);
7583
//
7684
//export open

src/syscall/syscall_libc_wasi.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,22 @@ const (
8787
PROT_READ = 1
8888
PROT_WRITE = 2
8989
PROT_EXEC = 4
90+
91+
// ../../lib/wasi-libc/expected/wasm32-wasi/predefined-macros.txt
92+
F_GETFL = 3
93+
F_SETFL = 4
94+
)
95+
96+
// These values are needed as a stub until Go supports WASI as a full target.
97+
// The constant values don't have a meaning and don't correspond to anything
98+
// real.
99+
const (
100+
_ = iota
101+
SYS_FCNTL
102+
SYS_FCNTL64
103+
SYS_FSTATAT64
104+
SYS_OPENAT
105+
SYS_UNLINKAT
90106
)
91107

92108
//go:extern errno
@@ -308,6 +324,32 @@ func Getpagesize() int {
308324
return 65536
309325
}
310326

327+
type Utsname struct {
328+
Sysname [65]int8
329+
Nodename [65]int8
330+
Release [65]int8
331+
Version [65]int8
332+
Machine [65]int8
333+
Domainname [65]int8
334+
}
335+
336+
// Stub Utsname, needed because WASI pretends to be linux/arm.
337+
func Uname(buf *Utsname) (err error)
338+
339+
type RawSockaddrInet4 struct {
340+
// stub
341+
}
342+
343+
type RawSockaddrInet6 struct {
344+
// stub
345+
}
346+
347+
// This is a stub, it is not functional.
348+
func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno)
349+
350+
// This is a stub, it is not functional.
351+
func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno)
352+
311353
// int stat(const char *path, struct stat * buf);
312354
//
313355
//export stat

src/syscall/syscall_nonhosted.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,11 @@ func Getpagesize() int {
210210
// common assumption when pagesize is unknown
211211
return 4096
212212
}
213+
214+
type RawSockaddrInet4 struct {
215+
// stub
216+
}
217+
218+
type RawSockaddrInet6 struct {
219+
// stub
220+
}

src/syscall/syscall_unix.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
11
package syscall
22

33
func Exec(argv0 string, argv []string, envv []string) (err error)
4+
5+
// The two SockaddrInet* structs have been copied from the Go source tree.
6+
7+
type SockaddrInet4 struct {
8+
Port int
9+
Addr [4]byte
10+
raw RawSockaddrInet4
11+
}
12+
13+
type SockaddrInet6 struct {
14+
Port int
15+
ZoneId uint32
16+
Addr [16]byte
17+
raw RawSockaddrInet6
18+
}

0 commit comments

Comments
 (0)