From d45915b6ba0f99a70c51243377471bd834a5f541 Mon Sep 17 00:00:00 2001 From: Nikolay Nikolov Date: Wed, 6 Oct 2021 07:44:04 +0300 Subject: [PATCH] * preopened dirs structure in the system unit modified to be a pointer to an array of records --- rtl/wasi/system.pp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/rtl/wasi/system.pp b/rtl/wasi/system.pp index c8b1b7be32..e69ea10311 100644 --- a/rtl/wasi/system.pp +++ b/rtl/wasi/system.pp @@ -48,12 +48,19 @@ const sLineBreak = LineEnding; DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsLF; +type + PPreopenedDir = ^TPreopenedDir; + TPreopenedDir = record + dir_name: PChar; + fd: longint; + end; + var argc: longint; argv: PPChar; envp: PPChar; preopened_dirs_count: longint; - preopened_dirs: PPChar; + preopened_dirs: PPreopenedDir; drives_count: longint; current_dirs: PPChar; current_dir_fds: Plongint; @@ -128,7 +135,7 @@ begin for I:=0 to preopened_dirs_count-1 do begin path:=savepath; - pdir:=preopened_dirs[I]; + pdir:=preopened_dirs[I].dir_name; if HasDriveLetter(pdir) then begin pdir_drive:=Ord(UpCase(pdir[0]))-(Ord('A')-1); @@ -151,7 +158,7 @@ begin longest_match:=pdir_length; while path^ in ['/','\'] do Inc(path); - fd:=I+3; + fd:=preopened_dirs[I].fd; FreeMem(relfd_path); relfd_path:=GetMem(StrLen(path)+1); Move(path^,relfd_path^,StrLen(path)+1); @@ -203,10 +210,11 @@ begin prestat_dir_name[prestat.u.dir.pr_name_len]:=#0; Inc(preopened_dirs_count); if preopened_dirs=nil then - preopened_dirs:=AllocMem(preopened_dirs_count*SizeOf(PChar)) + preopened_dirs:=AllocMem(preopened_dirs_count*SizeOf(TPreopenedDir)) else - ReAllocMem(preopened_dirs, preopened_dirs_count*SizeOf(PChar)); - preopened_dirs[preopened_dirs_count-1]:=prestat_dir_name; + ReAllocMem(preopened_dirs, preopened_dirs_count*SizeOf(TPreopenedDir)); + preopened_dirs[preopened_dirs_count-1].dir_name:=prestat_dir_name; + preopened_dirs[preopened_dirs_count-1].fd:=fd; if HasDriveLetter(prestat_dir_name) then drive_nr:=Ord(UpCase(prestat_dir_name[0]))-(Ord('A')-1) else