rtl: make STACK_MARGIN a variable instead of a const. this allows adjusting margin size on system unit init, based on the actual stack length of the executable. useful for small systems running with little stack. allow overwriting SysBackTraceStr with a platform-specific implementation

git-svn-id: trunk@49200 -
This commit is contained in:
Károly Balogh 2021-04-14 02:35:01 +00:00
parent 695665c393
commit 7b9ed5fe46

View File

@ -45,12 +45,13 @@ type
const const
{$if defined(CPUAVR)} {$if defined(CPUAVR)}
STACK_MARGIN = 64; { Stack size margin for stack checking } STACK_MARGIN_MAX = 64; { Stack size margin for stack checking }
{$elseif defined(CPUZ80)} {$elseif defined(CPUZ80)}
STACK_MARGIN = 64; { Stack size margin for stack checking } STACK_MARGIN_MAX = 64; { Stack size margin for stack checking }
{$else} {$else}
STACK_MARGIN = 16384; { Stack size margin for stack checking } STACK_MARGIN_MAX = 16384; { Stack size margin for stack checking }
{$endif} {$endif}
StackMargin: ptruint = STACK_MARGIN_MAX;
{ Random / Randomize constants } { Random / Randomize constants }
OldRandSeed : Cardinal = 0; OldRandSeed : Cardinal = 0;
@ -1042,7 +1043,7 @@ begin
{ don't use stack_size, since the stack pointer has already been { don't use stack_size, since the stack pointer has already been
decreased when this routine is called decreased when this routine is called
} }
c := Sptr - STACK_MARGIN; c := Sptr - StackMargin;
if (c <= StackBottom) then if (c <= StackBottom) then
begin begin
StackError:=true; StackError:=true;
@ -1289,10 +1290,12 @@ Begin
end; end;
{$ifndef FPC_SYSTEM_HAS_BACKTRACESTR}
function SysBackTraceStr (Addr: CodePointer): ShortString; function SysBackTraceStr (Addr: CodePointer): ShortString;
begin begin
SysBackTraceStr:=' $'+hexstr(addr); SysBackTraceStr:=' $'+hexstr(addr);
end; end;
{$endif FPC_SYSTEM_HAS_BACKTRACESTR}
{$ifndef FPC_SYSTEM_HAS_CAPTUREBACKTRACE} {$ifndef FPC_SYSTEM_HAS_CAPTUREBACKTRACE}