* added CheckInitialStkLen() function which checks whether the given stack size value is valid on the OS when creating a thread, fixing stack checking

git-svn-id: trunk@1722 -
This commit is contained in:
tom_at_work 2005-11-11 12:16:08 +00:00
parent d30db6fced
commit 1b4b42fdd6
20 changed files with 141 additions and 15 deletions

View File

@ -519,6 +519,11 @@ begin
OpenStdIO(StdErr,fmOutput,StdErrorHandle); OpenStdIO(StdErr,fmOutput,StdErrorHandle);
end; end;
function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
begin
result := stklen;
end;
begin begin
{ Setup heap } { Setup heap }
zero:=0; zero:=0;

View File

@ -242,11 +242,15 @@ begin
GetProcessID := SizeUInt (fpGetPID); GetProcessID := SizeUInt (fpGetPID);
end; end;
function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
begin
result := stklen;
end;
Begin Begin
IsConsole := TRUE; IsConsole := TRUE;
IsLibrary := FALSE; IsLibrary := FALSE;
StackLength := InitialStkLen; StackLength := CheckInitialStkLen(InitialStkLen);
StackBottom := Sptr - StackLength; StackBottom := Sptr - StackLength;
{ Set up signals handlers } { Set up signals handlers }
InstallSignals; InstallSignals;

View File

@ -245,11 +245,15 @@ begin
GetProcessID := SizeUInt (fpGetPID); GetProcessID := SizeUInt (fpGetPID);
end; end;
function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
begin
result := stklen;
end;
Begin Begin
///-F-/// IsConsole := TRUE; ///-F-/// IsConsole := TRUE;
///-F-/// IsLibrary := FALSE; ///-F-/// IsLibrary := FALSE;
StackLength := InitialStkLen; StackLength := CheckInitialStkLen(InitialStkLen);
StackBottom := Sptr - StackLength; StackBottom := Sptr - StackLength;
{ Set up signals handlers } { Set up signals handlers }
InstallSignals; InstallSignals;

View File

@ -610,10 +610,15 @@ begin
GetProcessID := SizeUInt (Go32_info_block.pid); GetProcessID := SizeUInt (Go32_info_block.pid);
end; end;
function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
begin
result := stklen;
end;
var var
temp_int : tseginfo; temp_int : tseginfo;
Begin Begin
StackLength := InitialStkLen; StackLength := CheckInitialStkLen(InitialStkLen);
StackBottom := __stkbottom; StackBottom := __stkbottom;
{ To be set if this is a GUI or console application } { To be set if this is a GUI or console application }
IsConsole := TRUE; IsConsole := TRUE;

View File

@ -45,7 +45,17 @@ var
emptychar : char;public name 'FPC_EMPTYCHAR'; emptychar : char;public name 'FPC_EMPTYCHAR';
initialstklen : SizeUint;external name '__stklen'; initialstklen : SizeUint;external name '__stklen';
{ checks whether the given suggested size for the stack of the current
thread is acceptable. If this is the case, returns it unaltered.
Otherwise it should return an acceptable value.
Operating systems that automatically expand their stack on demand, should
simply return a very large value.
Operating systems which do not have a possibility to retrieve stack size
information, should simply return the given stklen value (This is the default
implementation).
}
function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt; forward;
{**************************************************************************** {****************************************************************************
Include processor specific routines Include processor specific routines

View File

@ -32,7 +32,7 @@ Var
InOutRes:=0; InOutRes:=0;
// ErrNo:=0; // ErrNo:=0;
{ Stack checking } { Stack checking }
StackLength:=stklen; StackLength:= CheckInitialStkLen(stkLen);
StackBottom:=Sptr - StackLength; StackBottom:=Sptr - StackLength;
ThreadID := CurrentTM.GetCurrentThreadID(); ThreadID := CurrentTM.GetCurrentThreadID();
end; end;

View File

@ -33,4 +33,6 @@
{$endif} {$endif}
{$endif} {$endif}
{$if defined(cpupowerpc) or defined(cpupowerpc64) or defined(cpux86)}
{$DEFINE has_ugetrlimit}
{$endif}

View File

@ -458,7 +458,6 @@ begin
FPsigprocmask:=do_syscall(syscall_nr_rt_sigprocmask,TSysParam(how),TSysParam(nset),TSysParam(oset),TSysParam(8)); FPsigprocmask:=do_syscall(syscall_nr_rt_sigprocmask,TSysParam(how),TSysParam(nset),TSysParam(oset),TSysParam(8));
end; end;
Function FpNanoSleep(req : ptimespec;rem : ptimespec):cint; [public, alias : 'FPC_SYSC_NANOSLEEP']; Function FpNanoSleep(req : ptimespec;rem : ptimespec):cint; [public, alias : 'FPC_SYSC_NANOSLEEP'];
begin begin
FpNanoSleep:=Do_SysCall(syscall_nr_nanosleep,TSysParam(req),TSysParam(rem)); FpNanoSleep:=Do_SysCall(syscall_nr_nanosleep,TSysParam(req),TSysParam(rem));
@ -473,3 +472,18 @@ begin
fpgettimeofday:=do_syscall(syscall_nr_gettimeofday,TSysParam(tp),TSysParam(tzp)); fpgettimeofday:=do_syscall(syscall_nr_gettimeofday,TSysParam(tp),TSysParam(tzp));
end; end;
function FpGetRLimit(resource : cInt; rlim : PRLimit) : cInt;
begin
FpGetRLimit := do_syscall(syscall_nr_getrlimit,
TSysParam(resource), TSysParam(@rlim));
end;
{$ifdef HAS_UGETRLIMIT}
function fpugetrlimit(resource : cInt; rlim : PRLimit) : cInt;
begin
FpUGetRLimit := do_syscall(syscall_nr_ugetrlimit,
syscall_nr_getrlimit,
TSysParam(resource), TSysParam(@rlim));
end;
{$endif}

View File

@ -309,6 +309,28 @@ CONST
F_SetOwn = 8; F_SetOwn = 8;
F_GetOwn = 9; F_GetOwn = 9;
{ getrlimit/ugetrlimit resource parameter constants }
const
RLIMIT_CPU = 0; { CPU time in ms }
RLIMIT_FSIZE = 1; { Maximum filesize }
RLIMIT_DATA = 2; { max data size }
RLIMIT_STACK = 3; { max stack size }
RLIMIT_CORE = 4; { max core file size }
RLIMIT_RSS = 5; { max resident set size }
RLIMIT_NPROC = 6; { max number of processes }
RLIMIT_NOFILE = 7; { max number of open files }
RLIMIT_MEMLOCK = 8; { max locked-in-memory address space }
RLIMIT_AS = 9; { address space limit(?) }
RLIMIT_LOCKS = 10; { maximum file locks held }
type
rlim_t = cULong;
PRLimit = ^TRLimit;
TRLimit = record
rlim_cur : rlim_t;
rlim_max : rlim_t;
end;
{*************************************************************************} {*************************************************************************}
{ SIGNALS } { SIGNALS }
{*************************************************************************} {*************************************************************************}

View File

@ -231,12 +231,29 @@ begin
GetProcessID := SizeUInt (fpGetPID); GetProcessID := SizeUInt (fpGetPID);
end; end;
function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
var
limits : TRLimit;
success : boolean;
begin
success := false;
fillchar(limits, sizeof(limits), 0);
{$ifdef has_ugetrlimit}
success := fpugetrlimit(RLIMIT_STACK, @limits)=0;
{$endif}
if (not success) then
success := fpgetrlimit(RLIMIT_STACK, @limits)=0;
if (success) and (limits.rlim_cur < stklen) then
result := limits.rlim_cur
else
result := stklen;
end;
Begin Begin
SysResetFPU; SysResetFPU;
IsConsole := TRUE; IsConsole := TRUE;
IsLibrary := FALSE; IsLibrary := FALSE;
StackLength := InitialStkLen; StackLength := CheckInitialStkLen(initialStkLen);
StackBottom := Sptr - StackLength; StackBottom := Sptr - StackLength;
{ Set up signals handlers } { Set up signals handlers }
InstallSignals; InstallSignals;

View File

@ -476,6 +476,11 @@ begin
{$WARNING To be implemented - using GetProcessInformation???} {$WARNING To be implemented - using GetProcessInformation???}
end; end;
function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
begin
result := stklen;
end;
var var
resHdl: Mac_Handle; resHdl: Mac_Handle;
isFolder, hadAlias, leafIsAlias: Boolean; isFolder, hadAlias, leafIsAlias: Boolean;
@ -509,7 +514,7 @@ begin
{ To be set if this is a library and not a program } { To be set if this is a library and not a program }
IsLibrary := FALSE; IsLibrary := FALSE;
StackLength := InitialStkLen; StackLength := CheckInitialStkLen(InitialStkLen);
StackBottom := SPtr - StackLength; StackBottom := SPtr - StackLength;
pathTranslation:= false; pathTranslation:= false;

View File

@ -301,12 +301,17 @@ begin
GetProcessID:=SizeUInt(FindTask(NIL)); GetProcessID:=SizeUInt(FindTask(NIL));
end; end;
function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
begin
result := stklen;
end;
begin begin
SysResetFPU; SysResetFPU;
IsConsole := TRUE; IsConsole := TRUE;
IsLibrary := FALSE; IsLibrary := FALSE;
StackLength := InitialStkLen; StackLength := CheckInitialStkLen(InitialStkLen);
StackBottom := Sptr - StackLength; StackBottom := Sptr - StackLength;
{ OS specific startup } { OS specific startup }
MOS_ambMsg:=nil; MOS_ambMsg:=nil;

View File

@ -509,7 +509,10 @@ begin
end; end;
function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
begin
result := stklen;
end;
{***************************************************************************** {*****************************************************************************
SystemUnit Initialization SystemUnit Initialization
*****************************************************************************} *****************************************************************************}

View File

@ -104,6 +104,11 @@ begin
GetProcessID := 1; GetProcessID := 1;
end; end;
function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
begin
result := stklen;
end;
begin begin
ExitCode:=0; ExitCode:=0;
end. end.

View File

@ -206,11 +206,15 @@ begin
GetProcessID := SizeUInt (fpGetPID); GetProcessID := SizeUInt (fpGetPID);
end; end;
function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
begin
result := stklen;
end;
Begin Begin
IsConsole := TRUE; IsConsole := TRUE;
IsLibrary := FALSE; IsLibrary := FALSE;
StackLength := InitialStkLen; StackLength := CheckInitialStkLen(InitialStkLen);
StackBottom := Sptr - StackLength; StackBottom := Sptr - StackLength;
{ Set up signals handlers } { Set up signals handlers }
InstallSignals; InstallSignals;

View File

@ -86,6 +86,10 @@ Type TGrpArr = Array [0..0] of TGid; { C style array workarounds}
Function fpReadLink (name,linkname:pchar;maxlen:size_t):cint; cdecl; external clib name 'readlink'; Function fpReadLink (name,linkname:pchar;maxlen:size_t):cint; cdecl; external clib name 'readlink';
Function FpUmask (cmask : TMode): TMode; cdecl; external clib name 'umask'; Function FpUmask (cmask : TMode): TMode; cdecl; external clib name 'umask';
function fpsettimeofday(tp:ptimeval;tzp:ptimezone):cint; cdecl; external clib name 'settimeofday'; function fpsettimeofday(tp:ptimeval;tzp:ptimezone):cint; cdecl; external clib name 'settimeofday';
function FpGetRLimit(resource : cInt; rlim : PRLimit) : cInt; cdecl; external clib name 'getrlimit';
{$ifdef HAS_UGETRLIMIT}
function FpGetRLimit(resource : cInt; rlim : PRLimit) : cInt; cdecl; external clib name 'ugetrlimit';
{$endif}
{$ifdef linux} {$ifdef linux}
{$ifndef FPC_IS_SYSTEM} {$ifndef FPC_IS_SYSTEM}

View File

@ -1489,6 +1489,10 @@ begin
GetProcessID := 1; GetProcessID := 1;
end; end;
function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
begin
result := stklen;
end;
var var
temp_int : tseginfo; temp_int : tseginfo;

View File

@ -1118,13 +1118,17 @@ begin
GetProcessID := ProcessID; GetProcessID := ProcessID;
end; end;
function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
begin
result := stklen;
end;
const const
Exe_entry_code : pointer = @Exe_entry; Exe_entry_code : pointer = @Exe_entry;
Dll_entry_code : pointer = @Dll_entry; Dll_entry_code : pointer = @Dll_entry;
begin begin
StackLength := InitialStkLen; StackLength := CheckInitialStkLen(InitialStkLen);
StackBottom := Sptr - StackLength; StackBottom := Sptr - StackLength;
{ get some helpful informations } { get some helpful informations }
GetStartupInfo(@startupinfo); GetStartupInfo(@startupinfo);

View File

@ -1067,13 +1067,17 @@ begin
GetProcessID := ProcessID; GetProcessID := ProcessID;
end; end;
function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
begin
result := stklen;
end;
const const
Exe_entry_code : pointer = @Exe_entry; Exe_entry_code : pointer = @Exe_entry;
Dll_entry_code : pointer = @Dll_entry; Dll_entry_code : pointer = @Dll_entry;
begin begin
StackLength := InitialStkLen; StackLength := CheckInitialStkLen(InitialStkLen);
StackBottom := Sptr - StackLength; StackBottom := Sptr - StackLength;
{ get some helpful informations } { get some helpful informations }
GetStartupInfo(@startupinfo); GetStartupInfo(@startupinfo);

View File

@ -1635,12 +1635,17 @@ begin
GetProcessID := ProcessID; GetProcessID := ProcessID;
end; end;
function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
begin
result := stklen;
end;
const const
Exe_entry_code : pointer = @Exe_entry; Exe_entry_code : pointer = @Exe_entry;
Dll_entry_code : pointer = @Dll_entry; Dll_entry_code : pointer = @Dll_entry;
begin begin
StackLength := InitialStkLen; StackLength := CheckInitialStkLen(InitialStkLen);
StackBottom := Sptr - StackLength; StackBottom := Sptr - StackLength;
{ Enable FPU exceptions } { Enable FPU exceptions }
_controlfp(1, $0008001F); _controlfp(1, $0008001F);