* set stack margin on windows, so there is stack space left for exception handling in case of a stack overflow, resolves #40589

This commit is contained in:
florian 2024-01-24 21:31:03 +01:00
parent c4fc5fc916
commit 14ab1cfb71
5 changed files with 31 additions and 1 deletions

View File

@ -273,6 +273,8 @@ type
function GetModuleHandle(p : PAnsiChar) : THandle;
stdcall;external KernelDLL name 'GetModuleHandleA';
function SetThreadStackGuarantee(StackSizeInBytes : PPtrUint) : BOOL;
stdcall;external KernelDLL name 'SetThreadStackGuarantee';
{$else WINCE}
{ module functions }

View File

@ -227,7 +227,10 @@ var
- static threadvars, no callback: ThreadID remains 0 and
initialization happens here. }
if ThreadID=TThreadID(0) then
InitThread(ti.stklen);
begin
InitThread(ti.stklen);
SetThreadStackGuarantee(@StackMargin);
end;
dispose(pthreadinfo(param));

View File

@ -619,6 +619,7 @@ initialization
{ pass dummy value }
StackLength := CheckInitialStkLen($1000000);
StackBottom := StackTop - StackLength;
SetThreadStackGuarantee(@StackMargin);
cmdshow:=startupinfo.wshowwindow;
{ Setup heap and threading, these may be already initialized from TLS callback }

View File

@ -478,6 +478,8 @@ initialization
{ pass dummy value }
StackLength := CheckInitialStkLen($1000000);
StackBottom := StackTop - StackLength;
SetThreadStackGuarantee(@StackMargin);
{ get some helpful informations }
GetStartupInfo(@startupinfo);
{ some misc Win32 stuff }

22
tests/webtbs/tw40589.pp Normal file
View File

@ -0,0 +1,22 @@
{ %RESULT=202 }
{ %opt=gl }
{$mode objfpc}
type
TForm1 = class
procedure Button1Click(Sender: TObject);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Button1Click(self);
end;
var
Form1 : TForm1;
begin
Form1:=TForm1.Create;
Form1.Button1Click(nil);
end.