mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-11-02 13:19:34 +01:00
* Since StackTop=StackBottom+StackLength, any two variables are sufficient to describe stack, the third one is redundant.
* As a first part of cleanup, replaced StackTop with function returning StackBottom+StackLength. * On Win32 and Win64, StackTop returns the stack base from TIB instead. git-svn-id: trunk@27119 -
This commit is contained in:
parent
bca09a8f69
commit
3a55c4301e
@ -535,7 +535,7 @@ begin
|
||||
begin
|
||||
stackbottom:=pointer(heap_brk); {In DOS mode, heap_brk is
|
||||
also the stack bottom.}
|
||||
StackTop := StackBottom + InitialStkLen;
|
||||
StackLength:=sptr-stackbottom;
|
||||
{$WARNING To be checked/corrected!}
|
||||
ApplicationType := 1; (* Running under DOS. *)
|
||||
IsConsole := true;
|
||||
@ -549,8 +549,11 @@ begin
|
||||
osOS2:
|
||||
begin
|
||||
DosGetInfoBlocks (@TIB, @PIB);
|
||||
StackBottom := pointer (TIB^.Stack);
|
||||
StackTop := TIB^.StackLimit;
|
||||
StackLength:=CheckInitialStkLen(InitialStklen);
|
||||
{ TODO: verify if TIB^.StackLimit is correct,
|
||||
from MSWindows point of view TIB^.Stack should be used instead }
|
||||
StackBottom := TIB^.StackLimit - StackLength;
|
||||
|
||||
Environment := pointer (PIB^.Env);
|
||||
ApplicationType := PIB^.ProcType;
|
||||
ProcessID := PIB^.PID;
|
||||
@ -562,7 +565,7 @@ begin
|
||||
begin
|
||||
stackbottom:=nil; {Not sure how to get it, but seems to be
|
||||
always zero.}
|
||||
StackTop := StackBottom + InitialStkLen;
|
||||
StackLength:=sptr-stackbottom;
|
||||
{$WARNING To be checked/corrected!}
|
||||
ApplicationType := 1; (* Running under DOS. *)
|
||||
IsConsole := true;
|
||||
@ -570,7 +573,6 @@ begin
|
||||
end;
|
||||
end;
|
||||
exitproc:=nil;
|
||||
StackLength := CheckInitialStkLen (InitialStkLen);
|
||||
|
||||
{Initialize the heap.}
|
||||
initheap;
|
||||
|
||||
@ -177,7 +177,7 @@ end;
|
||||
|
||||
begin
|
||||
StackLength := CheckInitialStkLen(InitialStkLen);
|
||||
StackBottom := StackTop - StackLength;
|
||||
StackBottom := Sptr - StackLength;
|
||||
{ OS specific startup }
|
||||
|
||||
{ Setup heap }
|
||||
|
||||
@ -647,7 +647,6 @@ Begin
|
||||
and to ensure that StackLength = StackTop - StackBottom }
|
||||
StackLength := CheckInitialStkLen(InitialStkLen)-256;
|
||||
StackBottom := __stkbottom;
|
||||
StackTop := StackBottom + StackLength;
|
||||
{ To be set if this is a GUI or console application }
|
||||
IsConsole := TRUE;
|
||||
{ To be set if this is a library and not a program }
|
||||
|
||||
@ -682,6 +682,13 @@ End;
|
||||
Miscellaneous
|
||||
*****************************************************************************}
|
||||
|
||||
{$ifndef FPC_SYSTEM_HAS_STACKTOP}
|
||||
function StackTop: pointer;
|
||||
begin
|
||||
result:=StackBottom+StackLength;
|
||||
end;
|
||||
{$endif FPC_SYSTEM_HAS_STACKTOP}
|
||||
|
||||
{$ifndef FPC_SYSTEM_HAS_GET_PC_ADDR}
|
||||
{ This provides a dummy implementation
|
||||
of get_pc_addr function, for CPU's that don't need
|
||||
|
||||
@ -701,10 +701,10 @@ Var
|
||||
StdErr : Text;
|
||||
InOutRes : Word;
|
||||
{ Stack checking }
|
||||
StackTop,
|
||||
StackBottom : Pointer;
|
||||
StackLength : SizeUInt;
|
||||
|
||||
function StackTop: Pointer;
|
||||
|
||||
{ Numbers for routines that have compiler magic }
|
||||
{$I innr.inc}
|
||||
|
||||
@ -351,9 +351,8 @@ begin
|
||||
{$endif}
|
||||
{$endif}
|
||||
IsConsole := TRUE;
|
||||
StackTop := initialstkptr;
|
||||
StackLength := CheckInitialStkLen(initialStkLen);
|
||||
StackBottom := StackTop - StackLength;
|
||||
StackBottom := initialstkptr - StackLength;
|
||||
{ Set up signals handlers (may be needed by init code to test cpu features) }
|
||||
InstallSignals;
|
||||
{$if defined(cpui386) or defined(cpuarm)}
|
||||
|
||||
@ -340,7 +340,6 @@ begin
|
||||
end;
|
||||
|
||||
begin
|
||||
StackTop := __stktop;
|
||||
StackBottom := __stkbottom;
|
||||
StackLength := __stktop - __stkbottom;
|
||||
InstallInterruptHandlers;
|
||||
|
||||
@ -272,7 +272,7 @@ end;
|
||||
|
||||
begin
|
||||
StackLength := CheckInitialStkLen(InitialStkLen);
|
||||
StackBottom := StackTop - StackLength;
|
||||
StackBottom := Sptr - StackLength;
|
||||
{ OS specific startup }
|
||||
|
||||
{ Set up signals handlers }
|
||||
|
||||
@ -1125,11 +1125,10 @@ begin
|
||||
end;
|
||||
{$ENDIF OS2EXCEPTIONS}
|
||||
DosGetInfoBlocks (@TIB, @PIB);
|
||||
StackBottom := TIB^.Stack;
|
||||
{ $IFNDEF OS2EXCEPTIONS}
|
||||
StackTop := TIB^.StackLimit;
|
||||
{ $ENDIF OS2EXCEPTIONS}
|
||||
StackLength := CheckInitialStkLen (InitialStkLen);
|
||||
{ TODO: verify if TIB^.StackLimit is correct,
|
||||
from MSWindows point of view TIB^.Stack should be used instead }
|
||||
StackBottom := TIB^.StackLimit - StackLength;
|
||||
|
||||
{Set type of application}
|
||||
ApplicationType := PIB^.ProcType;
|
||||
|
||||
@ -247,7 +247,7 @@ end;
|
||||
|
||||
begin
|
||||
StackLength := CheckInitialStkLen(InitialStkLen);
|
||||
StackBottom := StackTop - StackLength;
|
||||
StackBottom := Sptr - StackLength;
|
||||
{ OS specific startup }
|
||||
|
||||
{ Set up signals handlers }
|
||||
|
||||
@ -128,6 +128,12 @@ function main_wrapper(arg: Pointer; proc: Pointer): ptrint; forward;
|
||||
procedure OutermostHandler; external name '__FPC_DEFAULT_HANDLER';
|
||||
{$endif FPC_USE_WIN32_SEH}
|
||||
|
||||
{$define FPC_SYSTEM_HAS_STACKTOP}
|
||||
function StackTop: pointer; assembler;nostackframe;
|
||||
asm
|
||||
movl %fs:(4),%eax
|
||||
end;
|
||||
|
||||
{ include system independent routines }
|
||||
{$I system.inc}
|
||||
|
||||
@ -642,9 +648,6 @@ function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
|
||||
result:=tpeheader((pointer(getmodulehandle(nil))+(tdosheader(pointer(getmodulehandle(nil))^).e_lfanew))^).SizeOfStackReserve;
|
||||
end;
|
||||
|
||||
var
|
||||
st : Pointer;
|
||||
|
||||
begin
|
||||
{ get some helpful informations }
|
||||
GetStartupInfo(@startupinfo);
|
||||
@ -654,12 +657,6 @@ begin
|
||||
|
||||
MainInstance:=SysInstance;
|
||||
|
||||
asm
|
||||
movl %fs:(4),%eax
|
||||
movl %eax,st
|
||||
end;
|
||||
StackTop:=st;
|
||||
|
||||
{ pass dummy value }
|
||||
StackLength := CheckInitialStkLen($1000000);
|
||||
StackBottom := StackTop - StackLength;
|
||||
|
||||
@ -116,6 +116,12 @@ asm
|
||||
end;
|
||||
{$endif FPC_USE_WIN64_SEH}
|
||||
|
||||
{$define FPC_SYSTEM_HAS_STACKTOP}
|
||||
function StackTop: pointer; assembler;nostackframe;
|
||||
asm
|
||||
movq %gs:(8),%rax
|
||||
end;
|
||||
|
||||
{ include system independent routines }
|
||||
{$I system.inc}
|
||||
|
||||
@ -581,14 +587,7 @@ function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
|
||||
result:=tpeheader((pointer(getmodulehandle(nil))+(tdosheader(pointer(getmodulehandle(nil))^).e_lfanew))^).SizeOfStackReserve;
|
||||
end;
|
||||
|
||||
|
||||
function GetExceptionPointer : Pointer; assembler;nostackframe;
|
||||
asm
|
||||
movq %gs:(8),%rax
|
||||
end;
|
||||
|
||||
begin
|
||||
StackTop:=GetExceptionPointer;
|
||||
{ pass dummy value }
|
||||
StackLength := CheckInitialStkLen($1000000);
|
||||
StackBottom := StackTop - StackLength;
|
||||
|
||||
@ -1350,15 +1350,9 @@ end;
|
||||
{$endif WINCE_EXCEPTION_HANDLING}
|
||||
|
||||
procedure Exe_entry;[public, alias : '_FPC_EXE_Entry'];
|
||||
var
|
||||
st: pointer;
|
||||
begin
|
||||
IsLibrary:=false;
|
||||
{$ifdef CPUARM}
|
||||
asm
|
||||
str sp,st
|
||||
end;
|
||||
StackTop:=st;
|
||||
asm
|
||||
mov fp,#0
|
||||
bl PASCALMAIN;
|
||||
@ -1373,11 +1367,6 @@ begin
|
||||
mov %esp,%fs:(0)
|
||||
{$endif WINCE_EXCEPTION_HANDLING}
|
||||
pushl %ebp
|
||||
movl %esp,%eax
|
||||
movl %eax,st
|
||||
end;
|
||||
StackTop:=st;
|
||||
asm
|
||||
xorl %eax,%eax
|
||||
movw %ss,%ax
|
||||
movl %eax,_SS
|
||||
@ -1758,7 +1747,7 @@ initialization
|
||||
if not(IsLibrary) then
|
||||
SysInitFPU;
|
||||
StackLength := CheckInitialStkLen(InitialStkLen);
|
||||
StackBottom := StackTop - StackLength;
|
||||
StackBottom := Sptr - StackLength;
|
||||
{ some misc stuff }
|
||||
hprevinst:=0;
|
||||
if not IsLibrary then
|
||||
|
||||
Loading…
Reference in New Issue
Block a user