Bläddra i källkod

* WebAssembly threads: use the stack size, specified for the main thread (via
the $M directive, or the '-Cs' compiler option) as the default stack size for
other spawned threads

Nikolay Nikolov 1 år sedan
förälder
incheckning
3c027b0ba0
3 ändrade filer med 5 tillägg och 3 borttagningar
  1. 1 1
      compiler/systems/i_wasi.pas
  2. 3 0
      rtl/wasi/system.pp
  3. 1 2
      rtl/wasi/systhrd.inc

+ 1 - 1
compiler/systems/i_wasi.pas

@@ -35,7 +35,7 @@ unit i_wasi;
             name         : 'The WebAssembly System Interface (WASI)';
             shortname    : 'Wasi';
             flags        : [tf_under_development,tf_needs_symbol_size,tf_needs_symbol_type,
-                            tf_files_case_sensitive,tf_no_generic_stackcheck,
+                            tf_files_case_sensitive,tf_no_generic_stackcheck,tf_emit_stklen,
                             tf_smartlink_sections,tf_has_winlike_resources,
                             { avoid the creation of threadvar tables }
                             tf_section_threadvars];

+ 3 - 0
rtl/wasi/system.pp

@@ -73,6 +73,9 @@ Procedure DebugWriteln(aString : ShortString);
 
 implementation
 
+var
+  StkLen: SizeUInt; external name '__stklen';
+
 {$I wasitypes.inc}
 {$I wasiprocs.inc}
 

+ 1 - 2
rtl/wasi/systhrd.inc

@@ -361,7 +361,6 @@ Function wasi_thread_spawn(start_arg: PWasmThread) : LongInt; external 'wasi' na
 function WasiBeginThread(sa : Pointer;stacksize : PtrUInt; ThreadFunction : tthreadfunc;p : pointer;creationFlags : dword; var ThreadId : TThreadID) : TThreadID;
 
 Const
-  DefaultStackSize=1024*1024;
   HeapAlignment=16;
 Var
   T : PWasmThread;
@@ -374,7 +373,7 @@ begin
   T^.ThreadFunction:=ThreadFunction;
   T^.ThreadFunctionArg:=p;
   if stacksize<=0 then
-    stacksize:=DefaultStackSize;
+    stacksize:=StkLen;
   T^.StackBlock:=GetMem(stacksize);
   T^.InitialStackPointer:=Pointer(PtrUInt(PtrUInt(T^.StackBlock)+stacksize) and $FFFFFFF0);
   {$IFDEF DEBUGWASMTHREADS}DebugWriteln('WasiBeginThread: InitialStackPointer='+IntToStr(PtrUint(T^.InitialStackPointer)));{$ENDIF}