system.pp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  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. FPC Pascal system unit for the Win64 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 SYSTEMEXCEPTIONDEBUG}
  15. {$ifdef SYSTEMDEBUG}
  16. {$define SYSTEMEXCEPTIONDEBUG}
  17. {$endif SYSTEMDEBUG}
  18. {$define DISABLE_NO_THREAD_MANAGER}
  19. {$define HAS_WIDESTRINGMANAGER}
  20. {$ifdef FPC_USE_WIN64_SEH}
  21. {$define FPC_SYSTEM_HAS_RAISEEXCEPTION}
  22. {$define FPC_SYSTEM_HAS_RERAISE}
  23. {$endif FPC_USE_WIN64_SEH}
  24. { include system-independent routine headers }
  25. {$I systemh.inc}
  26. const
  27. LineEnding = #13#10;
  28. LFNSupport = true;
  29. DirectorySeparator = '\';
  30. DriveSeparator = ':';
  31. ExtensionSeparator = '.';
  32. PathSeparator = ';';
  33. AllowDirectorySeparators : set of char = ['\','/'];
  34. AllowDriveSeparators : set of char = [':'];
  35. { FileNameCaseSensitive and FileNameCasePreserving are defined separately below!!! }
  36. maxExitCode = 65535;
  37. MaxPathLen = 260;
  38. AllFilesMask = '*';
  39. type
  40. PEXCEPTION_FRAME = ^TEXCEPTION_FRAME;
  41. TEXCEPTION_FRAME = record
  42. next : PEXCEPTION_FRAME;
  43. handler : pointer;
  44. end;
  45. const
  46. { Default filehandles }
  47. UnusedHandle : THandle = THandle(-1);
  48. StdInputHandle : THandle = 0;
  49. StdOutputHandle : THandle = 0;
  50. StdErrorHandle : THandle = 0;
  51. System_exception_frame : PEXCEPTION_FRAME =nil;
  52. FileNameCaseSensitive : boolean = false;
  53. FileNameCasePreserving: boolean = true;
  54. CtrlZMarksEOF: boolean = true; (* #26 is considered as end of file *)
  55. sLineBreak = LineEnding;
  56. DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsCRLF;
  57. type
  58. TStartupInfo = record
  59. cb : longint;
  60. lpReserved : Pointer;
  61. lpDesktop : Pointer;
  62. lpTitle : Pointer;
  63. dwX : longint;
  64. dwY : longint;
  65. dwXSize : longint;
  66. dwYSize : longint;
  67. dwXCountChars : longint;
  68. dwYCountChars : longint;
  69. dwFillAttribute : longint;
  70. dwFlags : longint;
  71. wShowWindow : Word;
  72. cbReserved2 : Word;
  73. lpReserved2 : Pointer;
  74. hStdInput : THandle;
  75. hStdOutput : THandle;
  76. hStdError : THandle;
  77. end;
  78. var
  79. { C compatible arguments }
  80. argc : longint;
  81. argv : ppchar;
  82. { Win32 Info }
  83. startupinfo : tstartupinfo;
  84. StartupConsoleMode : dword;
  85. MainInstance : qword;
  86. cmdshow : longint;
  87. DLLreason : dword;
  88. DLLparam : PtrInt;
  89. const
  90. hprevinst: qword=0;
  91. type
  92. TDLL_Entry_Hook = procedure (dllparam : PtrInt);
  93. const
  94. Dll_Process_Detach_Hook : TDLL_Entry_Hook = nil;
  95. Dll_Thread_Attach_Hook : TDLL_Entry_Hook = nil;
  96. Dll_Thread_Detach_Hook : TDLL_Entry_Hook = nil;
  97. Const
  98. { it can be discussed whether fmShareDenyNone means read and write or read, write and delete, see
  99. also http://bugs.freepascal.org/view.php?id=8898, this allows users to configure the used
  100. value
  101. }
  102. fmShareDenyNoneFlags : DWord = 3;
  103. implementation
  104. var
  105. SysInstance : qword;public;
  106. {$ifdef FPC_USE_WIN64_SEH}
  107. function main_wrapper(arg: Pointer; proc: Pointer): ptrint; assembler; nostackframe;
  108. asm
  109. subq $40, %rsp
  110. .seh_stackalloc 40
  111. .seh_endprologue
  112. call %rdx { "arg" is passed in %rcx }
  113. nop { this nop is critical for exception handling }
  114. addq $40, %rsp
  115. .seh_handler __FPC_default_handler,@except,@unwind
  116. end;
  117. {$endif FPC_USE_WIN64_SEH}
  118. { include system independent routines }
  119. {$I system.inc}
  120. {*****************************************************************************
  121. System Dependent Exit code
  122. *****************************************************************************}
  123. {$ifndef FPC_USE_WIN64_SEH}
  124. procedure install_exception_handlers;forward;
  125. {$endif FPC_USE_WIN64_SEH}
  126. procedure PascalMain;stdcall;external name 'PASCALMAIN';
  127. { include code common with win32 }
  128. {$I syswin.inc}
  129. { TLS directory code }
  130. {$I systlsdir.inc}
  131. Procedure system_exit;
  132. begin
  133. { see comments in win32/system.pp about this logic }
  134. if IsLibrary then
  135. begin
  136. if DllInitState in [DLL_PROCESS_ATTACH,DLL_PROCESS_DETACH] then
  137. LongJmp(DLLBuf,1)
  138. else
  139. MainThreadIDWin32:=0;
  140. end;
  141. if not IsConsole then
  142. begin
  143. Close(stderr);
  144. Close(stdout);
  145. Close(erroutput);
  146. Close(Input);
  147. Close(Output);
  148. { what about Input and Output ?? PM }
  149. { now handled, FPK }
  150. end;
  151. { call exitprocess, with cleanup as required }
  152. ExitProcess(exitcode);
  153. end;
  154. var
  155. { old compilers emitted a reference to _fltused if a module contains
  156. floating type code so the linker could leave away floating point
  157. libraries or not. VC does this as well so we need to define this
  158. symbol as well (FK)
  159. }
  160. _fltused : int64;cvar;public;
  161. { value of the stack segment
  162. to check if the call stack can be written on exceptions }
  163. _SS : Cardinal;
  164. procedure Exe_entry;[public,alias:'_FPC_EXE_Entry'];
  165. begin
  166. IsLibrary:=false;
  167. { install the handlers for exe only ?
  168. or should we install them for DLL also ? (PM) }
  169. {$ifndef FPC_USE_WIN64_SEH}
  170. install_exception_handlers;
  171. {$endif FPC_USE_WIN64_SEH}
  172. ExitCode:=0;
  173. asm
  174. xorq %rax,%rax
  175. movw %ss,%ax
  176. movl %eax,_SS(%rip)
  177. movq %rbp,%rsi
  178. xorq %rbp,%rbp
  179. {$ifdef FPC_USE_WIN64_SEH}
  180. xor %rcx,%rcx
  181. lea PASCALMAIN(%rip),%rdx
  182. call main_wrapper
  183. {$else FPC_USE_WIN64_SEH}
  184. call PASCALMAIN
  185. {$endif FPC_USE_WIN64_SEH}
  186. movq %rsi,%rbp
  187. end ['RSI','RBP']; { <-- specifying RSI allows compiler to save/restore it properly }
  188. { if we pass here there was no error ! }
  189. system_exit;
  190. end;
  191. procedure _FPC_DLLMainCRTStartup(_hinstance : qword;_dllreason : dword;_dllparam:Pointer);stdcall;public name '_DLLMainCRTStartup';
  192. begin
  193. IsConsole:=true;
  194. sysinstance:=_hinstance;
  195. dllreason:=_dllreason;
  196. dllparam:=PtrInt(_dllparam);
  197. DLL_Entry;
  198. end;
  199. procedure _FPC_DLLWinMainCRTStartup(_hinstance : qword;_dllreason : dword;_dllparam:Pointer);stdcall;public name '_DLLWinMainCRTStartup';
  200. begin
  201. IsConsole:=false;
  202. sysinstance:=_hinstance;
  203. dllreason:=_dllreason;
  204. dllparam:=PtrInt(_dllparam);
  205. DLL_Entry;
  206. end;
  207. function is_prefetch(p : pointer) : boolean;
  208. var
  209. a : array[0..15] of byte;
  210. doagain : boolean;
  211. instrlo,instrhi,opcode : byte;
  212. i : longint;
  213. begin
  214. result:=false;
  215. { read memory savely without causing another exeception }
  216. if not(ReadProcessMemory(GetCurrentProcess,p,@a,sizeof(a),nil)) then
  217. exit;
  218. i:=0;
  219. doagain:=true;
  220. while doagain and (i<15) do
  221. begin
  222. opcode:=a[i];
  223. instrlo:=opcode and $f;
  224. instrhi:=opcode and $f0;
  225. case instrhi of
  226. { prefix? }
  227. $20,$30:
  228. doagain:=(instrlo and 7)=6;
  229. $60:
  230. doagain:=(instrlo and $c)=4;
  231. $f0:
  232. doagain:=instrlo in [0,2,3];
  233. $0:
  234. begin
  235. result:=(instrlo=$f) and (a[i+1] in [$d,$18]);
  236. exit;
  237. end;
  238. else
  239. doagain:=false;
  240. end;
  241. inc(i);
  242. end;
  243. end;
  244. //
  245. // Hardware exception handling
  246. //
  247. {$I seh64.inc}
  248. type
  249. TVectoredExceptionHandler = function (excep : PExceptionPointers) : Longint;
  250. function AddVectoredExceptionHandler(FirstHandler : DWORD;VectoredHandler : TVectoredExceptionHandler) : longint;
  251. external 'kernel32' name 'AddVectoredExceptionHandler';
  252. {$ifndef FPC_USE_WIN64_SEH}
  253. const
  254. MaxExceptionLevel = 16;
  255. exceptLevel : Byte = 0;
  256. var
  257. exceptRip : array[0..MaxExceptionLevel-1] of Int64;
  258. exceptError : array[0..MaxExceptionLevel-1] of Byte;
  259. resetFPU : array[0..MaxExceptionLevel-1] of Boolean;
  260. {$ifdef SYSTEMEXCEPTIONDEBUG}
  261. procedure DebugHandleErrorAddrFrame(error : longint; addr, frame : pointer);
  262. begin
  263. if IsConsole then
  264. begin
  265. write(stderr,'HandleErrorAddrFrame(error=',error);
  266. write(stderr,',addr=',hexstr(int64(addr),16));
  267. writeln(stderr,',frame=',hexstr(int64(frame),16),')');
  268. end;
  269. HandleErrorAddrFrame(error,addr,frame);
  270. end;
  271. {$endif SYSTEMEXCEPTIONDEBUG}
  272. procedure JumpToHandleErrorFrame;
  273. var
  274. rip, rbp : int64;
  275. error : longint;
  276. begin
  277. // save ebp
  278. asm
  279. movq (%rbp),%rax
  280. movq %rax,rbp
  281. end;
  282. if exceptLevel>0 then
  283. dec(exceptLevel);
  284. rip:=exceptRip[exceptLevel];
  285. error:=exceptError[exceptLevel];
  286. {$ifdef SYSTEMEXCEPTIONDEBUG}
  287. if IsConsole then
  288. writeln(stderr,'In JumpToHandleErrorFrame error=',error);
  289. {$endif SYSTEMEXCEPTIONDEBUG}
  290. if resetFPU[exceptLevel] then
  291. SysResetFPU;
  292. { build a fake stack }
  293. asm
  294. movq rbp,%r8
  295. movq rip,%rdx
  296. movl error,%ecx
  297. pushq rip
  298. movq rbp,%rbp // Change frame pointer
  299. {$ifdef SYSTEMEXCEPTIONDEBUG}
  300. jmpl DebugHandleErrorAddrFrame
  301. {$else not SYSTEMEXCEPTIONDEBUG}
  302. jmpl HandleErrorAddrFrame
  303. {$endif SYSTEMEXCEPTIONDEBUG}
  304. end;
  305. end;
  306. function syswin64_x86_64_exception_handler(excep : PExceptionPointers) : Longint;public;
  307. var
  308. res: longint;
  309. err: byte;
  310. must_reset_fpu: boolean;
  311. begin
  312. res:=EXCEPTION_CONTINUE_SEARCH;
  313. {$ifdef SYSTEMEXCEPTIONDEBUG}
  314. if IsConsole then
  315. Writeln(stderr,'syswin64_x86_64_exception_handler called');
  316. {$endif SYSTEMEXCEPTIONDEBUG}
  317. if excep^.ContextRecord^.SegSs=_SS then
  318. begin
  319. err := 0;
  320. must_reset_fpu := true;
  321. {$ifdef SYSTEMEXCEPTIONDEBUG}
  322. if IsConsole then Writeln(stderr,'Exception ',
  323. hexstr(excep^.ExceptionRecord^.ExceptionCode,8));
  324. {$endif SYSTEMEXCEPTIONDEBUG}
  325. case cardinal(excep^.ExceptionRecord^.ExceptionCode) of
  326. STATUS_INTEGER_DIVIDE_BY_ZERO,
  327. STATUS_FLOAT_DIVIDE_BY_ZERO :
  328. err := 200;
  329. STATUS_ARRAY_BOUNDS_EXCEEDED :
  330. begin
  331. err := 201;
  332. must_reset_fpu := false;
  333. end;
  334. STATUS_STACK_OVERFLOW :
  335. begin
  336. err := 202;
  337. must_reset_fpu := false;
  338. end;
  339. STATUS_FLOAT_OVERFLOW :
  340. err := 205;
  341. STATUS_FLOAT_DENORMAL_OPERAND,
  342. STATUS_FLOAT_UNDERFLOW :
  343. err := 206;
  344. { excep^.ContextRecord^.FloatSave.StatusWord := excep^.ContextRecord^.FloatSave.StatusWord and $ffffff00;}
  345. STATUS_FLOAT_INEXACT_RESULT,
  346. STATUS_FLOAT_INVALID_OPERATION,
  347. STATUS_FLOAT_STACK_CHECK :
  348. err := 207;
  349. STATUS_INTEGER_OVERFLOW :
  350. begin
  351. err := 215;
  352. must_reset_fpu := false;
  353. end;
  354. STATUS_ILLEGAL_INSTRUCTION:
  355. err := 216;
  356. STATUS_ACCESS_VIOLATION:
  357. { Athlon prefetch bug? }
  358. if is_prefetch(pointer(excep^.ContextRecord^.rip)) then
  359. begin
  360. { if yes, then retry }
  361. excep^.ExceptionRecord^.ExceptionCode := 0;
  362. res:=EXCEPTION_CONTINUE_EXECUTION;
  363. end
  364. else
  365. err := 216;
  366. STATUS_CONTROL_C_EXIT:
  367. err := 217;
  368. STATUS_PRIVILEGED_INSTRUCTION:
  369. begin
  370. err := 218;
  371. must_reset_fpu := false;
  372. end;
  373. else
  374. begin
  375. if ((excep^.ExceptionRecord^.ExceptionCode and SEVERITY_ERROR) = SEVERITY_ERROR) then
  376. err := 217
  377. else
  378. { pass through exceptions which aren't an error. The problem is that vectored handlers
  379. always are called before structured ones so we see also internal exceptions of libraries.
  380. I wonder if there is a better solution (FK)
  381. }
  382. res:=EXCEPTION_CONTINUE_SEARCH;
  383. end;
  384. end;
  385. if (err <> 0) and (exceptLevel < MaxExceptionLevel) then
  386. begin
  387. exceptRip[exceptLevel] := excep^.ContextRecord^.Rip;
  388. exceptError[exceptLevel] := err;
  389. resetFPU[exceptLevel] := must_reset_fpu;
  390. inc(exceptLevel);
  391. excep^.ContextRecord^.Rip := Int64(@JumpToHandleErrorFrame);
  392. excep^.ExceptionRecord^.ExceptionCode := 0;
  393. res := EXCEPTION_CONTINUE_EXECUTION;
  394. {$ifdef SYSTEMEXCEPTIONDEBUG}
  395. if IsConsole then begin
  396. writeln(stderr,'Exception Continue Exception set at ',
  397. hexstr(exceptRip[exceptLevel-1],16));
  398. writeln(stderr,'Rip changed to ',
  399. hexstr(int64(@JumpToHandleErrorFrame),16), ' error=', err);
  400. end;
  401. {$endif SYSTEMEXCEPTIONDEBUG}
  402. end;
  403. end;
  404. syswin64_x86_64_exception_handler := res;
  405. end;
  406. procedure install_exception_handlers;
  407. begin
  408. AddVectoredExceptionHandler(1,@syswin64_x86_64_exception_handler);
  409. end;
  410. {$endif ndef FPC_USE_WIN64_SEH}
  411. procedure LinkIn(p1,p2,p3: Pointer); inline;
  412. begin
  413. end;
  414. procedure _FPC_mainCRTStartup;stdcall;public name '_mainCRTStartup';
  415. begin
  416. IsConsole:=true;
  417. GetConsoleMode(GetStdHandle((Std_Input_Handle)),@StartupConsoleMode);
  418. {$ifdef FPC_USE_TLS_DIRECTORY}
  419. LinkIn(@_tls_used,@FreePascal_TLS_callback,@FreePascal_end_of_TLS_callback);
  420. {$endif FPC_USE_TLS_DIRECTORY}
  421. Exe_entry;
  422. end;
  423. procedure _FPC_WinMainCRTStartup;stdcall;public name '_WinMainCRTStartup';
  424. begin
  425. IsConsole:=false;
  426. {$ifdef FPC_USE_TLS_DIRECTORY}
  427. LinkIn(@_tls_used,@FreePascal_TLS_callback,@FreePascal_end_of_TLS_callback);
  428. {$endif FPC_USE_TLS_DIRECTORY}
  429. Exe_entry;
  430. end;
  431. {$ifdef FPC_SECTION_THREADVARS}
  432. function fpc_tls_add(addr: pointer): pointer; assembler; nostackframe;
  433. [public,alias: 'FPC_TLS_ADD']; compilerproc;
  434. asm
  435. sub $56,%rsp { 32 spill area + 16 local vars + 8 misalignment }
  436. .seh_stackalloc 56
  437. .seh_endprologue
  438. lea tls_data_start(%rip),%rax
  439. sub %rax,%rcx
  440. cmpb $0,IsLibrary(%rip)
  441. mov _tls_index(%rip),%eax
  442. jnz .L1
  443. mov %gs:(88),%rdx
  444. add (%rdx,%rax,8),%rcx
  445. mov %rcx,%rax
  446. jmp .L3
  447. .L1:
  448. mov %rcx,32(%rsp)
  449. call GetLastError
  450. mov %rax,40(%rsp) { save LastError }
  451. mov _tls_index(%rip),%ecx
  452. call TlsGetValue
  453. test %rax,%rax
  454. jnz .L2
  455. { This can happen when a thread existed before DLL was loaded,
  456. or if DisableThreadLibraryCalls was called. }
  457. call SysAllocateThreadVars
  458. mov $0x1000000,%rcx
  459. call InitThread
  460. mov _tls_index(%rip),%ecx
  461. call TlsGetValue
  462. .L2:
  463. add %rax,32(%rsp)
  464. mov 40(%rsp),%rcx
  465. call SetLastError
  466. mov 32(%rsp),%rax
  467. .L3:
  468. add $56,%rsp
  469. end;
  470. {$endif FPC_SECTION_THREADVARS}
  471. function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
  472. type
  473. tdosheader = packed record
  474. e_magic : word;
  475. e_cblp : word;
  476. e_cp : word;
  477. e_crlc : word;
  478. e_cparhdr : word;
  479. e_minalloc : word;
  480. e_maxalloc : word;
  481. e_ss : word;
  482. e_sp : word;
  483. e_csum : word;
  484. e_ip : word;
  485. e_cs : word;
  486. e_lfarlc : word;
  487. e_ovno : word;
  488. e_res : array[0..3] of word;
  489. e_oemid : word;
  490. e_oeminfo : word;
  491. e_res2 : array[0..9] of word;
  492. e_lfanew : longint;
  493. end;
  494. tpeheader = packed record
  495. PEMagic : longint;
  496. Machine : word;
  497. NumberOfSections : word;
  498. TimeDateStamp : longint;
  499. PointerToSymbolTable : longint;
  500. NumberOfSymbols : longint;
  501. SizeOfOptionalHeader : word;
  502. Characteristics : word;
  503. Magic : word;
  504. MajorLinkerVersion : byte;
  505. MinorLinkerVersion : byte;
  506. SizeOfCode : longint;
  507. SizeOfInitializedData : longint;
  508. SizeOfUninitializedData : longint;
  509. AddressOfEntryPoint : longint;
  510. BaseOfCode : longint;
  511. {$ifdef win32}
  512. BaseOfData : longint;
  513. {$endif win32}
  514. ImageBase : PtrInt;
  515. SectionAlignment : longint;
  516. FileAlignment : longint;
  517. MajorOperatingSystemVersion : word;
  518. MinorOperatingSystemVersion : word;
  519. MajorImageVersion : word;
  520. MinorImageVersion : word;
  521. MajorSubsystemVersion : word;
  522. MinorSubsystemVersion : word;
  523. Reserved1 : longint;
  524. SizeOfImage : longint;
  525. SizeOfHeaders : longint;
  526. CheckSum : longint;
  527. Subsystem : word;
  528. DllCharacteristics : word;
  529. SizeOfStackReserve : PtrInt;
  530. SizeOfStackCommit : PtrInt;
  531. SizeOfHeapReserve : PtrInt;
  532. SizeOfHeapCommit : PtrInt;
  533. LoaderFlags : longint;
  534. NumberOfRvaAndSizes : longint;
  535. DataDirectory : array[1..$80] of byte;
  536. end;
  537. begin
  538. result:=tpeheader((pointer(getmodulehandle(nil))+(tdosheader(pointer(getmodulehandle(nil))^).e_lfanew))^).SizeOfStackReserve;
  539. end;
  540. function GetExceptionPointer : Pointer; assembler;nostackframe;
  541. asm
  542. movq %gs:(8),%rax
  543. end;
  544. begin
  545. StackTop:=GetExceptionPointer;
  546. { pass dummy value }
  547. StackLength := CheckInitialStkLen($1000000);
  548. StackBottom := StackTop - StackLength;
  549. { get some helpful informations }
  550. GetStartupInfo(@startupinfo);
  551. { some misc Win32 stuff }
  552. if not IsLibrary then
  553. SysInstance:=getmodulehandle(nil);
  554. MainInstance:=SysInstance;
  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. initwidestringmanager;
  564. initunicodestringmanager;
  565. InitWin32Widestrings;
  566. SysInitStdIO;
  567. { Arguments }
  568. setup_arguments;
  569. { Reset IO Error }
  570. InOutRes:=0;
  571. ProcessID := GetCurrentProcessID;
  572. { Reset internal error variable }
  573. errno:=0;
  574. initvariantmanager;
  575. DispCallByIDProc:=@DoDispCallByIDError;
  576. end.