system.pas 20 KB

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