sysinitgprof.pp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2006 by Florian Klaempfl and Pavel Ozerski
  4. member of the Free Pascal development team.
  5. Win32 cygwin profiler startup code
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. unit sysinitgprof;
  13. interface
  14. implementation
  15. {$linklib gmon}
  16. {$linklib gcc}
  17. {$linklib cygwin}
  18. {$linklib user32}
  19. {$linklib kernel32}
  20. const
  21. monstarted : dword = 0;
  22. var
  23. SysInstance : Longint;external name '_FPC_SysInstance';
  24. stext : record end;external name '__text_start__';
  25. etext : record end;external name 'etext';
  26. procedure EXE_Entry; external name '_FPC_EXE_Entry';
  27. function DLL_Entry : longbool; external name '_FPC_DLL_Entry';
  28. procedure Cygwin_crt0(p : pointer);cdecl;external name 'cygwin_crt0';
  29. procedure __main;cdecl;external name '__main';
  30. procedure _mcleanup;cdecl;external name '_mcleanup';
  31. procedure monstartup(main,etext : pointer);cdecl;external name 'monstartup';
  32. procedure CMainEXE;cdecl;forward;
  33. procedure CMainDLL;cdecl;forward;
  34. const
  35. STD_INPUT_HANDLE = dword(-10);
  36. function GetStdHandle(nStdHandle:DWORD) : THandle; stdcall; external 'kernel32' name 'GetStdHandle';
  37. function GetConsoleMode(hConsoleHandle: THandle; var lpMode: DWORD): Boolean; stdcall; external 'kernel32' name 'GetConsoleMode';
  38. procedure EXEgmon_start;
  39. begin
  40. if monstarted=0 then
  41. begin
  42. inc(monstarted);
  43. monstartup(@stext,@etext);
  44. end;
  45. end;
  46. procedure DLLgmon_start;
  47. begin
  48. if monstarted=0 then
  49. begin
  50. inc(monstarted);
  51. monstartup(@stext,@etext);
  52. end;
  53. end;
  54. procedure CMainEXE;cdecl;
  55. begin
  56. asm
  57. subl $0x8,%esp
  58. andl $0xfffffff0,%esp
  59. end;
  60. EXEgmon_start;
  61. __main;
  62. EXE_Entry;
  63. end;
  64. procedure CMainDLL;cdecl;
  65. begin
  66. asm
  67. subl $0x8,%esp
  68. andl $0xfffffff0,%esp
  69. end;
  70. DLLgmon_start;
  71. __main;
  72. DLL_Entry;
  73. end;
  74. procedure _FPC_mainCRTStartup;stdcall;public name '_mainCRTStartup';
  75. begin
  76. IsConsole:=true;
  77. asm
  78. subl $0x8,%esp
  79. andl $0xfffffff0,%esp
  80. end;
  81. { it seems cygwin messed around with the console mode so we've to
  82. store the startup console mode before cygwin can do anything (FK)
  83. }
  84. GetConsoleMode(GetStdHandle((Std_Input_Handle)),StartupConsoleMode);
  85. Cygwin_crt0(@CMainEXE);
  86. end;
  87. procedure _FPC_WinMainCRTStartup;stdcall;public name '_WinMainCRTStartup';
  88. begin
  89. IsConsole:=false;
  90. asm
  91. subl $0x8,%esp
  92. andl $0xfffffff0,%esp
  93. end;
  94. Cygwin_crt0(@CMainEXE);
  95. end;
  96. procedure _FPC_DLLMainCRTStartup(_hinstance,_dllreason,_dllparam:longint);stdcall;public name '_DLLMainCRTStartup';
  97. begin
  98. IsConsole:=true;
  99. sysinstance:=_hinstance;
  100. dllreason:=_dllreason;
  101. dllparam:=_dllparam;
  102. asm
  103. subl $0x8,%esp
  104. andl $0xfffffff0,%esp
  105. end;
  106. Cygwin_crt0(@CMainDLL);
  107. end;
  108. procedure _FPC_DLLWinMainCRTStartup(_hinstance,_dllreason,_dllparam:longint);stdcall;public name '_DLLWinMainCRTStartup';
  109. begin
  110. IsConsole:=false;
  111. sysinstance:=_hinstance;
  112. dllreason:=_dllreason;
  113. dllparam:=_dllparam;
  114. asm
  115. subl $0x8,%esp
  116. andl $0xfffffff0,%esp
  117. end;
  118. Cygwin_crt0(@CMainDLL);
  119. end;
  120. procedure asm_exit;stdcall;public name 'asm_exit';
  121. begin
  122. _mcleanup;
  123. end;
  124. end.