+ added error handling to the do_read and do_Write WASI routines

git-svn-id: branches/wasm@48310 -
This commit is contained in:
nickysn 2021-01-22 02:06:30 +00:00
parent 85ea2b9b11
commit e14451c6b6
2 changed files with 66 additions and 22 deletions

View File

@ -37,22 +37,46 @@ function Do_Write(Handle:thandle;Addr:Pointer;Len:Longint):longint;
var
our_iov: __wasi_ciovec_t;
our_nwritten: longint;
res: __wasi_errno_t;
begin
our_iov.buf := Addr;
our_iov.buf_len := Len;
fd_write(Handle, @our_iov, 1, @our_nwritten);
Do_Write:=our_nwritten;
repeat
our_iov.buf := Addr;
our_iov.buf_len := Len;
res:=fd_write(Handle, @our_iov, 1, @our_nwritten);
until (res=__WASI_ERRNO_SUCCESS) or ((res<>__WASI_ERRNO_INTR) and (res<>__WASI_ERRNO_AGAIN));
if res=__WASI_ERRNO_SUCCESS then
begin
Do_Write:=our_nwritten;
InOutRes:=0;
end
else
begin
Do_Write:=0;
InOutRes:=Errno2InoutRes(res);
end;
end;
function Do_Read(Handle:thandle;Addr:Pointer;Len:Longint):Longint;
var
our_iov: __wasi_iovec_t;
our_nread: __wasi_size_t;
res: __wasi_errno_t;
begin
our_iov.buf:=Addr;
our_iov.buf_len:=Len;
fd_read(Handle,@our_iov,1,@our_nread);
Do_Read:=our_nread;
repeat
our_iov.buf:=Addr;
our_iov.buf_len:=Len;
fd_read(Handle,@our_iov,1,@our_nread);
until (res=__WASI_ERRNO_SUCCESS) or ((res<>__WASI_ERRNO_INTR) and (res<>__WASI_ERRNO_AGAIN));
if res=__WASI_ERRNO_SUCCESS then
begin
Do_Read:=our_nread;
InOutRes:=0;
end
else
begin
Do_Read:=0;
InOutRes:=Errno2InoutRes(res);
end;
end;
function Do_FilePos(Handle: thandle):Int64;

View File

@ -15,22 +15,42 @@
**********************************************************************}
{procedure GetInOutRes(def: Word);
var
regs : Registers;
function Errno2InoutRes(errno: __wasi_errno_t): Word;
begin
regs.AX:=$5900;
regs.BX:=$0;
MsDos(regs);
InOutRes:=regs.AX;
case InOutRes of
19 : InOutRes:=150;
21 : InOutRes:=152;
32 : InOutRes:=5;
case errno of
__WASI_ERRNO_NFILE,
__WASI_ERRNO_MFILE:
Errno2InoutRes:=4;
__WASI_ERRNO_NOENT:
Errno2InoutRes:=2;
__WASI_ERRNO_BADF:
Errno2InoutRes:=6;
__WASI_ERRNO_NOMEM,
__WASI_ERRNO_FAULT:
Errno2InoutRes:=217;
__WASI_ERRNO_INVAL:
Errno2InoutRes:=218;
__WASI_ERRNO_PIPE,
__WASI_ERRNO_INTR,
__WASI_ERRNO_IO,
__WASI_ERRNO_AGAIN,
__WASI_ERRNO_NOSPC:
Errno2InoutRes:=101;
__WASI_ERRNO_NAMETOOLONG:
Errno2InoutRes:=3;
__WASI_ERRNO_ROFS,
__WASI_ERRNO_EXIST,
__WASI_ERRNO_NOTEMPTY,
__WASI_ERRNO_ACCES:
Errno2InoutRes:=5;
__WASI_ERRNO_BUSY,
__WASI_ERRNO_NOTDIR, // busy, enotdir, mantis #25931
__WASI_ERRNO_ISDIR:
Errno2InoutRes:=5;
else
Errno2InoutRes:=errno;
end;
if InOutRes=0 then
InOutRes:=Def;
end;}
end;
{*****************************************************************************
Low Level File Routines