sysinitgprof.pp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. procedure EXEgmon_start;
  35. begin
  36. if monstarted=0 then
  37. begin
  38. inc(monstarted);
  39. monstartup(@stext,@etext);
  40. end;
  41. end;
  42. procedure DLLgmon_start;
  43. begin
  44. if monstarted=0 then
  45. begin
  46. inc(monstarted);
  47. monstartup(@stext,@etext);
  48. end;
  49. end;
  50. procedure CMainEXE;cdecl;
  51. begin
  52. asm
  53. subl $0x8,%esp
  54. andl $0xfffffff0,%esp
  55. end;
  56. EXEgmon_start;
  57. __main;
  58. EXE_Entry;
  59. end;
  60. procedure CMainDLL;cdecl;
  61. begin
  62. asm
  63. subl $0x8,%esp
  64. andl $0xfffffff0,%esp
  65. end;
  66. DLLgmon_start;
  67. __main;
  68. DLL_Entry;
  69. end;
  70. procedure _FPC_mainCRTStartup;stdcall;public name '_mainCRTStartup';
  71. begin
  72. IsConsole:=true;
  73. asm
  74. subl $0x8,%esp
  75. andl $0xfffffff0,%esp
  76. end;
  77. Cygwin_crt0(@CMainEXE);
  78. end;
  79. procedure _FPC_WinMainCRTStartup;stdcall;public name '_WinMainCRTStartup';
  80. begin
  81. IsConsole:=false;
  82. asm
  83. subl $0x8,%esp
  84. andl $0xfffffff0,%esp
  85. end;
  86. Cygwin_crt0(@CMainEXE);
  87. end;
  88. procedure _FPC_DLLMainCRTStartup(_hinstance,_dllreason,_dllparam:longint);stdcall;public name '_DLLMainCRTStartup';
  89. begin
  90. IsConsole:=true;
  91. sysinstance:=_hinstance;
  92. dllreason:=_dllreason;
  93. dllparam:=_dllparam;
  94. asm
  95. subl $0x8,%esp
  96. andl $0xfffffff0,%esp
  97. end;
  98. Cygwin_crt0(@CMainDLL);
  99. end;
  100. procedure _FPC_DLLWinMainCRTStartup(_hinstance,_dllreason,_dllparam:longint);stdcall;public name '_DLLWinMainCRTStartup';
  101. begin
  102. IsConsole:=false;
  103. sysinstance:=_hinstance;
  104. dllreason:=_dllreason;
  105. dllparam:=_dllparam;
  106. asm
  107. subl $0x8,%esp
  108. andl $0xfffffff0,%esp
  109. end;
  110. Cygwin_crt0(@CMainDLL);
  111. end;
  112. procedure asm_exit;stdcall;public name 'asm_exit';
  113. begin
  114. _mcleanup;
  115. end;
  116. end.