From 720068360ea09dac6fcd35dd47e763baa5805c6b Mon Sep 17 00:00:00 2001 From: nickysn Date: Wed, 23 Jun 2021 21:22:15 +0000 Subject: [PATCH] + workaround for newer wasmtime versions that don't report the fd type of stdin/stdout/stderr. Always assume handles 0..2 are a device, so that standard input and output are flushed. git-svn-id: trunk@49541 - --- rtl/wasi/sysos.inc | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/rtl/wasi/sysos.inc b/rtl/wasi/sysos.inc index cfe69c0944..a8f8bae103 100644 --- a/rtl/wasi/sysos.inc +++ b/rtl/wasi/sysos.inc @@ -58,8 +58,19 @@ end; function Do_IsDevice(Handle:THandle):boolean; var + res: __wasi_errno_t; ourfdstat: __wasi_fdstat_t; begin - __wasi_fd_fdstat_get(Handle,@ourfdstat); - Do_IsDevice:=ourfdstat.fs_filetype in [__WASI_FILETYPE_BLOCK_DEVICE,__WASI_FILETYPE_CHARACTER_DEVICE]; + res:=__wasi_fd_fdstat_get(Handle,@ourfdstat); + if res=__WASI_ERRNO_SUCCESS then + begin + if ourfdstat.fs_filetype=__WASI_FILETYPE_UNKNOWN then + { wasmtime 0.24.0 and later versions return __WASI_FILETYPE_UNKNOWN for stdin/stdout/stderr } + Do_IsDevice:=Handle<=2 + else + Do_IsDevice:=ourfdstat.fs_filetype in [__WASI_FILETYPE_BLOCK_DEVICE,__WASI_FILETYPE_CHARACTER_DEVICE] + end + else + { in case of error (e.g. access denied), assume device for stdin/stdout/stderr } + Do_IsDevice:=Handle<=2; end;