diff options
author | Ayke van Laethem <[email protected]> | 2023-07-06 12:01:52 +0200 |
---|---|---|
committer | Ron Evans <[email protected]> | 2023-08-04 11:59:11 +0200 |
commit | a93f0ed12a30d694ad8db2a2636b1247e772c3e8 (patch) | |
tree | e1790e1e4cb11623e05efb93450b5ad937afcf51 /src | |
parent | c25dd0a972a1d68b4d154831a6d196e28f17ddad (diff) | |
download | tinygo-a93f0ed12a30d694ad8db2a2636b1247e772c3e8.tar.gz tinygo-a93f0ed12a30d694ad8db2a2636b1247e772c3e8.zip |
all: Go 1.21 support
Diffstat (limited to 'src')
-rw-r--r-- | src/internal/bytealg/bytealg.go | 10 | ||||
-rw-r--r-- | src/runtime/baremetal.go | 2 | ||||
-rw-r--r-- | src/runtime/metrics.go | 10 | ||||
-rw-r--r-- | src/runtime/runtime.go | 24 | ||||
-rw-r--r-- | src/runtime/runtime_nintendoswitch.go | 2 | ||||
-rw-r--r-- | src/runtime/runtime_wasm_js.go | 4 | ||||
-rw-r--r-- | src/runtime/symtab.go | 5 | ||||
-rw-r--r-- | src/syscall/syscall_libc_darwin.go | 1 |
8 files changed, 54 insertions, 4 deletions
diff --git a/src/internal/bytealg/bytealg.go b/src/internal/bytealg/bytealg.go index a6744c414..72be9ac58 100644 --- a/src/internal/bytealg/bytealg.go +++ b/src/internal/bytealg/bytealg.go @@ -251,3 +251,13 @@ func IndexRabinKarp(s, substr string) int { } return -1 } + +// MakeNoZero makes a slice of length and capacity n without zeroing the bytes. +// It is the caller's responsibility to ensure uninitialized bytes +// do not leak to the end user. +func MakeNoZero(n int) []byte { + // Note: this does zero the buffer even though that's not necessary. + // For performance reasons we might want to change this (similar to the + // malloc function implemented in the runtime). + return make([]byte, n) +} diff --git a/src/runtime/baremetal.go b/src/runtime/baremetal.go index a51191bb9..173d0db25 100644 --- a/src/runtime/baremetal.go +++ b/src/runtime/baremetal.go @@ -38,6 +38,8 @@ func growHeap() bool { //export malloc func libc_malloc(size uintptr) unsafe.Pointer { + // Note: this zeroes the returned buffer which is not necessary. + // The same goes for bytealg.MakeNoZero. return alloc(size, nil) } diff --git a/src/runtime/metrics.go b/src/runtime/metrics.go new file mode 100644 index 000000000..bd07777db --- /dev/null +++ b/src/runtime/metrics.go @@ -0,0 +1,10 @@ +package runtime + +// Implementation of functions needed by runtime/metrics. +// Mostly just dummy implementations: we don't currently use any of these +// metrics. + +//go:linkname godebug_registerMetric internal/godebug.registerMetric +func godebug_registerMetric(name string, read func() uint64) { + // Dummy function for compatibility with Go 1.21. +} diff --git a/src/runtime/runtime.go b/src/runtime/runtime.go index ceb6a2240..ac7cd25c9 100644 --- a/src/runtime/runtime.go +++ b/src/runtime/runtime.go @@ -100,3 +100,27 @@ func godebug_setUpdate(update func(string, string)) { // variable changes (for example, via os.Setenv). godebugUpdate = update } + +//go:linkname godebug_setNewIncNonDefault internal/godebug.setNewIncNonDefault +func godebug_setNewIncNonDefault(newIncNonDefault func(string) func()) { + // Dummy function necessary in Go 1.21. +} + +// Write to the given file descriptor. +// This is called from internal/godebug starting with Go 1.21, and only seems to +// be called with the stderr file descriptor. +func write(fd uintptr, p unsafe.Pointer, n int32) int32 { + if fd == 2 { // stderr + // Convert to a string, because we know that p won't change during the + // call to printstring. + // TODO: use unsafe.String instead once we require Go 1.20. + s := _string{ + ptr: (*byte)(p), + length: uintptr(n), + } + str := *(*string)(unsafe.Pointer(&s)) + printstring(str) + return n + } + return 0 +} diff --git a/src/runtime/runtime_nintendoswitch.go b/src/runtime/runtime_nintendoswitch.go index f2606023f..bcfa5151d 100644 --- a/src/runtime/runtime_nintendoswitch.go +++ b/src/runtime/runtime_nintendoswitch.go @@ -105,7 +105,7 @@ func abort() { } //export write -func write(fd int32, buf *byte, count int) int { +func libc_write(fd int32, buf *byte, count int) int { // TODO: Proper handling write for i := 0; i < count; i++ { putchar(*buf) diff --git a/src/runtime/runtime_wasm_js.go b/src/runtime/runtime_wasm_js.go index c735c76fc..443ed9e2e 100644 --- a/src/runtime/runtime_wasm_js.go +++ b/src/runtime/runtime_wasm_js.go @@ -44,8 +44,8 @@ func nanosecondsToTicks(ns int64) timeUnit { // This function is called by the scheduler. // Schedule a call to runtime.scheduler, do not actually sleep. // -//export runtime.sleepTicks +//go:wasmimport gojs runtime.sleepTicks func sleepTicks(d timeUnit) -//export runtime.ticks +//go:wasmimport gojs runtime.ticks func ticks() timeUnit diff --git a/src/runtime/symtab.go b/src/runtime/symtab.go index cfc9885d7..37c21ee89 100644 --- a/src/runtime/symtab.go +++ b/src/runtime/symtab.go @@ -5,11 +5,14 @@ type Frames struct { } type Frame struct { + PC uintptr + + Func *Func + Function string File string Line int - PC uintptr } func CallersFrames(callers []uintptr) *Frames { diff --git a/src/syscall/syscall_libc_darwin.go b/src/syscall/syscall_libc_darwin.go index 704ba29ca..d64f1061f 100644 --- a/src/syscall/syscall_libc_darwin.go +++ b/src/syscall/syscall_libc_darwin.go @@ -68,6 +68,7 @@ const ( EISDIR Errno = 21 EINVAL Errno = 22 EMFILE Errno = 24 + EROFS Errno = 30 EPIPE Errno = 32 EAGAIN Errno = 35 ENOTCONN Errno = 57 |