Browse Source

* PS1: clamp the stack size, so it doesn't exceed the maximum memory available (minus 1k for heap)

Nikolay Nikolov 10 months ago
parent
commit
94e399faf7
1 changed files with 9 additions and 1 deletions
  1. 9 1
      rtl/ps1/system.pp

+ 9 - 1
rtl/ps1/system.pp

@@ -109,8 +109,16 @@ begin
 end;
 
 function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
+const
+  MinHeap = 1024;  // always leave at least 1k heap
+var
+  MaxStack: SizeInt;
 begin
-  result:= stklen;
+  MaxStack:=SizeInt(PtrUInt($80200000)-PtrUInt(@bss_end))-MinHeap;
+  if stklen<MaxStack then
+    result:= stklen
+  else
+    result:=MaxStack;
 end;
 
 procedure system_exit;