mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-03 02:27:48 +00:00
wasm: call __stdio_exit on exit
This flushes stdio, so that functions like puts and printf write out all buffered data even if the output isn't connected to a terminal. For discussion, see: https://github.com/bytecodealliance/wasmtime/issues/7833
This commit is contained in:
committed by
Ron Evans
parent
55f7d21ff5
commit
3021e16bbf
@@ -21,6 +21,11 @@ func fd_write(id uint32, iovs *__wasi_iovec_t, iovs_len uint, nwritten *uint) (e
|
||||
//go:wasmimport wasi_snapshot_preview1 proc_exit
|
||||
func proc_exit(exitcode uint32)
|
||||
|
||||
// Flush stdio on exit.
|
||||
//
|
||||
//export __stdio_exit
|
||||
func __stdio_exit()
|
||||
|
||||
const (
|
||||
putcharBufferSize = 120
|
||||
stdout = 1
|
||||
@@ -72,6 +77,9 @@ func abort() {
|
||||
|
||||
//go:linkname syscall_Exit syscall.Exit
|
||||
func syscall_Exit(code int) {
|
||||
// TODO: should we call __stdio_exit here?
|
||||
// It's a low-level exit (syscall.Exit) so doing any libc stuff seems
|
||||
// unexpected, but then where else should stdio buffers be flushed?
|
||||
proc_exit(uint32(code))
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ func _start() {
|
||||
heapStart = uintptr(unsafe.Pointer(&heapStartSymbol))
|
||||
heapEnd = uintptr(wasm_memory_size(0) * wasmPageSize)
|
||||
run()
|
||||
__stdio_exit()
|
||||
}
|
||||
|
||||
// Read the command line arguments from WASI.
|
||||
|
||||
@@ -18,6 +18,7 @@ func _start() {
|
||||
|
||||
wasmNested = true
|
||||
run()
|
||||
__stdio_exit()
|
||||
wasmNested = false
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user