* WASI: preserve the initial value of the stack pointer on startup, so that we

can later use the area after that, until the end of memory as an initial heap
This commit is contained in:
Nikolay Nikolov 2024-07-21 18:21:43 +03:00
parent 5cfd214b68
commit 7d1999eedb
3 changed files with 44 additions and 4 deletions

View File

@ -32,7 +32,7 @@ procedure PASCALMAIN; external 'PASCALMAIN';
{$if defined(FPC_WASM_BRANCHFUL_EXCEPTIONS) or defined(FPC_WASM_NATIVE_EXCEPTIONS)}
Procedure DoUnHandledException; external name 'FPC_DOUNHANDLEDEXCEPTION';
procedure _initialize;
procedure _initialize_pascal;
begin
try
PASCALMAIN;
@ -41,12 +41,28 @@ begin
end;
end;
{$else}
procedure _initialize;
procedure _initialize_pascal;
begin
PASCALMAIN;
end;
{$endif}
procedure SetInitialHeapBlockStart(p: Pointer); external name 'FPC_WASM_SETINITIALHEAPBLOCKSTART';
{ TODO: remove this, when calling SetInitialHeapBlockStart works directly from within inline asm }
procedure SetInitialHeapBlockStart2(p: Pointer);
begin
SetInitialHeapBlockStart(p);
end;
procedure _initialize; assembler; nostackframe;
asm
global.get $__stack_pointer
call $SetInitialHeapBlockStart2
call $_initialize_pascal
end;
exports
_initialize,
_initialize name '_initialize_promising' promising;

View File

@ -32,7 +32,7 @@ procedure PASCALMAIN; external 'PASCALMAIN';
{$if defined(FPC_WASM_BRANCHFUL_EXCEPTIONS) or defined(FPC_WASM_NATIVE_EXCEPTIONS)}
Procedure DoUnHandledException; external name 'FPC_DOUNHANDLEDEXCEPTION';
procedure _start;
procedure _start_pascal;
begin
try
PASCALMAIN;
@ -41,12 +41,28 @@ begin
end;
end;
{$else}
procedure _start;
procedure _start_pascal;
begin
PASCALMAIN;
end;
{$endif}
procedure SetInitialHeapBlockStart(p: Pointer); external name 'FPC_WASM_SETINITIALHEAPBLOCKSTART';
{ TODO: remove this, when calling SetInitialHeapBlockStart works directly from within inline asm }
procedure SetInitialHeapBlockStart2(p: Pointer);
begin
SetInitialHeapBlockStart(p);
end;
procedure _start; assembler; nostackframe;
asm
global.get $__stack_pointer
call $SetInitialHeapBlockStart2
call $_start_pascal
end;
exports
_start,
_start name '_start_promising' promising;

View File

@ -20,6 +20,14 @@
Heap Management
*****************************************************************************}
var
InitialHeapBlockStart: Pointer;
procedure SetInitialHeapBlockStart(p: Pointer);[Public, Alias : 'FPC_WASM_SETINITIALHEAPBLOCKSTART'];
begin
InitialHeapBlockStart:=p;
end;
function SysOSAlloc(size: ptruint): pointer;
const
page_size = 65536;