summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjonas <jonas@3ad0048d-3df7-0310-abae-a5850022a9f2>2021-04-08 19:50:30 +0000
committerjonas <jonas@3ad0048d-3df7-0310-abae-a5850022a9f2>2021-04-08 19:50:30 +0000
commit0c7ce873f2c71726b81a6c6c224eec358cf202e4 (patch)
tree1f92e1d94957df2cc3ff1714c327c4c91d50b1ef
parent899215521fc52132a3538888a2c394fc33158864 (diff)
downloadfpc-0c7ce873f2c71726b81a6c6c224eec358cf202e4.tar.gz
* Darwin/BSD: fixed StackBottom calculation
git-svn-id: https://svn.freepascal.org/svn/fpc/trunk@49139 3ad0048d-3df7-0310-abae-a5850022a9f2
-rw-r--r--rtl/bsd/system.pp20
1 files changed, 17 insertions, 3 deletions
diff --git a/rtl/bsd/system.pp b/rtl/bsd/system.pp
index de986f1cd6..f5ffa670c6 100644
--- a/rtl/bsd/system.pp
+++ b/rtl/bsd/system.pp
@@ -350,13 +350,27 @@ begin
GetProcessID := SizeUInt (fpGetPID);
end;
+function InternalPageSize: SizeUInt; inline;
+begin
+{$ifndef darwin}
+ InternalPageSize := 4096;
+{$else not darwin}
+ InternalPageSize := darwin_page_size;
+{$endif not darwin}
+end;
+
+function AlignedStackTop: Pointer;
+begin
+ AlignedStackTop:=Pointer((ptruint(sptr) + InternalPageSize - 1) and not(InternalPageSize - 1));
+end;
+
function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
var
stackpointer: ptruint;
begin
- stackpointer := (ptruint(sptr) + 4095) and not(4095);
+ stackpointer := ptruint(AlignedStackTop);
if stklen > stackpointer then
- stklen := stackpointer-4096;
+ stklen := stackpointer - InternalPageSize;
result := stklen;
end;
@@ -366,7 +380,7 @@ Begin
{$endif darwin}
IsConsole := TRUE;
StackLength := CheckInitialStkLen(InitialStkLen);
- StackBottom := Sptr - StackLength;
+ StackBottom := AlignedStackTop - StackLength;
{$ifdef FPC_HAS_SETSYSNR_INC}
{ This procedure is needed for openbsd system which re-uses
the same syscall numbers depending on OS version }