system.pp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  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. err := 200;
  332. STATUS_FLOAT_DIVIDE_BY_ZERO :
  333. err := 208;
  334. STATUS_ARRAY_BOUNDS_EXCEEDED :
  335. begin
  336. err := 201;
  337. must_reset_fpu := false;
  338. end;
  339. STATUS_STACK_OVERFLOW :
  340. begin
  341. err := 202;
  342. must_reset_fpu := false;
  343. end;
  344. STATUS_FLOAT_OVERFLOW :
  345. err := 205;
  346. STATUS_FLOAT_DENORMAL_OPERAND,
  347. STATUS_FLOAT_UNDERFLOW :
  348. err := 206;
  349. {excep^.ContextRecord^.FloatSave.StatusWord := excep^.ContextRecord^.FloatSave.StatusWord and $ffffff00;}
  350. STATUS_FLOAT_INEXACT_RESULT,
  351. STATUS_FLOAT_INVALID_OPERATION,
  352. STATUS_FLOAT_STACK_CHECK :
  353. err := 207;
  354. STATUS_INTEGER_OVERFLOW :
  355. begin
  356. err := 215;
  357. must_reset_fpu := false;
  358. end;
  359. STATUS_ILLEGAL_INSTRUCTION:
  360. { if we're testing sse support, simply set the flag and continue }
  361. if sse_check then
  362. begin
  363. os_supports_sse:=false;
  364. { skip the offending movaps %xmm7, %xmm6 instruction }
  365. inc(excep^.ContextRecord^.Eip,3);
  366. excep^.ExceptionRecord^.ExceptionCode := 0;
  367. res:=EXCEPTION_CONTINUE_EXECUTION;
  368. end
  369. else
  370. err := 216;
  371. STATUS_ACCESS_VIOLATION:
  372. { Athlon prefetch bug? }
  373. if is_prefetch(pointer(excep^.ContextRecord^.Eip)) then
  374. begin
  375. { if yes, then retry }
  376. excep^.ExceptionRecord^.ExceptionCode := 0;
  377. res:=EXCEPTION_CONTINUE_EXECUTION;
  378. end
  379. else
  380. err := 216;
  381. STATUS_CONTROL_C_EXIT:
  382. err := 217;
  383. STATUS_PRIVILEGED_INSTRUCTION:
  384. begin
  385. err := 218;
  386. must_reset_fpu := false;
  387. end;
  388. STATUS_FLOAT_MULTIPLE_FAULTS,
  389. STATUS_FLOAT_MULTIPLE_TRAPS:
  390. begin
  391. { dumping ExtendedRegisters and comparing with the actually value of mxcsr revealed 24 }
  392. TranslateMxcsr(excep^.ContextRecord^.ExtendedRegisters[24],ssecode);
  393. {$ifdef SYSTEMEXCEPTIONDEBUG}
  394. if IsConsole then
  395. Writeln(stderr,'MXSR: ',hexstr(excep^.ContextRecord^.ExtendedRegisters[24], 2),' SSECODE: ',ssecode);
  396. {$endif SYSTEMEXCEPTIONDEBUG}
  397. err:=-ssecode;
  398. end;
  399. else
  400. begin
  401. if ((excep^.ExceptionRecord^.ExceptionCode and SEVERITY_ERROR) = SEVERITY_ERROR) then
  402. err := 217
  403. else
  404. err := 255;
  405. end;
  406. end;
  407. if (err <> 0) and (exceptLevel < MaxExceptionLevel) then begin
  408. exceptEip[exceptLevel] := excep^.ContextRecord^.Eip;
  409. exceptError[exceptLevel] := err;
  410. resetFPU[exceptLevel] := must_reset_fpu;
  411. inc(exceptLevel);
  412. excep^.ContextRecord^.Eip := Longint(@JumpToHandleErrorFrame);
  413. excep^.ExceptionRecord^.ExceptionCode := 0;
  414. res := EXCEPTION_CONTINUE_EXECUTION;
  415. {$ifdef SYSTEMEXCEPTIONDEBUG}
  416. if IsConsole then begin
  417. writeln(stderr,'Exception Continue Exception set at ',
  418. hexstr(exceptEip[exceptLevel],8));
  419. writeln(stderr,'Eip changed to ',
  420. hexstr(longint(@JumpToHandleErrorFrame),8), ' error=', err);
  421. end;
  422. {$endif SYSTEMEXCEPTIONDEBUG}
  423. end;
  424. end;
  425. syswin32_i386_exception_handler := res;
  426. end;
  427. procedure install_exception_handlers;
  428. begin
  429. SetUnhandledExceptionFilter(@syswin32_i386_exception_handler);
  430. end;
  431. procedure remove_exception_handlers;
  432. begin
  433. SetUnhandledExceptionFilter(nil);
  434. end;
  435. {$endif not FPC_USE_WIN32_SEH}
  436. {$else not cpui386 (Processor specific !!)}
  437. procedure install_exception_handlers;
  438. begin
  439. end;
  440. procedure remove_exception_handlers;
  441. begin
  442. end;
  443. {$endif Set_i386_Exception_handler}
  444. {$ifdef FPC_SECTION_THREADVARS}
  445. function fpc_tls_add(addr: pointer): pointer; assembler; nostackframe;
  446. [public,alias: 'FPC_TLS_ADD']; compilerproc;
  447. asm
  448. sub $tls_data_start,%eax
  449. cmpb $0,IsLibrary
  450. mov _tls_index,%ecx
  451. jnz .L1
  452. mov %fs:(0x2c),%edx
  453. add (%edx,%ecx,4),%eax
  454. ret
  455. .L1:
  456. push %ebx
  457. mov %eax,%ebx
  458. call GetLastError
  459. push %eax { save LastError }
  460. push _tls_index
  461. call TlsGetValue
  462. test %eax,%eax
  463. jnz .L2
  464. { This can happen when a thread existed before DLL was loaded,
  465. or if DisableThreadLibraryCalls was called. }
  466. call SysAllocateThreadVars
  467. mov $0x1000000,%eax
  468. call InitThread
  469. push _tls_index
  470. call TlsGetValue
  471. .L2:
  472. add %eax,%ebx
  473. call SetLastError { restore (value is on stack) }
  474. mov %ebx,%eax
  475. pop %ebx
  476. end;
  477. {$endif FPC_SECTION_THREADVARS}
  478. function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
  479. type
  480. tdosheader = packed record
  481. e_magic : word;
  482. e_cblp : word;
  483. e_cp : word;
  484. e_crlc : word;
  485. e_cparhdr : word;
  486. e_minalloc : word;
  487. e_maxalloc : word;
  488. e_ss : word;
  489. e_sp : word;
  490. e_csum : word;
  491. e_ip : word;
  492. e_cs : word;
  493. e_lfarlc : word;
  494. e_ovno : word;
  495. e_res : array[0..3] of word;
  496. e_oemid : word;
  497. e_oeminfo : word;
  498. e_res2 : array[0..9] of word;
  499. e_lfanew : longint;
  500. end;
  501. tpeheader = packed record
  502. PEMagic : longint;
  503. Machine : word;
  504. NumberOfSections : word;
  505. TimeDateStamp : longint;
  506. PointerToSymbolTable : longint;
  507. NumberOfSymbols : longint;
  508. SizeOfOptionalHeader : word;
  509. Characteristics : word;
  510. Magic : word;
  511. MajorLinkerVersion : byte;
  512. MinorLinkerVersion : byte;
  513. SizeOfCode : longint;
  514. SizeOfInitializedData : longint;
  515. SizeOfUninitializedData : longint;
  516. AddressOfEntryPoint : longint;
  517. BaseOfCode : longint;
  518. BaseOfData : longint;
  519. ImageBase : longint;
  520. SectionAlignment : longint;
  521. FileAlignment : longint;
  522. MajorOperatingSystemVersion : word;
  523. MinorOperatingSystemVersion : word;
  524. MajorImageVersion : word;
  525. MinorImageVersion : word;
  526. MajorSubsystemVersion : word;
  527. MinorSubsystemVersion : word;
  528. Reserved1 : longint;
  529. SizeOfImage : longint;
  530. SizeOfHeaders : longint;
  531. CheckSum : longint;
  532. Subsystem : word;
  533. DllCharacteristics : word;
  534. SizeOfStackReserve : longint;
  535. SizeOfStackCommit : longint;
  536. SizeOfHeapReserve : longint;
  537. SizeOfHeapCommit : longint;
  538. LoaderFlags : longint;
  539. NumberOfRvaAndSizes : longint;
  540. DataDirectory : array[1..$80] of byte;
  541. end;
  542. begin
  543. result:=tpeheader((pointer(getmodulehandle(nil))+(tdosheader(pointer(getmodulehandle(nil))^).e_lfanew))^).SizeOfStackReserve;
  544. end;
  545. initialization
  546. { get some helpful informations }
  547. GetStartupInfo(@startupinfo);
  548. { some misc Win32 stuff }
  549. if not IsLibrary then
  550. FPCSysInstance^:=getmodulehandle(nil);
  551. MainInstance:=FPCSysInstance^;
  552. { pass dummy value }
  553. StackLength := CheckInitialStkLen($1000000);
  554. StackBottom := StackTop - StackLength;
  555. cmdshow:=startupinfo.wshowwindow;
  556. { Setup heap and threading, these may be already initialized from TLS callback }
  557. if not Assigned(CurrentTM.BeginThread) then
  558. begin
  559. InitHeap;
  560. InitSystemThreads;
  561. end;
  562. SysInitExceptions;
  563. { setup fastmove stuff }
  564. fpc_cpucodeinit;
  565. initunicodestringmanager;
  566. InitWin32Widestrings;
  567. SysInitStdIO;
  568. { Arguments }
  569. setup_arguments;
  570. InitSystemDynLibs;
  571. { Reset IO Error }
  572. InOutRes:=0;
  573. ProcessID := GetCurrentProcessID;
  574. DispCallByIDProc:=@DoDispCallByIDError;
  575. finalization
  576. WinFinalizeSystem;
  577. end.