system.pas 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242
  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. {Link the startup code.}
  16. {$ifdef VER1_0}
  17. {$l prt1.oo2}
  18. {$else}
  19. {$l prt1.o}
  20. {$endif}
  21. {$ifdef SYSTEMDEBUG}
  22. {$define SYSTEMEXCEPTIONDEBUG}
  23. {$endif SYSTEMDEBUG}
  24. { $DEFINE OS2EXCEPTIONS}
  25. {$I systemh.inc}
  26. {$IFDEF OS2EXCEPTIONS}
  27. (* Types and constants for exception handler support *)
  28. type
  29. {x} PEXCEPTION_FRAME = ^TEXCEPTION_FRAME;
  30. {x} TEXCEPTION_FRAME = record
  31. {x} next : PEXCEPTION_FRAME;
  32. {x} handler : pointer;
  33. {x} end;
  34. {$ENDIF OS2EXCEPTIONS}
  35. {$I heaph.inc}
  36. {Platform specific information}
  37. const
  38. LineEnding = #13#10;
  39. { LFNSupport is defined separately below!!! }
  40. DirectorySeparator = '\';
  41. DriveSeparator = ':';
  42. PathSeparator = ';';
  43. { FileNameCaseSensitive is defined separately below!!! }
  44. {$IFDEF OS2EXCEPTIONS}
  45. {x} System_exception_frame : PEXCEPTION_FRAME =nil;
  46. {$ENDIF OS2EXCEPTIONS}
  47. type Tos=(osDOS,osOS2,osDPMI);
  48. var os_mode:Tos;
  49. type TByteArray = array [0..$ffff] of byte;
  50. PByteArray = ^TByteArray;
  51. TSysThreadIB = record
  52. TID,
  53. Priority,
  54. Version: cardinal;
  55. MCCount,
  56. MCForceFlag: word;
  57. end;
  58. PSysThreadIB = ^TSysThreadIB;
  59. TThreadInfoBlock = record
  60. PExChain,
  61. Stack,
  62. StackLimit: pointer;
  63. TIB2: PSysThreadIB;
  64. Version,
  65. Ordinal: cardinal;
  66. end;
  67. PThreadInfoBlock = ^TThreadInfoBlock;
  68. PPThreadInfoBlock = ^PThreadInfoBlock;
  69. TProcessInfoBlock = record
  70. PID,
  71. ParentPid,
  72. Handle: cardinal;
  73. Cmd,
  74. Env: PByteArray;
  75. Status,
  76. ProcType: cardinal;
  77. end;
  78. PProcessInfoBlock = ^TProcessInfoBlock;
  79. PPProcessInfoBlock = ^PProcessInfoBlock;
  80. const UnusedHandle=$ffff;
  81. StdInputHandle=0;
  82. StdOutputHandle=1;
  83. StdErrorHandle=2;
  84. LFNSupport: boolean = true;
  85. FileNameCaseSensitive: boolean = false;
  86. sLineBreak = LineEnding;
  87. DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsCRLF;
  88. var
  89. { C-compatible arguments and environment }
  90. argc : longint;external name '_argc';
  91. argv : ppchar;external name '_argv';
  92. envp : ppchar;external name '_environ';
  93. EnvC: cardinal; external name '_envc';
  94. (* Pointer to the block of environment variables - used e.g. in unit Dos. *)
  95. Environment: PChar;
  96. var
  97. (* Type / run mode of the current process: *)
  98. (* 0 .. full screen OS/2 session *)
  99. (* 1 .. DOS session *)
  100. (* 2 .. VIO windowable OS/2 session *)
  101. (* 3 .. Presentation Manager OS/2 session *)
  102. (* 4 .. detached (background) OS/2 process *)
  103. ApplicationType: cardinal;
  104. implementation
  105. {$I system.inc}
  106. var
  107. heap_base: pointer; external name '__heap_base';
  108. heap_brk: pointer; external name '__heap_brk';
  109. heap_end: pointer; external name '__heap_end';
  110. (* Maximum heap size - only used if heap is allocated as continuous block. *)
  111. {$IFDEF CONTHEAP}
  112. BrkLimit: cardinal;
  113. {$ENDIF CONTHEAP}
  114. procedure DosGetInfoBlocks (PATIB: PPThreadInfoBlock;
  115. PAPIB: PPProcessInfoBlock); cdecl;
  116. external 'DOSCALLS' index 312;
  117. function DosLoadModule (ObjName: PChar; ObjLen: cardinal; DLLName: PChar;
  118. var Handle: cardinal): longint; cdecl;
  119. external 'DOSCALLS' index 318;
  120. function DosQueryProcAddr (Handle, Ordinal: cardinal; ProcName: PChar;
  121. var Address: pointer): longint; cdecl;
  122. external 'DOSCALLS' index 321;
  123. function DosSetRelMaxFH (var ReqCount, CurMaxFH: longint): longint; cdecl;
  124. external 'DOSCALLS' index 382;
  125. function DosSetCurrentDir (Name:PChar): longint; cdecl;
  126. external 'DOSCALLS' index 255;
  127. procedure DosQueryCurrentDisk(var DiskNum:longint;var Logical:longint); cdecl;
  128. external 'DOSCALLS' index 275;
  129. function DosSetDefaultDisk (DiskNum:longint): longint; cdecl;
  130. external 'DOSCALLS' index 220;
  131. { This is not real prototype, but is close enough }
  132. { for us (the 2nd parameter is actually a pointer }
  133. { to a structure). }
  134. function DosCreateDir( Name : pchar; p : pointer): longint; cdecl;
  135. external 'DOSCALLS' index 270;
  136. function DosDeleteDir( Name : pchar) : longint; cdecl;
  137. external 'DOSCALLS' index 226;
  138. function DosQueryCurrentDir(DiskNum:longint;var Buffer;
  139. var BufLen:longint):longint; cdecl;
  140. external 'DOSCALLS' index 274;
  141. function DosMove(OldFile,NewFile:PChar):longint; cdecl;
  142. external 'DOSCALLS' index 271;
  143. function DosDelete(FileName:PChar):longint; cdecl;
  144. external 'DOSCALLS' index 259;
  145. procedure DosExit(Action, Result: longint); cdecl;
  146. external 'DOSCALLS' index 234;
  147. {This is the correct way to call external assembler procedures.}
  148. procedure syscall; external name '___SYSCALL';
  149. { converts an OS/2 error code to a TP compatible error }
  150. { code. Same thing exists under most other supported }
  151. { systems. }
  152. { Only call for OS/2 DLL imported routines }
  153. Procedure Errno2InOutRes;
  154. Begin
  155. { errors 1..18 are the same as in DOS }
  156. case InOutRes of
  157. { simple offset to convert these error codes }
  158. { exactly like the error codes in Win32 }
  159. 19..31 : InOutRes := InOutRes + 131;
  160. { gets a bit more complicated ... }
  161. 32..33 : InOutRes := 5;
  162. 38 : InOutRes := 100;
  163. 39 : InOutRes := 101;
  164. 112 : InOutRes := 101;
  165. 110 : InOutRes := 5;
  166. 114 : InOutRes := 6;
  167. 290 : InOutRes := 290;
  168. end;
  169. { all other cases ... we keep the same error code }
  170. end;
  171. {$IFDEF OS2EXCEPTIONS}
  172. (*
  173. The operating system defines a class of error conditions called exceptions, and specifies the default actions that are taken when these exceptions occur. The system default action in most cases is to terminate the thread that caused the exception.
  174. Exception values have the following 32-bit format:
  175. 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  176. 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
  177. ÚÄÄÄÂÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  178. ³Sev³C³ Facility ³ Code ³
  179. ÀÄÄÄÁÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  180. Sev Severity code. Possible values are described in the following list:
  181. 00 Success
  182. 01 Informational
  183. 10 Warning
  184. 11 Error
  185. C Customer code flag.
  186. Facility Facility code.
  187. Code Facility's status code.
  188. Exceptions that are specific to OS/2 Version 2.X (for example, XCPT_SIGNAL) have a facility code of 1.
  189. System exceptions include both synchronous and asynchronous exceptions. Synchronous exceptions are caused by events that are internal to a thread's execution. For example, synchronous exceptions could be caused by invalid parameters, or by a thread's request to end its own execution.
  190. Asynchronous exceptions are caused by events that are external to a thread's execution. For example, an asynchronous exception can be caused by a user's entering a Ctrl+C or Ctrl+Break key sequence, or by a process' issuing DosKillProcess to end the execution of another process.
  191. The Ctrl+Break and Ctrl+C exceptions are also known as signals, or as signal exceptions.
  192. The following tables show the symbolic names of system exceptions, their numerical values, and related information fields.
  193. Portable, Non-Fatal, Software-Generated Exceptions
  194. ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄ¿
  195. ³Exception Name ³Value ³
  196. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄ´
  197. ³XCPT_GUARD_PAGE_VIOLATION ³0x80000001³
  198. ³ ExceptionInfo[0] - R/W flag ³ ³
  199. ³ ExceptionInfo[1] - FaultAddr ³ ³
  200. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄ´
  201. ³XCPT_UNABLE_TO_GROW_STACK ³0x80010001³
  202. ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÙ
  203. Portable, Fatal, Hardware-Generated Exceptions
  204. ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  205. ³Exception Name ³Value ³Related Trap ³
  206. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  207. ³XCPT_ACCESS_VIOLATION ³0xC0000005³0x09, 0x0B, ³
  208. ³ ExceptionInfo[0] - Flags ³ ³0x0C, 0x0D, ³
  209. ³ XCPT_UNKNOWN_ACCESS 0x0 ³ ³0x0E ³
  210. ³ XCPT_READ_ACCESS 0x1 ³ ³ ³
  211. ³ XCPT_WRITE_ACCESS 0x2 ³ ³ ³
  212. ³ XCPT_EXECUTE_ACCESS 0x4 ³ ³ ³
  213. ³ XCPT_SPACE_ACCESS 0x8 ³ ³ ³
  214. ³ XCPT_LIMIT_ACCESS 0x10 ³ ³ ³
  215. ³ ExceptionInfo[1] - FaultAddr ³ ³ ³
  216. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  217. ³XCPT_INTEGER_DIVIDE_BY_ZERO ³0xC000009B³0 ³
  218. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  219. ³XCPT_FLOAT_DIVIDE_BY_ZERO ³0xC0000095³0x10 ³
  220. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  221. ³XCPT_FLOAT_INVALID_OPERATION ³0xC0000097³0x10 ³
  222. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  223. ³XCPT_ILLEGAL_INSTRUCTION ³0xC000001C³0x06 ³
  224. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  225. ³XCPT_PRIVILEGED_INSTRUCTION ³0xC000009D³0x0D ³
  226. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  227. ³XCPT_INTEGER_OVERFLOW ³0xC000009C³0x04 ³
  228. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  229. ³XCPT_FLOAT_OVERFLOW ³0xC0000098³0x10 ³
  230. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  231. ³XCPT_FLOAT_UNDERFLOW ³0xC000009A³0x10 ³
  232. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  233. ³XCPT_FLOAT_DENORMAL_OPERAND ³0xC0000094³0x10 ³
  234. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  235. ³XCPT_FLOAT_INEXACT_RESULT ³0xC0000096³0x10 ³
  236. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  237. ³XCPT_FLOAT_STACK_CHECK ³0xC0000099³0x10 ³
  238. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  239. ³XCPT_DATATYPE_MISALIGNMENT ³0xC000009E³0x11 ³
  240. ³ ExceptionInfo[0] - R/W flag ³ ³ ³
  241. ³ ExceptionInfo[1] - Alignment ³ ³ ³
  242. ³ ExceptionInfo[2] - FaultAddr ³ ³ ³
  243. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  244. ³XCPT_BREAKPOINT ³0xC000009F³0x03 ³
  245. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  246. ³XCPT_SINGLE_STEP ³0xC00000A0³0x01 ³
  247. ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  248. Portable, Fatal, Software-Generated Exceptions
  249. ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  250. ³Exception Name ³Value ³Related Trap ³
  251. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  252. ³XCPT_IN_PAGE_ERROR ³0xC0000006³0x0E ³
  253. ³ ExceptionInfo[0] - FaultAddr ³ ³ ³
  254. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  255. ³XCPT_PROCESS_TERMINATE ³0xC0010001³ ³
  256. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  257. ³XCPT_ASYNC_PROCESS_TERMINATE ³0xC0010002³ ³
  258. ³ ExceptionInfo[0] - TID of ³ ³ ³
  259. ³ terminating thread ³ ³ ³
  260. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  261. ³XCPT_NONCONTINUABLE_EXCEPTION ³0xC0000024³ ³
  262. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  263. ³XCPT_INVALID_DISPOSITION ³0xC0000025³ ³
  264. ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  265. Non-Portable, Fatal Exceptions
  266. ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  267. ³Exception Name ³Value ³Related Trap ³
  268. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  269. ³XCPT_INVALID_LOCK_SEQUENCE ³0xC000001D³ ³
  270. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄ´
  271. ³XCPT_ARRAY_BOUNDS_EXCEEDED ³0xC0000093³0x05 ³
  272. ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  273. Unwind Operation Exceptions
  274. ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄ¿
  275. ³Exception Name ³Value ³
  276. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄ´
  277. ³XCPT_UNWIND ³0xC0000026³
  278. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄ´
  279. ³XCPT_BAD_STACK ³0xC0000027³
  280. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄ´
  281. ³XCPT_INVALID_UNWIND_TARGET ³0xC0000028³
  282. ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÙ
  283. Fatal Signal Exceptions
  284. ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄ¿
  285. ³Exception Name ³Value ³
  286. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄ´
  287. ³XCPT_SIGNAL ³0xC0010003³
  288. ³ ExceptionInfo[ 0 ] - Signal ³ ³
  289. ³ Number ³ ³
  290. ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÙ
  291. *)
  292. {$ENDIF OS2EXCEPTIONS}
  293. {****************************************************************************
  294. Miscellaneous related routines.
  295. ****************************************************************************}
  296. procedure system_exit;
  297. begin
  298. DosExit(1{process}, exitcode);
  299. end;
  300. {$ASMMODE ATT}
  301. function paramcount:longint;assembler;
  302. asm
  303. movl argc,%eax
  304. decl %eax
  305. end ['EAX'];
  306. function args:pointer;assembler;
  307. asm
  308. movl argv,%eax
  309. end ['EAX'];
  310. function paramstr(l:longint):string;
  311. var p:^Pchar;
  312. begin
  313. if L = 0 then
  314. begin
  315. GetMem (P, 260);
  316. p[0] := #0; { in case of error, initialize to empty string }
  317. {$ASMMODE INTEL}
  318. asm
  319. mov edx, P
  320. mov ecx, 260
  321. mov eax, 7F33h
  322. call syscall { error handle already with empty string }
  323. end ['eax', 'ecx', 'edx'];
  324. ParamStr := StrPas (PChar (P));
  325. FreeMem (P, 260);
  326. end
  327. else
  328. if (l>0) and (l<=paramcount) then
  329. begin
  330. p:=args;
  331. paramstr:=strpas(p[l]);
  332. end
  333. else paramstr:='';
  334. end;
  335. procedure randomize; assembler;
  336. asm
  337. mov ah, 2Ch
  338. call syscall
  339. mov word ptr [randseed], cx
  340. mov word ptr [randseed + 2], dx
  341. end ['eax', 'ecx', 'edx'];
  342. {$ASMMODE ATT}
  343. {****************************************************************************
  344. Heap management releated routines.
  345. ****************************************************************************}
  346. { this function allows to extend the heap by calling
  347. syscall $7f00 resizes the brk area}
  348. function sbrk(size:longint):pointer;
  349. {$IFDEF DUMPGROW}
  350. var
  351. L: longword;
  352. begin
  353. WriteLn ('Trying to grow heap by ', Size, ' to ', HeapSize + Size);
  354. {$IFDEF CONTHEAP}
  355. WriteLn ('BrkLimit is ', BrkLimit);
  356. {$ENDIF CONTHEAP}
  357. asm
  358. movl size,%edx
  359. movw $0x7f00,%ax
  360. call syscall { result directly in EAX }
  361. inc eax { Result in EAX, -1 = error (has to be transformed to 0) }
  362. jz .LSbrk_End
  363. dec eax { No error - back to previous value }
  364. .LSbrk_End:
  365. mov %eax,L
  366. end ['eax', 'edx'];
  367. WriteLn ('New heap at ', L);
  368. Sbrk := pointer (L);
  369. end;
  370. {$ELSE DUMPGROW}
  371. assembler;
  372. asm
  373. movl size,%edx
  374. movw $0x7f00,%ax
  375. call syscall
  376. inc %eax { Result in EAX, -1 = error (has to be transformed to 0) }
  377. jz .LSbrk_End
  378. dec %eax { No error - back to previous value }
  379. .LSbrk_End:
  380. end ['eax', 'edx'];
  381. {$ENDIF DUMPGROW}
  382. function getheapstart:pointer;assembler;
  383. asm
  384. movl heap_base,%eax
  385. end ['EAX'];
  386. function getheapsize:longint;assembler;
  387. asm
  388. movl heap_brk,%eax
  389. end ['EAX'];
  390. {$i heap.inc}
  391. {****************************************************************************
  392. Low Level File Routines
  393. ****************************************************************************}
  394. procedure allowslash(p:Pchar);
  395. {Allow slash as backslash.}
  396. var i:longint;
  397. begin
  398. for i:=0 to strlen(p) do
  399. if p[i]='/' then p[i]:='\';
  400. end;
  401. procedure do_close(h:longint);
  402. begin
  403. { Only three standard handles under real OS/2 }
  404. if h>2 then
  405. begin
  406. asm
  407. pushl %ebx
  408. movb $0x3e,%ah
  409. movl h,%ebx
  410. call syscall
  411. jnc .Lnoerror { error code? }
  412. movw %ax, InOutRes { yes, then set InOutRes }
  413. .Lnoerror:
  414. popl %ebx
  415. end ['eax'];
  416. end;
  417. end;
  418. procedure do_erase(p:Pchar);
  419. begin
  420. allowslash(p);
  421. inoutres:=DosDelete(p);
  422. end;
  423. procedure do_rename(p1,p2:Pchar);
  424. begin
  425. allowslash(p1);
  426. allowslash(p2);
  427. inoutres:=DosMove(p1, p2);
  428. end;
  429. function do_read(h,addr,len:longint):longint; assembler;
  430. asm
  431. movl len,%ecx
  432. movl addr,%edx
  433. movl h,%ebx
  434. movb $0x3f,%ah
  435. call syscall
  436. jnc .LDOSREAD1
  437. movw %ax,inoutres;
  438. xorl %eax,%eax
  439. .LDOSREAD1:
  440. end ['eax', 'ebx', 'ecx', 'edx'];
  441. function do_write(h,addr,len:longint) : longint; assembler;
  442. asm
  443. xorl %eax,%eax
  444. cmpl $0,len { 0 bytes to write is undefined behavior }
  445. jz .LDOSWRITE1
  446. movl len,%ecx
  447. movl addr,%edx
  448. movl h,%ebx
  449. movb $0x40,%ah
  450. call syscall
  451. jnc .LDOSWRITE1
  452. movw %ax,inoutres;
  453. .LDOSWRITE1:
  454. end ['eax', 'ebx', 'ecx', 'edx'];
  455. function do_filepos(handle:longint): longint; assembler;
  456. asm
  457. movw $0x4201,%ax
  458. movl handle,%ebx
  459. xorl %edx,%edx
  460. call syscall
  461. jnc .LDOSFILEPOS
  462. movw %ax,inoutres;
  463. xorl %eax,%eax
  464. .LDOSFILEPOS:
  465. end ['eax', 'ebx', 'ecx', 'edx'];
  466. procedure do_seek(handle,pos:longint); assembler;
  467. asm
  468. movw $0x4200,%ax
  469. movl handle,%ebx
  470. movl pos,%edx
  471. call syscall
  472. jnc .LDOSSEEK1
  473. movw %ax,inoutres;
  474. .LDOSSEEK1:
  475. end ['eax', 'ebx', 'ecx', 'edx'];
  476. function do_seekend(handle:longint):longint; assembler;
  477. asm
  478. movw $0x4202,%ax
  479. movl handle,%ebx
  480. xorl %edx,%edx
  481. call syscall
  482. jnc .Lset_at_end1
  483. movw %ax,inoutres;
  484. xorl %eax,%eax
  485. .Lset_at_end1:
  486. end ['eax', 'ebx', 'ecx', 'edx'];
  487. function do_filesize(handle:longint):longint;
  488. var aktfilepos:longint;
  489. begin
  490. aktfilepos:=do_filepos(handle);
  491. do_filesize:=do_seekend(handle);
  492. do_seek(handle,aktfilepos);
  493. end;
  494. procedure do_truncate(handle,pos:longint); assembler;
  495. asm
  496. (* DOS function 40h isn't safe for this according to EMX documentation *)
  497. movl $0x7F25,%eax
  498. movl Handle,%ebx
  499. movl Pos,%edx
  500. call syscall
  501. incl %eax
  502. movl %ecx, %eax
  503. jnz .LTruncate1 { compare the value of EAX to verify error }
  504. (* File position is undefined after truncation, move to the end. *)
  505. movl $0x4202,%eax
  506. movl Handle,%ebx
  507. movl $0,%edx
  508. call syscall
  509. jnc .LTruncate2
  510. .LTruncate1:
  511. movw %ax,inoutres;
  512. .LTruncate2:
  513. end ['eax', 'ebx', 'ecx', 'edx'];
  514. const
  515. FileHandleCount: longint = 20;
  516. function Increase_File_Handle_Count: boolean;
  517. var Err: word;
  518. L1, L2: longint;
  519. begin
  520. L1 := 10;
  521. if DosSetRelMaxFH (L1, L2) <> 0 then
  522. Increase_File_Handle_Count := false
  523. else
  524. if L2 > FileHandleCount then
  525. begin
  526. FileHandleCount := L2;
  527. Increase_File_Handle_Count := true;
  528. end
  529. else
  530. Increase_File_Handle_Count := false;
  531. end;
  532. procedure do_open(var f;p:pchar;flags:longint);
  533. {
  534. filerec and textrec have both handle and mode as the first items so
  535. they could use the same routine for opening/creating.
  536. when (flags and $100) the file will be append
  537. when (flags and $1000) the file will be truncate/rewritten
  538. when (flags and $10000) there is no check for close (needed for textfiles)
  539. }
  540. var Action: longint;
  541. begin
  542. allowslash(p);
  543. { close first if opened }
  544. if ((flags and $10000)=0) then
  545. begin
  546. case filerec(f).mode of
  547. fminput,fmoutput,fminout : Do_Close(filerec(f).handle);
  548. fmclosed:;
  549. else
  550. begin
  551. inoutres:=102; {not assigned}
  552. exit;
  553. end;
  554. end;
  555. end;
  556. { reset file handle }
  557. filerec(f).handle := UnusedHandle;
  558. Action := 0;
  559. { convert filemode to filerec modes }
  560. case (flags and 3) of
  561. 0 : filerec(f).mode:=fminput;
  562. 1 : filerec(f).mode:=fmoutput;
  563. 2 : filerec(f).mode:=fminout;
  564. end;
  565. if (flags and $1000)<>0 then
  566. Action := $50000; (* Create / replace *)
  567. { empty name is special }
  568. if p[0]=#0 then
  569. begin
  570. case FileRec(f).mode of
  571. fminput :
  572. FileRec(f).Handle:=StdInputHandle;
  573. fminout, { this is set by rewrite }
  574. fmoutput :
  575. FileRec(f).Handle:=StdOutputHandle;
  576. fmappend :
  577. begin
  578. FileRec(f).Handle:=StdOutputHandle;
  579. FileRec(f).mode:=fmoutput; {fool fmappend}
  580. end;
  581. end;
  582. exit;
  583. end;
  584. Action := Action or (Flags and $FF);
  585. (* DenyNone if sharing not specified. *)
  586. if Flags and 112 = 0 then
  587. Action := Action or 64;
  588. asm
  589. pushl %ebx
  590. movl $0x7f2b, %eax
  591. movl Action, %ecx
  592. movl p, %edx
  593. call syscall
  594. cmpl $0xffffffff, %eax
  595. jnz .LOPEN1
  596. movw %cx, InOutRes
  597. movw UnusedHandle, %ax
  598. .LOPEN1:
  599. movl f,%edx { Warning : This assumes Handle is first }
  600. movw %ax,(%edx) { field of FileRec }
  601. popl %ebx
  602. end ['eax', 'ecx', 'edx'];
  603. if (InOutRes = 4) and Increase_File_Handle_Count then
  604. (* Trying again after increasing amount of file handles *)
  605. asm
  606. movl $0x7f2b, %eax
  607. movl Action, %ecx
  608. movl p, %edx
  609. call syscall
  610. cmpl $0xffffffff, %eax
  611. jnz .LOPEN2
  612. movw %cx, InOutRes
  613. movw UnusedHandle, %ax
  614. .LOPEN2:
  615. movl f,%edx
  616. movw %ax,(%edx)
  617. end ['eax', 'ecx', 'edx'];
  618. { for systems that have more handles }
  619. if FileRec (F).Handle > FileHandleCount then
  620. FileHandleCount := FileRec (F).Handle;
  621. if ((Flags and $100) <> 0) and
  622. (FileRec (F).Handle <> UnusedHandle) then
  623. begin
  624. do_seekend (FileRec (F).Handle);
  625. FileRec (F).Mode := fmOutput; {fool fmappend}
  626. end;
  627. end;
  628. {$ASMMODE INTEL}
  629. function do_isdevice (Handle: longint): boolean; assembler;
  630. (*
  631. var HT, Attr: longint;
  632. begin
  633. if os_mode = osOS2 then
  634. begin
  635. if DosQueryHType (Handle, HT, Attr) <> 0 then HT := 1;
  636. end
  637. else
  638. *)
  639. asm
  640. mov ebx, Handle
  641. mov eax, 4400h
  642. call syscall
  643. mov eax, 1
  644. jc @IsDevEnd
  645. test edx, 80h { verify if it is a file }
  646. jnz @IsDevEnd
  647. dec eax { nope, so result is zero }
  648. @IsDevEnd:
  649. end ['eax', 'ebx', 'edx'];
  650. {$ASMMODE ATT}
  651. {*****************************************************************************
  652. UnTyped File Handling
  653. *****************************************************************************}
  654. {$i file.inc}
  655. {*****************************************************************************
  656. Typed File Handling
  657. *****************************************************************************}
  658. {$i typefile.inc}
  659. {*****************************************************************************
  660. Text File Handling
  661. *****************************************************************************}
  662. {$DEFINE EOF_CTRLZ}
  663. {$i text.inc}
  664. {****************************************************************************
  665. Directory related routines.
  666. ****************************************************************************}
  667. {*****************************************************************************
  668. Directory Handling
  669. *****************************************************************************}
  670. procedure MkDir (const S: string);[IOCHECK];
  671. var buffer:array[0..255] of char;
  672. Rc : word;
  673. begin
  674. If (s='') or (InOutRes <> 0) then
  675. exit;
  676. move(s[1],buffer,length(s));
  677. buffer[length(s)]:=#0;
  678. allowslash(Pchar(@buffer));
  679. Rc := DosCreateDir(buffer,nil);
  680. if Rc <> 0 then
  681. begin
  682. InOutRes := Rc;
  683. Errno2Inoutres;
  684. end;
  685. end;
  686. procedure rmdir(const s : string);[IOCHECK];
  687. var buffer:array[0..255] of char;
  688. Rc : word;
  689. begin
  690. if (s = '.' ) then
  691. InOutRes := 16;
  692. If (s='') or (InOutRes <> 0) then
  693. exit;
  694. move(s[1],buffer,length(s));
  695. buffer[length(s)]:=#0;
  696. allowslash(Pchar(@buffer));
  697. Rc := DosDeleteDir(buffer);
  698. if Rc <> 0 then
  699. begin
  700. InOutRes := Rc;
  701. Errno2Inoutres;
  702. end;
  703. end;
  704. {$ASMMODE INTEL}
  705. procedure ChDir (const S: string);[IOCheck];
  706. var RC: longint;
  707. Buffer: array [0..255] of char;
  708. begin
  709. If (s='') or (InOutRes <> 0) then exit;
  710. if (Length (S) >= 2) and (S [2] = ':') then
  711. begin
  712. RC := DosSetDefaultDisk ((Ord (S [1]) and not ($20)) - $40);
  713. if RC <> 0 then
  714. InOutRes := RC
  715. else
  716. if Length (S) > 2 then
  717. begin
  718. Move (S [1], Buffer, Length (S));
  719. Buffer [Length (S)] := #0;
  720. AllowSlash (PChar (@Buffer));
  721. RC := DosSetCurrentDir (@Buffer);
  722. if RC <> 0 then
  723. begin
  724. InOutRes := RC;
  725. Errno2InOutRes;
  726. end;
  727. end;
  728. end else begin
  729. Move (S [1], Buffer, Length (S));
  730. Buffer [Length (S)] := #0;
  731. AllowSlash (PChar (@Buffer));
  732. RC := DosSetCurrentDir (@Buffer);
  733. if RC <> 0 then
  734. begin
  735. InOutRes:= RC;
  736. Errno2InOutRes;
  737. end;
  738. end;
  739. end;
  740. {$ASMMODE ATT}
  741. procedure GetDir (DriveNr: byte; var Dir: ShortString);
  742. {Written by Michael Van Canneyt.}
  743. var sof: Pchar;
  744. i:byte;
  745. l, l2: Longint;
  746. begin
  747. Dir [4] := #0;
  748. { Used in case the specified drive isn't available }
  749. sof:=pchar(@dir[4]);
  750. { dir[1..3] will contain '[drivenr]:\', but is not }
  751. { supplied by DOS, so we let dos string start at }
  752. { dir[4] }
  753. { Get dir from drivenr : 0=default, 1=A etc... }
  754. l:=255-3;
  755. InOutRes:=DosQueryCurrentDir(DriveNr, sof^, l);
  756. { Now Dir should be filled with directory in ASCIIZ, }
  757. { starting from dir[4] }
  758. dir[0]:=#3;
  759. dir[2]:=':';
  760. dir[3]:='\';
  761. i:=4;
  762. {Conversion to Pascal string }
  763. while (dir[i]<>#0) do
  764. begin
  765. { convert path name to DOS }
  766. if dir[i]='/' then
  767. dir[i]:='\';
  768. dir[0]:=char(i);
  769. inc(i);
  770. end;
  771. { upcase the string (FPC function) }
  772. if drivenr<>0 then { Drive was supplied. We know it }
  773. dir[1]:=chr(64+drivenr)
  774. else
  775. begin
  776. { We need to get the current drive from DOS function 19H }
  777. { because the drive was the default, which can be unknown }
  778. DosQueryCurrentDisk(l, l2);
  779. dir[1]:=chr(64+l);
  780. end;
  781. if not (FileNameCaseSensitive) then dir:=upcase(dir);
  782. end;
  783. {*****************************************************************************
  784. System unit initialization.
  785. ****************************************************************************}
  786. {****************************************************************************
  787. Error Message writing using messageboxes
  788. ****************************************************************************}
  789. type
  790. TWinMessageBox = function (Parent, Owner: cardinal;
  791. BoxText, BoxTitle: PChar; Identity, Style: cardinal): cardinal; cdecl;
  792. TWinInitialize = function (Options: cardinal): cardinal; cdecl;
  793. TWinCreateMsgQueue = function (Handle: cardinal; cmsg: longint): cardinal;
  794. cdecl;
  795. const
  796. ErrorBufferLength = 1024;
  797. mb_OK = $0000;
  798. mb_Error = $0040;
  799. mb_Moveable = $4000;
  800. MBStyle = mb_OK or mb_Error or mb_Moveable;
  801. WinInitialize: TWinInitialize = nil;
  802. WinCreateMsgQueue: TWinCreateMsgQueue = nil;
  803. WinMessageBox: TWinMessageBox = nil;
  804. EnvSize: cardinal = 0;
  805. var
  806. ErrorBuf: array [0..ErrorBufferLength] of char;
  807. ErrorLen: longint;
  808. PMWinHandle: cardinal;
  809. function ErrorWrite (var F: TextRec): integer;
  810. {
  811. An error message should always end with #13#10#13#10
  812. }
  813. var
  814. P: PChar;
  815. I: longint;
  816. begin
  817. if F.BufPos > 0 then
  818. begin
  819. if F.BufPos + ErrorLen > ErrorBufferLength then
  820. I := ErrorBufferLength - ErrorLen
  821. else
  822. I := F.BufPos;
  823. Move (F.BufPtr^, ErrorBuf [ErrorLen], I);
  824. Inc (ErrorLen, I);
  825. ErrorBuf [ErrorLen] := #0;
  826. end;
  827. if ErrorLen > 3 then
  828. begin
  829. P := @ErrorBuf [ErrorLen];
  830. for I := 1 to 4 do
  831. begin
  832. Dec (P);
  833. if not (P^ in [#10, #13]) then
  834. break;
  835. end;
  836. end;
  837. if ErrorLen = ErrorBufferLength then
  838. I := 4;
  839. if (I = 4) then
  840. begin
  841. WinMessageBox (0, 0, @ErrorBuf, PChar ('Error'), 0, MBStyle);
  842. ErrorLen := 0;
  843. end;
  844. F.BufPos := 0;
  845. ErrorWrite := 0;
  846. end;
  847. function ErrorClose (var F: TextRec): integer;
  848. begin
  849. if ErrorLen > 0 then
  850. begin
  851. WinMessageBox (0, 0, @ErrorBuf, PChar ('Error'), 0, MBStyle);
  852. ErrorLen := 0;
  853. end;
  854. ErrorLen := 0;
  855. ErrorClose := 0;
  856. end;
  857. function ErrorOpen (var F: TextRec): integer;
  858. begin
  859. TextRec(F).InOutFunc := @ErrorWrite;
  860. TextRec(F).FlushFunc := @ErrorWrite;
  861. TextRec(F).CloseFunc := @ErrorClose;
  862. ErrorOpen := 0;
  863. end;
  864. procedure AssignError (var T: Text);
  865. begin
  866. Assign (T, '');
  867. TextRec (T).OpenFunc := @ErrorOpen;
  868. Rewrite (T);
  869. end;
  870. procedure SysInitStdIO;
  871. begin
  872. { Setup stdin, stdout and stderr, for GUI apps redirect stderr,stdout to be
  873. displayed in a messagebox }
  874. (*
  875. StdInputHandle := longint(GetStdHandle(cardinal(STD_INPUT_HANDLE)));
  876. StdOutputHandle := longint(GetStdHandle(cardinal(STD_OUTPUT_HANDLE)));
  877. StdErrorHandle := longint(GetStdHandle(cardinal(STD_ERROR_HANDLE)));
  878. if not IsConsole then
  879. begin
  880. if (DosLoadModule (nil, 0, 'PMWIN', PMWinHandle) = 0) and
  881. (DosQueryProcAddr (PMWinHandle, 789, nil, pointer (WinMessageBox)) = 0)
  882. and
  883. (DosQueryProcAddr (PMWinHandle, 763, nil, pointer (WinInitialize)) = 0)
  884. and
  885. (DosQueryProcAddr (PMWinHandle, 716, nil, pointer (WinCreateMsgQueue))
  886. = 0)
  887. then
  888. begin
  889. WinInitialize (0);
  890. WinCreateMsgQueue (0, 0);
  891. end
  892. else
  893. HandleError (2);
  894. AssignError (StdErr);
  895. AssignError (StdOut);
  896. Assign (Output, '');
  897. Assign (Input, '');
  898. end
  899. else
  900. begin
  901. *)
  902. OpenStdIO (Input, fmInput, StdInputHandle);
  903. OpenStdIO (Output, fmOutput, StdOutputHandle);
  904. OpenStdIO (StdOut, fmOutput, StdOutputHandle);
  905. OpenStdIO (StdErr, fmOutput, StdErrorHandle);
  906. (*
  907. end;
  908. *)
  909. end;
  910. function GetFileHandleCount: longint;
  911. var L1, L2: longint;
  912. begin
  913. L1 := 0; (* Don't change the amount, just check. *)
  914. if DosSetRelMaxFH (L1, L2) <> 0 then GetFileHandleCount := 50
  915. else GetFileHandleCount := L2;
  916. end;
  917. var TIB: PThreadInfoBlock;
  918. PIB: PProcessInfoBlock;
  919. begin
  920. IsLibrary := FALSE;
  921. os_mode:=OsOs2;
  922. {$ASMMODE INTEL}
  923. asm
  924. {Enable the brk area by initializing it with the initial heap size.}
  925. mov eax, 7F01h
  926. mov edx, heap_brk
  927. add edx, heap_base
  928. call syscall
  929. cmp eax, -1
  930. jnz @heapok
  931. push dword 204
  932. call HandleError
  933. @heapok:
  934. {$IFDEF CONTHEAP}
  935. { Find out brk limit }
  936. mov eax, 7F02h
  937. mov ecx, 3
  938. call syscall
  939. jcxz @heaplimitknown
  940. mov eax, 0
  941. @heaplimitknown:
  942. mov BrkLimit, eax
  943. {$ELSE CONTHEAP}
  944. { Change sbrk behaviour to allocate arbitrary (non-contiguous) memory blocks }
  945. mov eax, 7F0Fh
  946. mov ecx, 0Ch
  947. mov edx, 8
  948. call syscall
  949. {$ENDIF CONTHEAP}
  950. end;
  951. {Now request, if we are running under DOS,
  952. read-access to the first meg. of memory.}
  953. (* Initialize the amount of file handles *)
  954. FileHandleCount := GetFileHandleCount;
  955. DosGetInfoBlocks (@TIB, @PIB);
  956. StackBottom := cardinal (TIB^.Stack);
  957. Environment := pointer (PIB^.Env);
  958. ApplicationType := PIB^.ProcType;
  959. IsConsole := ApplicationType <> 3;
  960. exitproc:=nil;
  961. {Initialize the heap.}
  962. initheap;
  963. { ... and exceptions }
  964. SysInitExceptions;
  965. { ... and I/O }
  966. SysInitStdIO;
  967. { no I/O-Error }
  968. inoutres:=0;
  969. {$ifdef HASVARIANT}
  970. initvariantmanager;
  971. {$endif HASVARIANT}
  972. {$IFDEF DUMPGROW}
  973. {$IFDEF CONTHEAP}
  974. WriteLn ('Initial brk size is ', GetHeapSize);
  975. WriteLn ('Brk limit is ', BrkLimit);
  976. {$ENDIF CONTHEAP}
  977. {$ENDIF DUMPGROW}
  978. end.
  979. {
  980. $Log$
  981. Revision 1.44 2003-10-12 18:07:30 hajny
  982. * wrong use of Intel syntax
  983. Revision 1.43 2003/10/12 17:59:40 hajny
  984. * wrong use of Intel syntax
  985. Revision 1.42 2003/10/12 17:52:28 hajny
  986. * wrong use of Intel syntax
  987. Revision 1.41 2003/10/12 10:45:36 hajny
  988. * sbrk error handling corrected
  989. Revision 1.40 2003/10/07 21:26:35 hajny
  990. * stdcall fixes and asm routines cleanup
  991. Revision 1.39 2003/10/06 16:58:27 yuri
  992. * Another set of native functions.
  993. Revision 1.38 2003/10/06 14:22:40 yuri
  994. * Some emx code removed. Now withous so stupid error as with dos ;)
  995. Revision 1.37 2003/10/04 08:30:59 yuri
  996. * at&t syntax instead of intel syntax was used
  997. Revision 1.36 2003/10/03 21:46:41 peter
  998. * stdcall fixes
  999. Revision 1.35 2003/10/01 18:42:49 yuri
  1000. * Unclosed comment
  1001. Revision 1.34 2003/09/29 18:39:59 hajny
  1002. * append fix applied to GO32v2, OS/2 and EMX
  1003. Revision 1.33 2003/09/27 11:52:36 peter
  1004. * sbrk returns pointer
  1005. Revision 1.32 2003/03/30 09:20:30 hajny
  1006. * platform extension unification
  1007. Revision 1.31 2003/01/15 22:16:12 hajny
  1008. * default sharing mode changed to DenyNone
  1009. Revision 1.30 2002/12/15 22:41:41 hajny
  1010. * First_Meg fixed + Environment initialization under Dos
  1011. Revision 1.29 2002/12/08 16:39:58 hajny
  1012. - WriteLn in GUI mode support commented out until fixed
  1013. Revision 1.28 2002/12/07 19:17:14 hajny
  1014. * GetEnv correction, better PM support, ...
  1015. Revision 1.27 2002/11/17 22:31:02 hajny
  1016. * type corrections (longint x cardinal)
  1017. Revision 1.26 2002/10/27 14:29:00 hajny
  1018. * heap management (hopefully) fixed
  1019. Revision 1.25 2002/10/14 19:39:17 peter
  1020. * threads unit added for thread support
  1021. Revision 1.24 2002/10/13 09:28:45 florian
  1022. + call to initvariantmanager inserted
  1023. Revision 1.23 2002/09/07 16:01:25 peter
  1024. * old logs removed and tabs fixed
  1025. Revision 1.22 2002/07/01 16:29:05 peter
  1026. * sLineBreak changed to normal constant like Kylix
  1027. Revision 1.21 2002/04/21 15:54:20 carl
  1028. + initialize some global variables
  1029. Revision 1.20 2002/04/12 17:42:16 carl
  1030. + generic stack checking
  1031. Revision 1.19 2002/03/11 19:10:33 peter
  1032. * Regenerated with updated fpcmake
  1033. Revision 1.18 2002/02/10 13:46:20 hajny
  1034. * heap management corrected (heap_brk)
  1035. }