system.pas 36 KB

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