Support Windows XP where SetThreadStackGuarantee is absent.

This commit is contained in:
Rika Ichinose 2024-01-26 16:57:49 +03:00
parent a2f2af87d2
commit a774075f2f
4 changed files with 12 additions and 7 deletions

View File

@ -273,8 +273,8 @@ type
function GetModuleHandle(p : PAnsiChar) : THandle;
stdcall;external KernelDLL name 'GetModuleHandleA';
function SetThreadStackGuarantee(StackSizeInBytes : PPtrUint) : BOOL;
stdcall;external KernelDLL name 'SetThreadStackGuarantee';
var
SetThreadStackGuarantee: function(StackSizeInBytes : PPtrUint) : BOOL; stdcall;
{$else WINCE}
{ module functions }
@ -304,7 +304,7 @@ type
procedure GetSystemInfo(lpSystemInfo: PSystemInfo); {$ifdef wince}cdecl{$else}stdcall{$endif};external KernelDLL name 'GetSystemInfo';
function WinLoadLibraryW(lpLibFileName:pwidechar):THandle; {$ifdef wince}cdecl{$else}stdcall{$endif}; external KernelDLL name 'LoadLibraryW';
function WinLoadLibraryA(lpLibFileName:pwidechar):THandle; {$ifdef wince}cdecl{$else}stdcall{$endif}; external KernelDLL name 'LoadLibraryA';
function WinGetModuleHandleW(lpModuleName:pwidechar):THandle; {$ifdef wince}cdecl{$else}stdcall{$endif}; external KernelDLL name 'GetModuleHandleW';
{$ifdef wince}
function WinGetProcAddress(hModule:THandle; lpProcName:PAnsiChar):pointer; {$ifdef wince}cdecl{$else}stdcall{$endif}; external KernelDLL name 'GetProcAddressA';
{$else}

View File

@ -229,8 +229,9 @@ var
if ThreadID=TThreadID(0) then
begin
InitThread(ti.stklen);
{$ifndef wince}
SetThreadStackGuarantee(@StackMargin);
{$ifndef wince}
if Assigned(SetThreadStackGuarantee) then
SetThreadStackGuarantee(@StackMargin);
{$endif wince}
end;

View File

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

View File

@ -478,7 +478,9 @@ initialization
{ pass dummy value }
StackLength := CheckInitialStkLen($1000000);
StackBottom := StackTop - StackLength;
SetThreadStackGuarantee(@StackMargin);
CodePointer(SetThreadStackGuarantee) := WinGetProcAddress(WinGetModuleHandleW(KernelDLL), 'SetThreadStackGuarantee');
if Assigned(SetThreadStackGuarantee) then
SetThreadStackGuarantee(@StackMargin);
{ get some helpful informations }
GetStartupInfo(@startupinfo);