+ 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 var
our_iov: __wasi_ciovec_t; our_iov: __wasi_ciovec_t;
our_nwritten: longint; our_nwritten: longint;
res: __wasi_errno_t;
begin begin
our_iov.buf := Addr; repeat
our_iov.buf_len := Len; our_iov.buf := Addr;
fd_write(Handle, @our_iov, 1, @our_nwritten); our_iov.buf_len := Len;
Do_Write:=our_nwritten; 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; end;
function Do_Read(Handle:thandle;Addr:Pointer;Len:Longint):Longint; function Do_Read(Handle:thandle;Addr:Pointer;Len:Longint):Longint;
var var
our_iov: __wasi_iovec_t; our_iov: __wasi_iovec_t;
our_nread: __wasi_size_t; our_nread: __wasi_size_t;
res: __wasi_errno_t;
begin begin
our_iov.buf:=Addr; repeat
our_iov.buf_len:=Len; our_iov.buf:=Addr;
fd_read(Handle,@our_iov,1,@our_nread); our_iov.buf_len:=Len;
Do_Read:=our_nread; 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; end;
function Do_FilePos(Handle: thandle):Int64; function Do_FilePos(Handle: thandle):Int64;

View File

@ -15,22 +15,42 @@
**********************************************************************} **********************************************************************}
{procedure GetInOutRes(def: Word); function Errno2InoutRes(errno: __wasi_errno_t): Word;
var
regs : Registers;
begin begin
regs.AX:=$5900; case errno of
regs.BX:=$0; __WASI_ERRNO_NFILE,
MsDos(regs); __WASI_ERRNO_MFILE:
InOutRes:=regs.AX; Errno2InoutRes:=4;
case InOutRes of __WASI_ERRNO_NOENT:
19 : InOutRes:=150; Errno2InoutRes:=2;
21 : InOutRes:=152; __WASI_ERRNO_BADF:
32 : InOutRes:=5; 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; end;
if InOutRes=0 then end;
InOutRes:=Def;
end;}
{***************************************************************************** {*****************************************************************************
Low Level File Routines Low Level File Routines