system.pas 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804
  1. {
  2. $Id$
  3. ****************************************************************************
  4. This file is part of the Free Pascal run time library.
  5. Copyright (c) 1999-2002 by Free Pascal development team
  6. Free Pascal - OS/2 runtime library
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. ****************************************************************************}
  13. unit {$ifdef VER1_0}sysos2{$else}System{$endif};
  14. interface
  15. {$ifdef SYSTEMDEBUG}
  16. {$define SYSTEMEXCEPTIONDEBUG}
  17. {.$define IODEBUG}
  18. {.$define DEBUGENVIRONMENT}
  19. {.$define DEBUGARGUMENTS}
  20. {$endif SYSTEMDEBUG}
  21. { $DEFINE OS2EXCEPTIONS}
  22. {$I systemh.inc}
  23. {$IFDEF OS2EXCEPTIONS}
  24. (* Types and constants for exception handler support *)
  25. type
  26. {x} PEXCEPTION_FRAME = ^TEXCEPTION_FRAME;
  27. {x} TEXCEPTION_FRAME = record
  28. {x} next : PEXCEPTION_FRAME;
  29. {x} handler : pointer;
  30. {x} end;
  31. {$ENDIF OS2EXCEPTIONS}
  32. const
  33. LineEnding = #13#10;
  34. { LFNSupport is defined separately below!!! }
  35. DirectorySeparator = '\';
  36. DriveSeparator = ':';
  37. PathSeparator = ';';
  38. { FileNameCaseSensitive is defined separately below!!! }
  39. MaxExitCode = 65535;
  40. MaxPathLen = 256;
  41. type Tos=(osDOS,osOS2,osDPMI);
  42. const os_mode: Tos = osOS2;
  43. first_meg: pointer = nil;
  44. {$IFDEF OS2EXCEPTIONS}
  45. {x} System_exception_frame : PEXCEPTION_FRAME =nil;
  46. {$ENDIF OS2EXCEPTIONS}
  47. type TByteArray = array [0..$ffff] of byte;
  48. PByteArray = ^TByteArray;
  49. TSysThreadIB = record
  50. TID,
  51. Priority,
  52. Version: cardinal;
  53. MCCount,
  54. MCForceFlag: word;
  55. end;
  56. PSysThreadIB = ^TSysThreadIB;
  57. TThreadInfoBlock = record
  58. PExChain,
  59. Stack,
  60. StackLimit: pointer;
  61. TIB2: PSysThreadIB;
  62. Version,
  63. Ordinal: cardinal;
  64. end;
  65. PThreadInfoBlock = ^TThreadInfoBlock;
  66. PPThreadInfoBlock = ^PThreadInfoBlock;
  67. TProcessInfoBlock = record
  68. PID,
  69. ParentPid,
  70. Handle: cardinal;
  71. Cmd,
  72. Env: PByteArray;
  73. Status,
  74. ProcType: cardinal;
  75. end;
  76. PProcessInfoBlock = ^TProcessInfoBlock;
  77. PPProcessInfoBlock = ^PProcessInfoBlock;
  78. const UnusedHandle=-1;
  79. StdInputHandle=0;
  80. StdOutputHandle=1;
  81. StdErrorHandle=2;
  82. LFNSupport: boolean = true;
  83. FileNameCaseSensitive: boolean = false;
  84. CtrlZMarksEOF: boolean = true; (* #26 is considered as end of file *)
  85. sLineBreak = LineEnding;
  86. DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsCRLF;
  87. var
  88. { C-compatible arguments and environment }
  89. argc : longint;
  90. argv : ppchar;
  91. envp : ppchar;
  92. EnvC: cardinal;
  93. (* Pointer to the block of environment variables - used e.g. in unit Dos. *)
  94. Environment: PChar;
  95. var
  96. (* Type / run mode of the current process: *)
  97. (* 0 .. full screen OS/2 session *)
  98. (* 1 .. DOS session *)
  99. (* 2 .. VIO windowable OS/2 session *)
  100. (* 3 .. Presentation Manager OS/2 session *)
  101. (* 4 .. detached (background) OS/2 process *)
  102. ApplicationType: cardinal;
  103. (* Is allocation of memory above 512 MB address limit allowed? Initialized *)
  104. (* during initialization of system unit according to capabilities of the *)
  105. (* underlying OS/2 version, can be overridden by user - heap is allocated *)
  106. (* for all threads, so the setting isn't declared as a threadvar and *)
  107. (* should be only changed at the beginning of the main thread if needed. *)
  108. UseHighMem: boolean;
  109. procedure SetDefaultOS2FileType (FType: ShortString);
  110. procedure SetDefaultOS2Creator (Creator: ShortString);
  111. implementation
  112. {$I system.inc}
  113. {****************************************************************************
  114. Miscellaneous related routines.
  115. ****************************************************************************}
  116. procedure system_exit;
  117. begin
  118. DosExit (1{process}, exitcode);
  119. end;
  120. {$ASMMODE ATT}
  121. function paramcount:longint;assembler;
  122. asm
  123. movl argc,%eax
  124. decl %eax
  125. end {['EAX']};
  126. function args:pointer;assembler;
  127. asm
  128. movl argv,%eax
  129. end {['EAX']};
  130. function paramstr(l:longint):string;
  131. var p:^Pchar;
  132. begin
  133. if (l>=0) and (l<=paramcount) then
  134. begin
  135. p:=args;
  136. paramstr:=strpas(p[l]);
  137. end
  138. else paramstr:='';
  139. end;
  140. procedure randomize;
  141. var
  142. dt: TSysDateTime;
  143. begin
  144. // Hmm... Lets use timer
  145. DosGetDateTime(dt);
  146. randseed:=dt.hour+(dt.minute shl 8)+(dt.second shl 16)+(dt.sec100 shl 32);
  147. end;
  148. {$ASMMODE ATT}
  149. {*****************************************************************************
  150. System unit initialization.
  151. ****************************************************************************}
  152. {****************************************************************************
  153. Error Message writing using messageboxes
  154. ****************************************************************************}
  155. type
  156. TWinMessageBox = function (Parent, Owner: cardinal;
  157. BoxText, BoxTitle: PChar; Identity, Style: cardinal): cardinal; cdecl;
  158. TWinInitialize = function (Options: cardinal): cardinal; cdecl;
  159. TWinCreateMsgQueue = function (Handle: cardinal; cmsg: longint): cardinal;
  160. cdecl;
  161. const
  162. ErrorBufferLength = 1024;
  163. mb_OK = $0000;
  164. mb_Error = $0040;
  165. mb_Moveable = $4000;
  166. MBStyle = mb_OK or mb_Error or mb_Moveable;
  167. WinInitialize: TWinInitialize = nil;
  168. WinCreateMsgQueue: TWinCreateMsgQueue = nil;
  169. WinMessageBox: TWinMessageBox = nil;
  170. EnvSize: cardinal = 0;
  171. var
  172. ErrorBuf: array [0..ErrorBufferLength] of char;
  173. ErrorLen: longint;
  174. PMWinHandle: cardinal;
  175. function ErrorWrite (var F: TextRec): integer;
  176. {
  177. An error message should always end with #13#10#13#10
  178. }
  179. var
  180. P: PChar;
  181. I: longint;
  182. begin
  183. if F.BufPos > 0 then
  184. begin
  185. if F.BufPos + ErrorLen > ErrorBufferLength then
  186. I := ErrorBufferLength - ErrorLen
  187. else
  188. I := F.BufPos;
  189. Move (F.BufPtr^, ErrorBuf [ErrorLen], I);
  190. Inc (ErrorLen, I);
  191. ErrorBuf [ErrorLen] := #0;
  192. end;
  193. if ErrorLen > 3 then
  194. begin
  195. P := @ErrorBuf [ErrorLen];
  196. for I := 1 to 4 do
  197. begin
  198. Dec (P);
  199. if not (P^ in [#10, #13]) then
  200. break;
  201. end;
  202. end;
  203. if ErrorLen = ErrorBufferLength then
  204. I := 4;
  205. if (I = 4) then
  206. begin
  207. WinMessageBox (0, 0, @ErrorBuf, PChar ('Error'), 0, MBStyle);
  208. ErrorLen := 0;
  209. end;
  210. F.BufPos := 0;
  211. ErrorWrite := 0;
  212. end;
  213. function ErrorClose (var F: TextRec): integer;
  214. begin
  215. if ErrorLen > 0 then
  216. begin
  217. WinMessageBox (0, 0, @ErrorBuf, PChar ('Error'), 0, MBStyle);
  218. ErrorLen := 0;
  219. end;
  220. ErrorLen := 0;
  221. ErrorClose := 0;
  222. end;
  223. function ErrorOpen (var F: TextRec): integer;
  224. begin
  225. TextRec(F).InOutFunc := @ErrorWrite;
  226. TextRec(F).FlushFunc := @ErrorWrite;
  227. TextRec(F).CloseFunc := @ErrorClose;
  228. ErrorOpen := 0;
  229. end;
  230. procedure AssignError (var T: Text);
  231. begin
  232. Assign (T, '');
  233. TextRec (T).OpenFunc := @ErrorOpen;
  234. Rewrite (T);
  235. end;
  236. procedure SysInitStdIO;
  237. begin
  238. { Setup stdin, stdout and stderr, for GUI apps redirect stderr,stdout to be
  239. displayed in a messagebox }
  240. (*
  241. StdInputHandle := longint(GetStdHandle(cardinal(STD_INPUT_HANDLE)));
  242. StdOutputHandle := longint(GetStdHandle(cardinal(STD_OUTPUT_HANDLE)));
  243. StdErrorHandle := longint(GetStdHandle(cardinal(STD_ERROR_HANDLE)));
  244. if not IsConsole then
  245. begin
  246. if (DosLoadModule (nil, 0, 'PMWIN', PMWinHandle) = 0) and
  247. (DosQueryProcAddr (PMWinHandle, 789, nil, pointer (WinMessageBox)) = 0)
  248. and
  249. (DosQueryProcAddr (PMWinHandle, 763, nil, pointer (WinInitialize)) = 0)
  250. and
  251. (DosQueryProcAddr (PMWinHandle, 716, nil, pointer (WinCreateMsgQueue))
  252. = 0)
  253. then
  254. begin
  255. WinInitialize (0);
  256. WinCreateMsgQueue (0, 0);
  257. end
  258. else
  259. HandleError (2);
  260. AssignError (StdErr);
  261. AssignError (StdOut);
  262. Assign (Output, '');
  263. Assign (Input, '');
  264. end
  265. else
  266. begin
  267. *)
  268. OpenStdIO (Input, fmInput, StdInputHandle);
  269. OpenStdIO (Output, fmOutput, StdOutputHandle);
  270. OpenStdIO (ErrOutput, fmOutput, StdErrorHandle);
  271. OpenStdIO (StdOut, fmOutput, StdOutputHandle);
  272. OpenStdIO (StdErr, fmOutput, StdErrorHandle);
  273. (*
  274. end;
  275. *)
  276. end;
  277. function strcopy(dest,source : pchar) : pchar;assembler;
  278. var
  279. saveeax,saveesi,saveedi : longint;
  280. asm
  281. movl %edi,saveedi
  282. movl %esi,saveesi
  283. {$ifdef REGCALL}
  284. movl %eax,saveeax
  285. movl %edx,%edi
  286. {$else}
  287. movl source,%edi
  288. {$endif}
  289. testl %edi,%edi
  290. jz .LStrCopyDone
  291. leal 3(%edi),%ecx
  292. andl $-4,%ecx
  293. movl %edi,%esi
  294. subl %edi,%ecx
  295. {$ifdef REGCALL}
  296. movl %eax,%edi
  297. {$else}
  298. movl dest,%edi
  299. {$endif}
  300. jz .LStrCopyAligned
  301. .LStrCopyAlignLoop:
  302. movb (%esi),%al
  303. incl %edi
  304. incl %esi
  305. testb %al,%al
  306. movb %al,-1(%edi)
  307. jz .LStrCopyDone
  308. decl %ecx
  309. jnz .LStrCopyAlignLoop
  310. .balign 16
  311. .LStrCopyAligned:
  312. movl (%esi),%eax
  313. movl %eax,%edx
  314. leal 0x0fefefeff(%eax),%ecx
  315. notl %edx
  316. addl $4,%esi
  317. andl %edx,%ecx
  318. andl $0x080808080,%ecx
  319. jnz .LStrCopyEndFound
  320. movl %eax,(%edi)
  321. addl $4,%edi
  322. jmp .LStrCopyAligned
  323. .LStrCopyEndFound:
  324. testl $0x0ff,%eax
  325. jz .LStrCopyByte
  326. testl $0x0ff00,%eax
  327. jz .LStrCopyWord
  328. testl $0x0ff0000,%eax
  329. jz .LStrCopy3Bytes
  330. movl %eax,(%edi)
  331. jmp .LStrCopyDone
  332. .LStrCopy3Bytes:
  333. xorb %dl,%dl
  334. movw %ax,(%edi)
  335. movb %dl,2(%edi)
  336. jmp .LStrCopyDone
  337. .LStrCopyWord:
  338. movw %ax,(%edi)
  339. jmp .LStrCopyDone
  340. .LStrCopyByte:
  341. movb %al,(%edi)
  342. .LStrCopyDone:
  343. {$ifdef REGCALL}
  344. movl saveeax,%eax
  345. {$else}
  346. movl dest,%eax
  347. {$endif}
  348. movl saveedi,%edi
  349. movl saveesi,%esi
  350. end;
  351. {$ifdef HASTHREADVAR}
  352. threadvar
  353. {$else HASTHREADVAR}
  354. var
  355. {$endif HASTHREADVAR}
  356. DefaultCreator: ShortString;
  357. DefaultFileType: ShortString;
  358. procedure SetDefaultOS2FileType (FType: ShortString);
  359. begin
  360. {$WARNING Not implemented yet!}
  361. DefaultFileType := FType;
  362. end;
  363. procedure SetDefaultOS2Creator (Creator: ShortString);
  364. begin
  365. {$WARNING Not implemented yet!}
  366. DefaultCreator := Creator;
  367. end;
  368. procedure InitEnvironment;
  369. var env_count : longint;
  370. dos_env,cp : pchar;
  371. begin
  372. env_count:=0;
  373. cp:=environment;
  374. while cp ^ <> #0 do
  375. begin
  376. inc(env_count);
  377. while (cp^ <> #0) do inc(longint(cp)); { skip to NUL }
  378. inc(longint(cp)); { skip to next character }
  379. end;
  380. envp := sysgetmem((env_count+1) * sizeof(pchar));
  381. envc := env_count;
  382. if (envp = nil) then exit;
  383. cp:=environment;
  384. env_count:=0;
  385. while cp^ <> #0 do
  386. begin
  387. envp[env_count] := sysgetmem(strlen(cp)+1);
  388. strcopy(envp[env_count], cp);
  389. {$IfDef DEBUGENVIRONMENT}
  390. Writeln(stderr,'env ',env_count,' = "',envp[env_count],'"');
  391. {$EndIf}
  392. inc(env_count);
  393. while (cp^ <> #0) do
  394. inc(longint(cp)); { skip to NUL }
  395. inc(longint(cp)); { skip to next character }
  396. end;
  397. envp[env_count]:=nil;
  398. end;
  399. procedure InitArguments;
  400. var
  401. arglen,
  402. count : PtrInt;
  403. argstart,
  404. pc,arg : pchar;
  405. quote : char;
  406. argvlen : PtrInt;
  407. procedure allocarg(idx,len: PtrInt);
  408. var
  409. oldargvlen : PtrInt;
  410. begin
  411. if idx>=argvlen then
  412. begin
  413. oldargvlen:=argvlen;
  414. argvlen:=(idx+8) and (not 7);
  415. sysreallocmem(argv,argvlen*sizeof(pointer));
  416. fillchar(argv[oldargvlen],(argvlen-oldargvlen)*sizeof(pointer),0);
  417. end;
  418. { use realloc to reuse already existing memory }
  419. { always allocate, even if length is zero, since }
  420. { the arg. is still present! }
  421. { sysreallocmem(argv[idx],len+1);}
  422. ArgV [Idx] := SysAllocMem (Succ (Len));
  423. end;
  424. begin
  425. count:=0;
  426. argv:=nil;
  427. argvlen:=0;
  428. // Get argv[0]
  429. pc:=cmdline;
  430. Arglen:=0;
  431. repeat
  432. Inc(Arglen);
  433. until (pc[Arglen] = #0);
  434. allocarg(count,arglen);
  435. move(pc^,argv[count]^,arglen);
  436. { ReSetup cmdline variable }
  437. repeat
  438. Inc(Arglen);
  439. until (pc[Arglen]=#0);
  440. Inc(Arglen);
  441. pc:=GetMem(ArgLen);
  442. move(cmdline^, pc^, arglen);
  443. Arglen:=0;
  444. repeat
  445. Inc(Arglen);
  446. until (pc[Arglen]=#0);
  447. pc[Arglen]:=' '; // combine argv[0] and command line
  448. CmdLine:=pc;
  449. { process arguments }
  450. pc:=cmdline;
  451. {$IfDef DEBUGARGUMENTS}
  452. Writeln(stderr,'GetCommandLine is #',pc,'#');
  453. {$EndIf }
  454. while pc^<>#0 do
  455. begin
  456. { skip leading spaces }
  457. while pc^ in [#1..#32] do
  458. inc(pc);
  459. if pc^=#0 then
  460. break;
  461. { calc argument length }
  462. quote:=' ';
  463. argstart:=pc;
  464. arglen:=0;
  465. while (pc^<>#0) do
  466. begin
  467. case pc^ of
  468. #1..#32 :
  469. begin
  470. if quote<>' ' then
  471. inc(arglen)
  472. else
  473. break;
  474. end;
  475. '"' :
  476. begin
  477. if quote<>'''' then
  478. begin
  479. if pchar(pc+1)^<>'"' then
  480. begin
  481. if quote='"' then
  482. quote:=' '
  483. else
  484. quote:='"';
  485. end
  486. else
  487. inc(pc);
  488. end
  489. else
  490. inc(arglen);
  491. end;
  492. '''' :
  493. begin
  494. if quote<>'"' then
  495. begin
  496. if pchar(pc+1)^<>'''' then
  497. begin
  498. if quote='''' then
  499. quote:=' '
  500. else
  501. quote:='''';
  502. end
  503. else
  504. inc(pc);
  505. end
  506. else
  507. inc(arglen);
  508. end;
  509. else
  510. inc(arglen);
  511. end;
  512. inc(pc);
  513. end;
  514. { copy argument }
  515. { Don't copy the first one, it is already there.}
  516. If Count<>0 then
  517. begin
  518. allocarg(count,arglen);
  519. quote:=' ';
  520. pc:=argstart;
  521. arg:=argv[count];
  522. while (pc^<>#0) do
  523. begin
  524. case pc^ of
  525. #1..#32 :
  526. begin
  527. if quote<>' ' then
  528. begin
  529. arg^:=pc^;
  530. inc(arg);
  531. end
  532. else
  533. break;
  534. end;
  535. '"' :
  536. begin
  537. if quote<>'''' then
  538. begin
  539. if pchar(pc+1)^<>'"' then
  540. begin
  541. if quote='"' then
  542. quote:=' '
  543. else
  544. quote:='"';
  545. end
  546. else
  547. inc(pc);
  548. end
  549. else
  550. begin
  551. arg^:=pc^;
  552. inc(arg);
  553. end;
  554. end;
  555. '''' :
  556. begin
  557. if quote<>'"' then
  558. begin
  559. if pchar(pc+1)^<>'''' then
  560. begin
  561. if quote='''' then
  562. quote:=' '
  563. else
  564. quote:='''';
  565. end
  566. else
  567. inc(pc);
  568. end
  569. else
  570. begin
  571. arg^:=pc^;
  572. inc(arg);
  573. end;
  574. end;
  575. else
  576. begin
  577. arg^:=pc^;
  578. inc(arg);
  579. end;
  580. end;
  581. inc(pc);
  582. end;
  583. arg^:=#0;
  584. end;
  585. {$IfDef DEBUGARGUMENTS}
  586. Writeln(stderr,'dos arg ',count,' #',arglen,'#',argv[count],'#');
  587. {$EndIf}
  588. inc(count);
  589. end;
  590. { get argc and create an nil entry }
  591. argc:=count;
  592. allocarg(argc,0);
  593. { free unused memory }
  594. sysreallocmem(argv,(argc+1)*sizeof(pointer));
  595. end;
  596. function GetFileHandleCount: longint;
  597. var L1: longint;
  598. L2: cardinal;
  599. begin
  600. L1 := 0; (* Don't change the amount, just check. *)
  601. if DosSetRelMaxFH (L1, L2) <> 0 then GetFileHandleCount := 50
  602. else GetFileHandleCount := L2;
  603. end;
  604. var TIB: PThreadInfoBlock;
  605. PIB: PProcessInfoBlock;
  606. RC: cardinal;
  607. ErrStr: string;
  608. P: pointer;
  609. begin
  610. IsLibrary := FALSE;
  611. (* Initialize the amount of file handles *)
  612. FileHandleCount := GetFileHandleCount;
  613. DosGetInfoBlocks (@TIB, @PIB);
  614. StackBottom := TIB^.Stack;
  615. {Set type of application}
  616. ApplicationType := PIB^.ProcType;
  617. ProcessID := PIB^.PID;
  618. ThreadID := TIB^.TIB2^.TID;
  619. IsConsole := ApplicationType <> 3;
  620. ExitProc := nil;
  621. {Initialize the heap.}
  622. (* Logic is following:
  623. The heap is initially restricted to low address space (< 512 MB).
  624. If underlying OS/2 version allows using more than 512 MB per process
  625. (OS/2 WarpServer for e-Business, eComStation, possibly OS/2 Warp 4.0
  626. with FP13 and above as well), use of this high memory is allowed for
  627. future memory allocations at the end of System unit initialization.
  628. The consequences are that the compiled application can allocate more
  629. memory, but it must make sure to use direct DosAllocMem calls if it
  630. needs a memory block for some system API not supporting high memory.
  631. This is probably no problem for direct calls to these APIs, but
  632. there might be situations when a memory block needs to be passed
  633. to a 3rd party DLL which in turn calls such an API call. In case
  634. of problems usage of high memory can be turned off by setting
  635. UseHighMem to false - the program should change the setting at its
  636. very beginning (e.g. in initialization section of the first unit
  637. listed in the "uses" section) to avoid having preallocated memory
  638. from the high memory region before changing value of this variable. *)
  639. InitHeap;
  640. { ... and exceptions }
  641. SysInitExceptions;
  642. { ... and I/O }
  643. SysInitStdIO;
  644. { no I/O-Error }
  645. inoutres:=0;
  646. {Initialize environment (must be after InitHeap because allocates memory)}
  647. Environment := pointer (PIB^.Env);
  648. InitEnvironment;
  649. CmdLine := pointer (PIB^.Cmd);
  650. InitArguments;
  651. DefaultCreator := '';
  652. DefaultFileType := '';
  653. InitSystemThreads;
  654. {$ifdef HASVARIANT}
  655. initvariantmanager;
  656. {$endif HASVARIANT}
  657. {$IFDEF EXTDUMPGROW}
  658. { Int_HeapSize := high (cardinal);}
  659. {$ENDIF EXTDUMPGROW}
  660. RC := DosAllocMem (P, 4096, $403);
  661. if RC = 87 then
  662. (* Using of high memory address space (> 512 MB) *)
  663. (* is not supported on this system. *)
  664. UseHighMem := false
  665. else
  666. begin
  667. UseHighMem := true;
  668. if RC <> 0 then
  669. begin
  670. Str (RC, ErrStr);
  671. ErrStr := 'Error during heap initialization (DosAllocMem - ' + ErrStr + ')!!'#13#10;
  672. DosWrite (2, @ErrStr [1], Length (ErrStr), RC);
  673. HandleError (204);
  674. end
  675. else
  676. DosFreeMem (P);
  677. end;
  678. end.
  679. {
  680. $Log$
  681. Revision 1.86 2005-05-12 20:29:04 michael
  682. + Added maxpathlen constant (maximum length of filename path)
  683. Revision 1.85 2005/05/03 22:17:26 hajny
  684. * SysAllocMem used for ArgV [Idx] allocation again
  685. Revision 1.84 2005/05/01 13:01:03 peter
  686. use fillchar after reallocmem, fix taken from win32
  687. Revision 1.83 2005/04/03 21:10:59 hajny
  688. * EOF_CTRLZ conditional define replaced with CtrlZMarksEOF, #26 handling made more consistent (fix for bug 2453)
  689. Revision 1.82 2005/03/27 20:50:35 hajny
  690. * correction of previous mistyping
  691. Revision 1.81 2005/03/27 20:40:54 hajny
  692. * fix for allocarg
  693. Revision 1.80 2005/03/01 21:59:14 hajny
  694. * compilation fix
  695. Revision 1.79 2005/02/14 17:13:31 peter
  696. * truncate log
  697. Revision 1.78 2005/02/06 16:57:18 peter
  698. * threads for go32v2,os,emx,netware
  699. }