summaryrefslogtreecommitdiff
path: root/packages/rtl/win32/sysinit.inc
blob: 65d13b03f823d49638651f10cf3e83b4ad36c4ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
{
    This file is part of the Free Pascal run time library.
    Copyright (c) 1999-2006 by Florian Klaempfl and Pavel Ozerski
    member of the Free Pascal development team.

    Win32 startup code, shared part

    See the file COPYING.FPC, included in this distribution,
    for details about the copyright.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 **********************************************************************}

   var
      SysInstance : Longint; public name '_FPC_SysInstance'; //external name '_FPC_SysInstance';
      TlsKeyVar: DWord = $ffffffff; public name '_FPC_TlsKey';

      InitFinalTable : record end; external name 'INITFINAL';
      ThreadvarTablesTable : record end; external name 'FPC_THREADVARTABLES';
      WideInitTables : record end; external name 'FPC_WIDEINITTABLES';
{$ifdef FPC_HAS_RESSTRINITS}
      ResStrInitTables : record end; external name 'FPC_RESSTRINITTABLES';
{$endif}
      ResourceStringTables : record end; external name 'FPC_RESOURCESTRINGTABLES';
      valgrind_used : boolean;external name '__fpc_valgrind';

{$if defined(FPC_USE_TLS_DIRECTORY) or defined(FPC_SECTION_THREADVARS)}
   var
      tlsdir: record end; external name '__tls_used';

    procedure LinkIn(p1,p2,p3: Pointer); inline;
      begin
      end;
{$endif}

{$ifdef FPC_USE_TLS_DIRECTORY}
   var
      tls_callback_end: pointer; external name '__FPC_end_of_tls_callbacks';
      tls_callback: pointer; external name '__FPC_tls_callbacks';
{$endif FPC_USE_TLS_DIRECTORY}

    procedure EXE_Entry(const info : TEntryInformation); external name '_FPC_EXE_Entry';
    function DLL_Entry(const info : TEntryInformation) : longbool; external name '_FPC_DLL_Entry';
    procedure PascalMain;external name 'PASCALMAIN';

    function GetStdHandle(nStdHandle:DWORD) : THandle; stdcall; external 'kernel32' name 'GetStdHandle';
    function GetConsoleMode(hConsoleHandle: THandle; var lpMode: DWORD): Boolean; stdcall; external 'kernel32' name 'GetConsoleMode';

    const
      STD_INPUT_HANDLE = dword(-10);
      SysInitEntryInformation : TEntryInformation = (
        InitFinalTable : @InitFinalTable;
        ThreadvarTablesTable : @ThreadvarTablesTable;
        ResourceStringTables : @ResourceStringTables;
{$ifdef FPC_HAS_RESSTRINITS}
        ResStrInitTables : @ResStrInitTables;
{$else}
        ResStrInitTables : nil;
{$endif}
{$ifndef FPC_WIDESTRING_EQUAL_UNICODESTRING}
        WideInitTables : @WideInitTables;
{$endif}
        asm_exit : @asm_exit;
        PascalMain : @PascalMain;
        valgrind_used : false;
        Platform: (
            TlsKeyAddr : @TlsKeyVar;
            SysInstanceAddr : @SysInstance;
          );
        );


    procedure SetupEntryInformation;
      begin
        { valgind_used is the only thng that can change at startup
        EntryInformation.InitFinalTable:=@InitFinalTable;
        EntryInformation.ThreadvarTablesTable:=@ThreadvarTablesTable;
        ResourceStringTables:=@ResourceStringTables;
        ResStrInitTables:=@ResStrInitTables;
{$ifndef FPC_WIDESTRING_EQUAL_UNICODESTRING}
        WideInitTables:=@WideInitTables;
{$endif}
        EntryInformation.asm_exit:=@asm_exit;
        EntryInformation.PascalMain:=@PascalMain;}
        SysInitEntryInformation.valgrind_used:=valgrind_used;
      end;

{$define FPC_INSSIDE_SYSINIT}
{$define FPC_HAS_INDIRECT_MAIN_INFORMATION}
{$include systlsdir.inc}