system.pp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2005 by Florian Klaempfl and Pavel Ozerski
  4. member of the Free Pascal development team.
  5. FPC Pascal system unit for the Win32 API.
  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 System;
  13. interface
  14. {$define FPC_IS_SYSTEM}
  15. {$ifdef SYSTEMDEBUG}
  16. {$define SYSTEMEXCEPTIONDEBUG}
  17. {$endif SYSTEMDEBUG}
  18. {$ifdef VER3_0}
  19. { 3.1.1+ do not require this anymore }
  20. {$define FPC_HAS_INDIRECT_ENTRY_INFORMATION}
  21. {$endif VER3_0}
  22. {$ifdef cpui386}
  23. {$define Set_i386_Exception_handler}
  24. {$endif cpui386}
  25. {$define DISABLE_NO_THREAD_MANAGER}
  26. {$define HAS_WIDESTRINGMANAGER}
  27. {$define DISABLE_NO_DYNLIBS_MANAGER}
  28. {$define FPC_SYSTEM_HAS_SYSDLH}
  29. {$define FPC_HAS_SETCTRLBREAKHANDLER}
  30. {$ifdef FPC_USE_WIN32_SEH}
  31. {$define FPC_SYSTEM_HAS_RAISEEXCEPTION}
  32. {$define FPC_SYSTEM_HAS_RERAISE}
  33. {$define FPC_SYSTEM_HAS_DONEEXCEPTION}
  34. {$define FPC_SYSTEM_HAS_SAFECALLHANDLER}
  35. {$endif FPC_USE_WIN32_SEH}
  36. { include system-independent routine headers }
  37. {$I systemh.inc}
  38. { include common windows headers }
  39. {$I syswinh.inc}
  40. var
  41. MainInstance : longint;
  42. implementation
  43. var
  44. FPCSysInstance : PLongint;public name '_FPC_SysInstance';
  45. {$define FPC_SYSTEM_HAS_OSSETUPENTRYINFORMATION}
  46. procedure OsSetupEntryInformation(constref info: TEntryInformation); forward;
  47. {$ifdef FPC_USE_WIN32_SEH}
  48. function main_wrapper(arg: Pointer; proc: Pointer): ptrint; forward;
  49. procedure OutermostHandler; external name '__FPC_DEFAULT_HANDLER';
  50. {$endif FPC_USE_WIN32_SEH}
  51. {$define FPC_SYSTEM_HAS_STACKTOP}
  52. function StackTop: pointer; assembler;nostackframe;
  53. asm
  54. movl %fs:(4),%eax
  55. end;
  56. { include system independent routines }
  57. {$I system.inc}
  58. { include code common with win64 }
  59. {$I syswin.inc}
  60. procedure OsSetupEntryInformation(constref info: TEntryInformation);
  61. begin
  62. TlsKey := info.OS.TlsKeyAddr;
  63. FPCSysInstance := info.OS.SysInstance;
  64. WStrInitTablesTable := info.OS.WideInitTables;
  65. end;
  66. {*****************************************************************************
  67. System Dependent Exit code
  68. *****************************************************************************}
  69. {$ifndef FPC_USE_WIN32_SEH}
  70. procedure install_exception_handlers;forward;
  71. procedure remove_exception_handlers;forward;
  72. {$endif FPC_USE_WIN32_SEH}
  73. Procedure system_exit;
  74. begin
  75. if IsLibrary then
  76. begin
  77. { If exiting from DLL_PROCESS_ATTACH/DETACH, unwind to DllMain context. }
  78. if DllInitState in [DLL_PROCESS_ATTACH,DLL_PROCESS_DETACH] then
  79. LongJmp(DLLBuf,1)
  80. else
  81. { Abnormal termination, Halt has been called from DLL function,
  82. put down the entire process (DLL_PROCESS_DETACH will still
  83. occur). At this point RTL has been already finalized in InternalExit
  84. and shouldn't be finalized another time in DLL_PROCESS_DETACH.
  85. Indicate this by resetting MainThreadIdWin32. }
  86. MainThreadIDWin32:=0;
  87. end;
  88. if not IsConsole then
  89. begin
  90. Close(stderr);
  91. Close(stdout);
  92. Close(erroutput);
  93. Close(Input);
  94. Close(Output);
  95. { what about Input and Output ?? PM }
  96. { now handled, FPK }
  97. end;
  98. {$ifndef FPC_USE_WIN32_SEH}
  99. if not IsLibrary then
  100. remove_exception_handlers;
  101. {$endif FPC_USE_WIN32_SEH}
  102. { do cleanup required by the startup code }
  103. EntryInformation.OS.asm_exit();
  104. { call exitprocess, with cleanup as required }
  105. ExitProcess(exitcode);
  106. end;
  107. var
  108. { value of the stack segment
  109. to check if the call stack can be written on exceptions }
  110. _SS : Cardinal;
  111. procedure Exe_entry(constref info : TEntryInformation);[public,alias:'_FPC_EXE_Entry'];
  112. var
  113. xframe: TEXCEPTION_FRAME;
  114. begin
  115. SetupEntryInformation(info);
  116. IsLibrary:=false;
  117. { install the handlers for exe only ?
  118. or should we install them for DLL also ? (PM) }
  119. {$ifndef FPC_USE_WIN32_SEH}
  120. install_exception_handlers;
  121. {$endif FPC_USE_WIN32_SEH}
  122. { This strange construction is needed to solve the _SS problem
  123. with a smartlinked syswin32 (PFV) }
  124. asm
  125. { movl %esp,%fs:(0)
  126. but don't insert it as it doesn't
  127. point to anything yet
  128. this will be used in signals unit }
  129. leal xframe,%eax
  130. movl %fs:(0),%ecx
  131. movl %ecx,TException_Frame.next(%eax)
  132. movl %eax,System_exception_frame
  133. {$ifndef FPC_USE_WIN32_SEH}
  134. movl $0,TException_Frame.handler(%eax)
  135. {$else}
  136. movl $OutermostHandler,TException_Frame.handler(%eax)
  137. movl %eax,%fs:(0)
  138. {$endif FPC_USE_WIN32_SEH}
  139. pushl %ebp
  140. xorl %eax,%eax
  141. movw %ss,%ax
  142. movl %eax,_SS
  143. xorl %ebp,%ebp
  144. end;
  145. EntryInformation.PascalMain();
  146. asm
  147. popl %ebp
  148. end;
  149. { if we pass here there was no error ! }
  150. system_exit;
  151. end;
  152. function is_prefetch(p : pointer) : boolean;
  153. var
  154. a : array[0..15] of byte;
  155. doagain : boolean;
  156. instrlo,instrhi,opcode : byte;
  157. i : longint;
  158. begin
  159. result:=false;
  160. { read memory savely without causing another exeception }
  161. if not(ReadProcessMemory(GetCurrentProcess,p,@a,sizeof(a),nil)) then
  162. exit;
  163. i:=0;
  164. doagain:=true;
  165. while doagain and (i<15) do
  166. begin
  167. opcode:=a[i];
  168. instrlo:=opcode and $f;
  169. instrhi:=opcode and $f0;
  170. case instrhi of
  171. { prefix? }
  172. $20,$30:
  173. doagain:=(instrlo and 7)=6;
  174. $60:
  175. doagain:=(instrlo and $c)=4;
  176. $f0:
  177. doagain:=instrlo in [0,2,3];
  178. $0:
  179. begin
  180. result:=(instrlo=$f) and (a[i+1] in [$d,$18]);
  181. exit;
  182. end;
  183. else
  184. doagain:=false;
  185. end;
  186. inc(i);
  187. end;
  188. end;
  189. //
  190. // Hardware exception handling
  191. //
  192. {$ifdef Set_i386_Exception_handler}
  193. type
  194. PFloatingSaveArea = ^TFloatingSaveArea;
  195. TFloatingSaveArea = packed record
  196. ControlWord : Cardinal;
  197. StatusWord : Cardinal;
  198. TagWord : Cardinal;
  199. ErrorOffset : Cardinal;
  200. ErrorSelector : Cardinal;
  201. DataOffset : Cardinal;
  202. DataSelector : Cardinal;
  203. RegisterArea : array[0..79] of Byte;
  204. Cr0NpxState : Cardinal;
  205. end;
  206. PContext = ^TContext;
  207. TContext = packed record
  208. //
  209. // The flags values within this flag control the contents of
  210. // a CONTEXT record.
  211. //
  212. ContextFlags : Cardinal;
  213. //
  214. // This section is specified/returned if CONTEXT_DEBUG_REGISTERS is
  215. // set in ContextFlags. Note that CONTEXT_DEBUG_REGISTERS is NOT
  216. // included in CONTEXT_FULL.
  217. //
  218. Dr0, Dr1, Dr2,
  219. Dr3, Dr6, Dr7 : Cardinal;
  220. //
  221. // This section is specified/returned if the
  222. // ContextFlags word contains the flag CONTEXT_FLOATING_POINT.
  223. //
  224. FloatSave : TFloatingSaveArea;
  225. //
  226. // This section is specified/returned if the
  227. // ContextFlags word contains the flag CONTEXT_SEGMENTS.
  228. //
  229. SegGs, SegFs,
  230. SegEs, SegDs : Cardinal;
  231. //
  232. // This section is specified/returned if the
  233. // ContextFlags word contains the flag CONTEXT_INTEGER.
  234. //
  235. Edi, Esi, Ebx,
  236. Edx, Ecx, Eax : Cardinal;
  237. //
  238. // This section is specified/returned if the
  239. // ContextFlags word contains the flag CONTEXT_CONTROL.
  240. //
  241. Ebp : Cardinal;
  242. Eip : Cardinal;
  243. SegCs : Cardinal;
  244. EFlags, Esp, SegSs : Cardinal;
  245. //
  246. // This section is specified/returned if the ContextFlags word
  247. // contains the flag CONTEXT_EXTENDED_REGISTERS.
  248. // The format and contexts are processor specific
  249. //
  250. ExtendedRegisters : array[0..MAXIMUM_SUPPORTED_EXTENSION-1] of Byte;
  251. end;
  252. PExceptionPointers = ^TExceptionPointers;
  253. TExceptionPointers = packed record
  254. ExceptionRecord : PExceptionRecord;
  255. ContextRecord : PContext;
  256. end;
  257. { type of functions that should be used for exception handling }
  258. TTopLevelExceptionFilter = function (excep : PExceptionPointers) : Longint;stdcall;
  259. {$i seh32.inc}
  260. {$ifndef FPC_USE_WIN32_SEH}
  261. function SetUnhandledExceptionFilter(lpTopLevelExceptionFilter : TTopLevelExceptionFilter) : TTopLevelExceptionFilter;
  262. stdcall;external 'kernel32' name 'SetUnhandledExceptionFilter';
  263. const
  264. MaxExceptionLevel = 16;
  265. exceptLevel : Byte = 0;
  266. var
  267. exceptEip : array[0..MaxExceptionLevel-1] of Longint;
  268. exceptError : array[0..MaxExceptionLevel-1] of Byte;
  269. resetFPU : array[0..MaxExceptionLevel-1] of Boolean;
  270. {$ifdef SYSTEMEXCEPTIONDEBUG}
  271. procedure DebugHandleErrorAddrFrame(error : longint; addr, frame : pointer);
  272. begin
  273. if IsConsole then
  274. begin
  275. write(stderr,'HandleErrorAddrFrame(error=',error);
  276. write(stderr,',addr=',hexstr(ptruint(addr),8));
  277. writeln(stderr,',frame=',hexstr(ptruint(frame),8),')');
  278. end;
  279. HandleErrorAddrFrame(error,addr,frame);
  280. end;
  281. {$endif SYSTEMEXCEPTIONDEBUG}
  282. procedure JumpToHandleErrorFrame;
  283. var
  284. eip, ebp, error : Longint;
  285. begin
  286. // save ebp
  287. asm
  288. movl (%ebp),%eax
  289. movl %eax,ebp
  290. end;
  291. if (exceptLevel > 0) then
  292. dec(exceptLevel);
  293. eip:=exceptEip[exceptLevel];
  294. error:=exceptError[exceptLevel];
  295. {$ifdef SYSTEMEXCEPTIONDEBUG}
  296. if IsConsole then
  297. writeln(stderr,'In JumpToHandleErrorFrame error=',error);
  298. {$endif SYSTEMEXCEPTIONDEBUG}
  299. if resetFPU[exceptLevel] then
  300. SysResetFPU;
  301. { build a fake stack }
  302. asm
  303. movl ebp,%ecx
  304. movl eip,%edx
  305. movl error,%eax
  306. pushl eip
  307. movl ebp,%ebp // Change frame pointer
  308. {$ifdef SYSTEMEXCEPTIONDEBUG}
  309. jmpl DebugHandleErrorAddrFrame
  310. {$else not SYSTEMEXCEPTIONDEBUG}
  311. jmpl HandleErrorAddrFrame
  312. {$endif SYSTEMEXCEPTIONDEBUG}
  313. end;
  314. end;
  315. function syswin32_i386_exception_handler(excep : PExceptionPointers) : Longint;stdcall;
  316. var
  317. res,ssecode: longint;
  318. err: byte;
  319. must_reset_fpu: boolean;
  320. begin
  321. res := EXCEPTION_CONTINUE_SEARCH;
  322. if excep^.ContextRecord^.SegSs=_SS then begin
  323. err := 0;
  324. must_reset_fpu := true;
  325. {$ifdef SYSTEMEXCEPTIONDEBUG}
  326. if IsConsole then Writeln(stderr,'Exception ',
  327. hexstr(excep^.ExceptionRecord^.ExceptionCode, 8));
  328. {$endif SYSTEMEXCEPTIONDEBUG}
  329. case excep^.ExceptionRecord^.ExceptionCode of
  330. STATUS_INTEGER_DIVIDE_BY_ZERO,
  331. STATUS_FLOAT_DIVIDE_BY_ZERO :
  332. err := 200;
  333. STATUS_ARRAY_BOUNDS_EXCEEDED :
  334. begin
  335. err := 201;
  336. must_reset_fpu := false;
  337. end;
  338. STATUS_STACK_OVERFLOW :
  339. begin
  340. err := 202;
  341. must_reset_fpu := false;
  342. end;
  343. STATUS_FLOAT_OVERFLOW :
  344. err := 205;
  345. STATUS_FLOAT_DENORMAL_OPERAND,
  346. STATUS_FLOAT_UNDERFLOW :
  347. err := 206;
  348. {excep^.ContextRecord^.FloatSave.StatusWord := excep^.ContextRecord^.FloatSave.StatusWord and $ffffff00;}
  349. STATUS_FLOAT_INEXACT_RESULT,
  350. STATUS_FLOAT_INVALID_OPERATION,
  351. STATUS_FLOAT_STACK_CHECK :
  352. err := 207;
  353. STATUS_INTEGER_OVERFLOW :
  354. begin
  355. err := 215;
  356. must_reset_fpu := false;
  357. end;
  358. STATUS_ILLEGAL_INSTRUCTION:
  359. { if we're testing sse support, simply set the flag and continue }
  360. if sse_check then
  361. begin
  362. os_supports_sse:=false;
  363. { skip the offending movaps %xmm7, %xmm6 instruction }
  364. inc(excep^.ContextRecord^.Eip,3);
  365. excep^.ExceptionRecord^.ExceptionCode := 0;
  366. res:=EXCEPTION_CONTINUE_EXECUTION;
  367. end
  368. else
  369. err := 216;
  370. STATUS_ACCESS_VIOLATION:
  371. { Athlon prefetch bug? }
  372. if is_prefetch(pointer(excep^.ContextRecord^.Eip)) then
  373. begin
  374. { if yes, then retry }
  375. excep^.ExceptionRecord^.ExceptionCode := 0;
  376. res:=EXCEPTION_CONTINUE_EXECUTION;
  377. end
  378. else
  379. err := 216;
  380. STATUS_CONTROL_C_EXIT:
  381. err := 217;
  382. STATUS_PRIVILEGED_INSTRUCTION:
  383. begin
  384. err := 218;
  385. must_reset_fpu := false;
  386. end;
  387. STATUS_FLOAT_MULTIPLE_FAULTS,
  388. STATUS_FLOAT_MULTIPLE_TRAPS:
  389. begin
  390. { dumping ExtendedRegisters and comparing with the actually value of mxcsr revealed 24 }
  391. TranslateMxcsr(excep^.ContextRecord^.ExtendedRegisters[24],ssecode);
  392. {$ifdef SYSTEMEXCEPTIONDEBUG}
  393. if IsConsole then
  394. Writeln(stderr,'MXSR: ',hexstr(excep^.ContextRecord^.ExtendedRegisters[24], 2),' SSECODE: ',ssecode);
  395. {$endif SYSTEMEXCEPTIONDEBUG}
  396. err:=-ssecode;
  397. end;
  398. else
  399. begin
  400. if ((excep^.ExceptionRecord^.ExceptionCode and SEVERITY_ERROR) = SEVERITY_ERROR) then
  401. err := 217
  402. else
  403. err := 255;
  404. end;
  405. end;
  406. if (err <> 0) and (exceptLevel < MaxExceptionLevel) then begin
  407. exceptEip[exceptLevel] := excep^.ContextRecord^.Eip;
  408. exceptError[exceptLevel] := err;
  409. resetFPU[exceptLevel] := must_reset_fpu;
  410. inc(exceptLevel);
  411. excep^.ContextRecord^.Eip := Longint(@JumpToHandleErrorFrame);
  412. excep^.ExceptionRecord^.ExceptionCode := 0;
  413. res := EXCEPTION_CONTINUE_EXECUTION;
  414. {$ifdef SYSTEMEXCEPTIONDEBUG}
  415. if IsConsole then begin
  416. writeln(stderr,'Exception Continue Exception set at ',
  417. hexstr(exceptEip[exceptLevel],8));
  418. writeln(stderr,'Eip changed to ',
  419. hexstr(longint(@JumpToHandleErrorFrame),8), ' error=', err);
  420. end;
  421. {$endif SYSTEMEXCEPTIONDEBUG}
  422. end;
  423. end;
  424. syswin32_i386_exception_handler := res;
  425. end;
  426. procedure install_exception_handlers;
  427. begin
  428. SetUnhandledExceptionFilter(@syswin32_i386_exception_handler);
  429. end;
  430. procedure remove_exception_handlers;
  431. begin
  432. SetUnhandledExceptionFilter(nil);
  433. end;
  434. {$endif not FPC_USE_WIN32_SEH}
  435. {$else not cpui386 (Processor specific !!)}
  436. procedure install_exception_handlers;
  437. begin
  438. end;
  439. procedure remove_exception_handlers;
  440. begin
  441. end;
  442. {$endif Set_i386_Exception_handler}
  443. {$ifdef FPC_SECTION_THREADVARS}
  444. function fpc_tls_add(addr: pointer): pointer; assembler; nostackframe;
  445. [public,alias: 'FPC_TLS_ADD']; compilerproc;
  446. asm
  447. sub $tls_data_start,%eax
  448. cmpb $0,IsLibrary
  449. mov _tls_index,%ecx
  450. jnz .L1
  451. mov %fs:(0x2c),%edx
  452. add (%edx,%ecx,4),%eax
  453. ret
  454. .L1:
  455. push %ebx
  456. mov %eax,%ebx
  457. call GetLastError
  458. push %eax { save LastError }
  459. push _tls_index
  460. call TlsGetValue
  461. test %eax,%eax
  462. jnz .L2
  463. { This can happen when a thread existed before DLL was loaded,
  464. or if DisableThreadLibraryCalls was called. }
  465. call SysAllocateThreadVars
  466. mov $0x1000000,%eax
  467. call InitThread
  468. push _tls_index
  469. call TlsGetValue
  470. .L2:
  471. add %eax,%ebx
  472. call SetLastError { restore (value is on stack) }
  473. mov %ebx,%eax
  474. pop %ebx
  475. end;
  476. {$endif FPC_SECTION_THREADVARS}
  477. function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
  478. type
  479. tdosheader = packed record
  480. e_magic : word;
  481. e_cblp : word;
  482. e_cp : word;
  483. e_crlc : word;
  484. e_cparhdr : word;
  485. e_minalloc : word;
  486. e_maxalloc : word;
  487. e_ss : word;
  488. e_sp : word;
  489. e_csum : word;
  490. e_ip : word;
  491. e_cs : word;
  492. e_lfarlc : word;
  493. e_ovno : word;
  494. e_res : array[0..3] of word;
  495. e_oemid : word;
  496. e_oeminfo : word;
  497. e_res2 : array[0..9] of word;
  498. e_lfanew : longint;
  499. end;
  500. tpeheader = packed record
  501. PEMagic : longint;
  502. Machine : word;
  503. NumberOfSections : word;
  504. TimeDateStamp : longint;
  505. PointerToSymbolTable : longint;
  506. NumberOfSymbols : longint;
  507. SizeOfOptionalHeader : word;
  508. Characteristics : word;
  509. Magic : word;
  510. MajorLinkerVersion : byte;
  511. MinorLinkerVersion : byte;
  512. SizeOfCode : longint;
  513. SizeOfInitializedData : longint;
  514. SizeOfUninitializedData : longint;
  515. AddressOfEntryPoint : longint;
  516. BaseOfCode : longint;
  517. BaseOfData : longint;
  518. ImageBase : longint;
  519. SectionAlignment : longint;
  520. FileAlignment : longint;
  521. MajorOperatingSystemVersion : word;
  522. MinorOperatingSystemVersion : word;
  523. MajorImageVersion : word;
  524. MinorImageVersion : word;
  525. MajorSubsystemVersion : word;
  526. MinorSubsystemVersion : word;
  527. Reserved1 : longint;
  528. SizeOfImage : longint;
  529. SizeOfHeaders : longint;
  530. CheckSum : longint;
  531. Subsystem : word;
  532. DllCharacteristics : word;
  533. SizeOfStackReserve : longint;
  534. SizeOfStackCommit : longint;
  535. SizeOfHeapReserve : longint;
  536. SizeOfHeapCommit : longint;
  537. LoaderFlags : longint;
  538. NumberOfRvaAndSizes : longint;
  539. DataDirectory : array[1..$80] of byte;
  540. end;
  541. begin
  542. result:=tpeheader((pointer(getmodulehandle(nil))+(tdosheader(pointer(getmodulehandle(nil))^).e_lfanew))^).SizeOfStackReserve;
  543. end;
  544. initialization
  545. { get some helpful informations }
  546. GetStartupInfo(@startupinfo);
  547. { some misc Win32 stuff }
  548. if not IsLibrary then
  549. FPCSysInstance^:=getmodulehandle(nil);
  550. MainInstance:=FPCSysInstance^;
  551. { pass dummy value }
  552. StackLength := CheckInitialStkLen($1000000);
  553. StackBottom := StackTop - StackLength;
  554. cmdshow:=startupinfo.wshowwindow;
  555. { Setup heap and threading, these may be already initialized from TLS callback }
  556. if not Assigned(CurrentTM.BeginThread) then
  557. begin
  558. InitHeap;
  559. InitSystemThreads;
  560. end;
  561. SysInitExceptions;
  562. { setup fastmove stuff }
  563. fpc_cpucodeinit;
  564. initunicodestringmanager;
  565. InitWin32Widestrings;
  566. SysInitStdIO;
  567. { Arguments }
  568. setup_arguments;
  569. InitSystemDynLibs;
  570. { Reset IO Error }
  571. InOutRes:=0;
  572. ProcessID := GetCurrentProcessID;
  573. DispCallByIDProc:=@DoDispCallByIDError;
  574. finalization
  575. WinFinalizeSystem;
  576. end.