mirror of
https://github.com/vapaamies/KolibriOS.git
synced 2025-09-21 22:53:51 +02:00
Units initialization/finalization support added
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
(*
|
||||
Minimal Delphi System unit
|
||||
KolibriOS RTL System unit
|
||||
*)
|
||||
|
||||
unit System;
|
||||
@@ -19,33 +19,96 @@ type
|
||||
D4: array [0..7] of Byte;
|
||||
end;
|
||||
|
||||
PProcedure = procedure;
|
||||
|
||||
TPackageUnitEntry = packed record
|
||||
Init, Finalize: PProcedure;
|
||||
end;
|
||||
|
||||
PUnitEntryTable = ^TUnitEntryTable;
|
||||
TUnitEntryTable = array [0..99999999] of TPackageUnitEntry;
|
||||
|
||||
PPackageInfo = ^TPackageInfo;
|
||||
TPackageInfo = packed record
|
||||
UnitCount: Integer;
|
||||
UnitInfo: PUnitEntryTable;
|
||||
end;
|
||||
|
||||
PInitContext = ^TInitContext;
|
||||
TInitContext = record
|
||||
InitTable: PPackageInfo;
|
||||
InitCount: Integer;
|
||||
OuterContext: PInitContext;
|
||||
ExceptionFrame, InitTable, InitCount: Integer;
|
||||
Module: Pointer;
|
||||
DLLSaveEBP, DLLSaveEBX, DLLSaveESI, DLLSaveEDI: Pointer;
|
||||
ExitProcessTLS: procedure;
|
||||
DLLInitState: byte;
|
||||
end;
|
||||
|
||||
procedure _Halt0;
|
||||
procedure _HandleFinally;
|
||||
procedure _StartExe(InitTable: PPackageInfo);
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
SysInit;
|
||||
|
||||
procedure _Halt0;
|
||||
asm
|
||||
XOR EAX, EAX
|
||||
DEC EAX
|
||||
INT $40
|
||||
end;
|
||||
var
|
||||
InitContext: TInitContext;
|
||||
|
||||
procedure _HandleFinally;
|
||||
asm
|
||||
end;
|
||||
|
||||
procedure InitUnits;
|
||||
var
|
||||
Idx: Integer;
|
||||
begin
|
||||
if InitContext.InitTable <> nil then
|
||||
with InitContext.InitTable^ do
|
||||
begin
|
||||
Idx := 0;
|
||||
while Idx < UnitCount do
|
||||
begin
|
||||
with UnitInfo[Idx] do
|
||||
begin
|
||||
if Assigned(Init) then
|
||||
Init;
|
||||
end;
|
||||
Inc(Idx);
|
||||
InitContext.InitCount := Idx;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure FinalizeUnits;
|
||||
begin
|
||||
if InitContext.InitTable <> nil then
|
||||
begin
|
||||
with InitContext do
|
||||
begin
|
||||
while InitCount > 0 do
|
||||
begin
|
||||
Dec(InitCount);
|
||||
with InitTable.UnitInfo[InitCount] do
|
||||
if Assigned(Finalize) then
|
||||
Finalize;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure _StartExe(InitTable: PPackageInfo);
|
||||
begin
|
||||
InitContext.InitTable := InitTable;
|
||||
InitContext.InitCount := 0;
|
||||
InitUnits;
|
||||
end;
|
||||
|
||||
procedure _Halt0;
|
||||
begin
|
||||
FinalizeUnits;
|
||||
asm
|
||||
OR EAX, -1
|
||||
INT $40
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
Reference in New Issue
Block a user