system.pas 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229
  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;
  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;
  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. mov %eax,L
  362. end;
  363. WriteLn ('New heap at ', L);
  364. Sbrk := pointer(L);
  365. end;
  366. {$ELSE DUMPGROW}
  367. assembler;
  368. asm
  369. movl size,%edx
  370. movw $0x7f00,%ax
  371. call syscall { result directly in EAX }
  372. end;
  373. {$ENDIF DUMPGROW}
  374. function getheapstart:pointer;assembler;
  375. asm
  376. movl heap_base,%eax
  377. end ['EAX'];
  378. function getheapsize:longint;assembler;
  379. asm
  380. movl heap_brk,%eax
  381. end ['EAX'];
  382. {$i heap.inc}
  383. {****************************************************************************
  384. Low Level File Routines
  385. ****************************************************************************}
  386. procedure allowslash(p:Pchar);
  387. {Allow slash as backslash.}
  388. var i:longint;
  389. begin
  390. for i:=0 to strlen(p) do
  391. if p[i]='/' then p[i]:='\';
  392. end;
  393. procedure do_close(h:longint);
  394. begin
  395. { Only three standard handles under real OS/2 }
  396. if h>2 then
  397. begin
  398. asm
  399. pushl %ebx
  400. movb $0x3e,%ah
  401. movl h,%ebx
  402. call syscall
  403. jnc .Lnoerror { error code? }
  404. movw %ax, InOutRes { yes, then set InOutRes }
  405. .Lnoerror:
  406. popl %ebx
  407. end;
  408. end;
  409. end;
  410. procedure do_erase(p:Pchar);
  411. begin
  412. allowslash(p);
  413. inoutres:=DosDelete(p);
  414. end;
  415. procedure do_rename(p1,p2:Pchar);
  416. begin
  417. allowslash(p1);
  418. allowslash(p2);
  419. inoutres:=DosMove(p1, p2);
  420. end;
  421. function do_read(h,addr,len:longint):longint; assembler;
  422. asm
  423. pushl %ebx
  424. movl len,%ecx
  425. movl addr,%edx
  426. movl h,%ebx
  427. movb $0x3f,%ah
  428. call syscall
  429. jnc .LDOSREAD1
  430. movw %ax,inoutres;
  431. xorl %eax,%eax
  432. .LDOSREAD1:
  433. popl %ebx
  434. end;
  435. function do_write(h,addr,len:longint) : longint; assembler;
  436. asm
  437. pushl %ebx
  438. xorl %eax,%eax
  439. cmpl $0,len { 0 bytes to write is undefined behavior }
  440. jz .LDOSWRITE1
  441. movl len,%ecx
  442. movl addr,%edx
  443. movl h,%ebx
  444. movb $0x40,%ah
  445. call syscall
  446. jnc .LDOSWRITE1
  447. movw %ax,inoutres;
  448. .LDOSWRITE1:
  449. popl %ebx
  450. end;
  451. function do_filepos(handle:longint): longint; assembler;
  452. asm
  453. pushl %ebx
  454. movw $0x4201,%ax
  455. movl handle,%ebx
  456. xorl %edx,%edx
  457. call syscall
  458. jnc .LDOSFILEPOS
  459. movw %ax,inoutres;
  460. xorl %eax,%eax
  461. .LDOSFILEPOS:
  462. popl %ebx
  463. end;
  464. procedure do_seek(handle,pos:longint); assembler;
  465. asm
  466. pushl %ebx
  467. movw $0x4200,%ax
  468. movl handle,%ebx
  469. movl pos,%edx
  470. call syscall
  471. jnc .LDOSSEEK1
  472. movw %ax,inoutres;
  473. .LDOSSEEK1:
  474. popl %ebx
  475. end;
  476. function do_seekend(handle:longint):longint; assembler;
  477. asm
  478. pushl %ebx
  479. movw $0x4202,%ax
  480. movl handle,%ebx
  481. xorl %edx,%edx
  482. call syscall
  483. jnc .Lset_at_end1
  484. movw %ax,inoutres;
  485. xorl %eax,%eax
  486. .Lset_at_end1:
  487. popl %ebx
  488. end;
  489. function do_filesize(handle:longint):longint;
  490. var aktfilepos:longint;
  491. begin
  492. aktfilepos:=do_filepos(handle);
  493. do_filesize:=do_seekend(handle);
  494. do_seek(handle,aktfilepos);
  495. end;
  496. procedure do_truncate(handle,pos:longint); assembler;
  497. asm
  498. pushl %ebx
  499. (* DOS function 40h isn't safe for this according to EMX documentation *)
  500. movl $0x7F25,%eax
  501. movl Handle,%ebx
  502. movl Pos,%edx
  503. call syscall
  504. incl %eax
  505. movl %ecx, %eax
  506. jnz .LTruncate1 { compare the value of EAX to verify error }
  507. (* File position is undefined after truncation, move to the end. *)
  508. movl $0x4202,%eax
  509. movl Handle,%ebx
  510. movl $0,%edx
  511. call syscall
  512. jnc .LTruncate2
  513. .LTruncate1:
  514. movw %ax,inoutres;
  515. .LTruncate2:
  516. popl %ebx
  517. end;
  518. const
  519. FileHandleCount: longint = 20;
  520. function Increase_File_Handle_Count: boolean;
  521. var Err: word;
  522. L1, L2: longint;
  523. begin
  524. L1 := 10;
  525. if DosSetRelMaxFH (L1, L2) <> 0 then
  526. Increase_File_Handle_Count := false
  527. else
  528. if L2 > FileHandleCount then
  529. begin
  530. FileHandleCount := L2;
  531. Increase_File_Handle_Count := true;
  532. end
  533. else
  534. Increase_File_Handle_Count := false;
  535. end;
  536. procedure do_open(var f;p:pchar;flags:longint);
  537. {
  538. filerec and textrec have both handle and mode as the first items so
  539. they could use the same routine for opening/creating.
  540. when (flags and $100) the file will be append
  541. when (flags and $1000) the file will be truncate/rewritten
  542. when (flags and $10000) there is no check for close (needed for textfiles)
  543. }
  544. var Action: longint;
  545. begin
  546. allowslash(p);
  547. { close first if opened }
  548. if ((flags and $10000)=0) then
  549. begin
  550. case filerec(f).mode of
  551. fminput,fmoutput,fminout : Do_Close(filerec(f).handle);
  552. fmclosed:;
  553. else
  554. begin
  555. inoutres:=102; {not assigned}
  556. exit;
  557. end;
  558. end;
  559. end;
  560. { reset file handle }
  561. filerec(f).handle := UnusedHandle;
  562. Action := 0;
  563. { convert filemode to filerec modes }
  564. case (flags and 3) of
  565. 0 : filerec(f).mode:=fminput;
  566. 1 : filerec(f).mode:=fmoutput;
  567. 2 : filerec(f).mode:=fminout;
  568. end;
  569. if (flags and $1000)<>0 then
  570. Action := $50000; (* Create / replace *)
  571. { empty name is special }
  572. if p[0]=#0 then
  573. begin
  574. case FileRec(f).mode of
  575. fminput :
  576. FileRec(f).Handle:=StdInputHandle;
  577. fminout, { this is set by rewrite }
  578. fmoutput :
  579. FileRec(f).Handle:=StdOutputHandle;
  580. fmappend :
  581. begin
  582. FileRec(f).Handle:=StdOutputHandle;
  583. FileRec(f).mode:=fmoutput; {fool fmappend}
  584. end;
  585. end;
  586. exit;
  587. end;
  588. Action := Action or (Flags and $FF);
  589. (* DenyNone if sharing not specified. *)
  590. if Flags and 112 = 0 then
  591. Action := Action or 64;
  592. asm
  593. movl $0x7f2b, %eax
  594. movl Action, %ecx
  595. movl p, %edx
  596. call syscall
  597. cmpl $0xffffffff, %eax
  598. jnz .LOPEN1
  599. movw %cx, InOutRes
  600. movw UnusedHandle, %ax
  601. .LOPEN1:
  602. movl f,%edx { Warning : This assumes Handle is first }
  603. movw %ax,(%edx) { field of FileRec }
  604. end;
  605. if (InOutRes = 4) and Increase_File_Handle_Count then
  606. (* Trying again after increasing amount of file handles *)
  607. asm
  608. movl $0x7f2b, %eax
  609. movl Action, %ecx
  610. movl p, %edx
  611. call syscall
  612. cmpl $0xffffffff, %eax
  613. jnz .LOPEN2
  614. movw %cx, InOutRes
  615. movw UnusedHandle, %ax
  616. .LOPEN2:
  617. movl f,%edx
  618. movw %ax,(%edx)
  619. end;
  620. { for systems that have more handles }
  621. if FileRec (F).Handle > FileHandleCount then
  622. FileHandleCount := FileRec (F).Handle;
  623. if ((Flags and $100) <> 0) and
  624. (FileRec (F).Handle <> UnusedHandle) then
  625. begin
  626. do_seekend (FileRec (F).Handle);
  627. FileRec (F).Mode := fmOutput; {fool fmappend}
  628. end;
  629. end;
  630. {$ASMMODE INTEL}
  631. function do_isdevice (Handle: longint): boolean; assembler;
  632. (*
  633. var HT, Attr: longint;
  634. begin
  635. if DosQueryHType (Handle, HT, Attr) <> 0 then HT := 1;
  636. *)
  637. asm
  638. push ebx
  639. mov ebx, Handle
  640. mov eax, 4400h
  641. call syscall
  642. mov eax, 1
  643. jc @IsDevEnd
  644. test edx, 80h { verify if it is a file }
  645. jnz @IsDevEnd
  646. dec eax { nope, so result is zero }
  647. @IsDevEnd:
  648. pop ebx
  649. end;
  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. push ebx
  925. {Enable the brk area by initializing it with the initial heap size.}
  926. mov eax, 7F01h
  927. mov edx, heap_brk
  928. add edx, heap_base
  929. call syscall
  930. cmp eax, -1
  931. jnz @heapok
  932. push dword 204
  933. call HandleError
  934. @heapok:
  935. {$IFDEF CONTHEAP}
  936. { Find out brk limit }
  937. mov eax, 7F02h
  938. mov ecx, 3
  939. call syscall
  940. jcxz @heaplimitknown
  941. mov eax, 0
  942. @heaplimitknown:
  943. mov BrkLimit, eax
  944. {$ELSE CONTHEAP}
  945. { Change sbrk behaviour to allocate arbitrary (non-contiguous) memory blocks }
  946. mov eax, 7F0Fh
  947. mov ecx, 0Ch
  948. mov edx, 8
  949. call syscall
  950. {$ENDIF CONTHEAP}
  951. pop ebx
  952. end;
  953. {Now request, if we are running under DOS,
  954. read-access to the first meg. of memory.}
  955. (* Initialize the amount of file handles *)
  956. FileHandleCount := GetFileHandleCount;
  957. DosGetInfoBlocks (@TIB, @PIB);
  958. StackBottom := cardinal (TIB^.Stack);
  959. Environment := pointer (PIB^.Env);
  960. ApplicationType := PIB^.ProcType;
  961. IsConsole := ApplicationType <> 3;
  962. exitproc:=nil;
  963. {Initialize the heap.}
  964. initheap;
  965. { ... and exceptions }
  966. SysInitExceptions;
  967. { ... and I/O }
  968. SysInitStdIO;
  969. { no I/O-Error }
  970. inoutres:=0;
  971. {$ifdef HASVARIANT}
  972. initvariantmanager;
  973. {$endif HASVARIANT}
  974. {$IFDEF DUMPGROW}
  975. {$IFDEF CONTHEAP}
  976. WriteLn ('Initial brk size is ', GetHeapSize);
  977. WriteLn ('Brk limit is ', BrkLimit);
  978. {$ENDIF CONTHEAP}
  979. {$ENDIF DUMPGROW}
  980. end.
  981. {
  982. $Log$
  983. Revision 1.39 2003-10-06 16:58:27 yuri
  984. * Another set of native functions.
  985. Revision 1.38 2003/10/06 14:22:40 yuri
  986. * Some emx code removed. Now withous so stupid error as with dos ;)
  987. Revision 1.37 2003/10/04 08:30:59 yuri
  988. * at&t syntax instead of intel syntax was used
  989. Revision 1.36 2003/10/03 21:46:41 peter
  990. * stdcall fixes
  991. Revision 1.35 2003/10/01 18:42:49 yuri
  992. * Unclosed comment
  993. Revision 1.34 2003/09/29 18:39:59 hajny
  994. * append fix applied to GO32v2, OS/2 and EMX
  995. Revision 1.33 2003/09/27 11:52:36 peter
  996. * sbrk returns pointer
  997. Revision 1.32 2003/03/30 09:20:30 hajny
  998. * platform extension unification
  999. Revision 1.31 2003/01/15 22:16:12 hajny
  1000. * default sharing mode changed to DenyNone
  1001. Revision 1.30 2002/12/15 22:41:41 hajny
  1002. * First_Meg fixed + Environment initialization under Dos
  1003. Revision 1.29 2002/12/08 16:39:58 hajny
  1004. - WriteLn in GUI mode support commented out until fixed
  1005. Revision 1.28 2002/12/07 19:17:14 hajny
  1006. * GetEnv correction, better PM support, ...
  1007. Revision 1.27 2002/11/17 22:31:02 hajny
  1008. * type corrections (longint x cardinal)
  1009. Revision 1.26 2002/10/27 14:29:00 hajny
  1010. * heap management (hopefully) fixed
  1011. Revision 1.25 2002/10/14 19:39:17 peter
  1012. * threads unit added for thread support
  1013. Revision 1.24 2002/10/13 09:28:45 florian
  1014. + call to initvariantmanager inserted
  1015. Revision 1.23 2002/09/07 16:01:25 peter
  1016. * old logs removed and tabs fixed
  1017. Revision 1.22 2002/07/01 16:29:05 peter
  1018. * sLineBreak changed to normal constant like Kylix
  1019. Revision 1.21 2002/04/21 15:54:20 carl
  1020. + initialize some global variables
  1021. Revision 1.20 2002/04/12 17:42:16 carl
  1022. + generic stack checking
  1023. Revision 1.19 2002/03/11 19:10:33 peter
  1024. * Regenerated with updated fpcmake
  1025. Revision 1.18 2002/02/10 13:46:20 hajny
  1026. * heap management corrected (heap_brk)
  1027. }