system.inc 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Run time library.
  4. Copyright (c) 1999-2000 by the Free Pascal development team
  5. See the file COPYING.FPC, included in this distribution,
  6. For details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {****************************************************************************
  12. Local types
  13. ****************************************************************************}
  14. {
  15. TextRec and FileRec are put in a separate file to make it available to other
  16. units without putting it explicitly in systemh.
  17. This way we keep TP compatibility, and the TextRec definition is available
  18. for everyone who needs it.
  19. }
  20. {$i filerec.inc}
  21. {$i textrec.inc}
  22. Procedure HandleError (Errno : Longint); forward;
  23. Procedure HandleErrorFrame (Errno : longint;frame : longint); forward;
  24. type
  25. FileFunc = Procedure(var t : TextRec);
  26. const
  27. STACK_MARGIN = 16384; { Stack size margin for stack checking }
  28. { Random / Randomize constants }
  29. OldRandSeed : Cardinal = 0;
  30. InitialSeed : Boolean = TRUE;
  31. Seed2 : Cardinal = 0;
  32. Seed3 : Cardinal = 0;
  33. { For Error Handling.}
  34. ErrorBase : Longint = 0;
  35. { Used by the ansistrings and maybe also other things in the future }
  36. var
  37. emptychar : char;public name 'FPC_EMPTYCHAR';
  38. stacklength : longint;external name '__stklen';
  39. {****************************************************************************
  40. Routines which have compiler magic
  41. ****************************************************************************}
  42. {$I innr.inc}
  43. Function lo(i : Integer) : byte; [INTERNPROC: In_lo_Word];
  44. Function lo(w : Word) : byte; [INTERNPROC: In_lo_Word];
  45. Function lo(l : Longint) : Word; [INTERNPROC: In_lo_long];
  46. Function lo(l : DWord) : Word; [INTERNPROC: In_lo_long];
  47. Function hi(i : Integer) : byte; [INTERNPROC: In_hi_Word];
  48. Function hi(w : Word) : byte; [INTERNPROC: In_hi_Word];
  49. Function hi(l : Longint) : Word; [INTERNPROC: In_hi_long];
  50. Function hi(l : DWord) : Word; [INTERNPROC: In_hi_long];
  51. Function lo(q : QWord) : DWord; [INTERNPROC: In_lo_qword];
  52. Function lo(i : Int64) : DWord; [INTERNPROC: In_lo_qword];
  53. Function hi(q : QWord) : DWord; [INTERNPROC: In_hi_qword];
  54. Function hi(i : Int64) : DWord; [INTERNPROC: In_hi_qword];
  55. Function chr(b : byte) : Char; [INTERNPROC: In_chr_byte];
  56. {$ifndef INTERNLENGTH}
  57. Function Length(s : string) : byte; [INTERNPROC: In_Length_string];
  58. Function Length(c : char) : byte; [INTERNPROC: In_Length_string];
  59. {$endif INTERNLENGTH}
  60. Procedure Reset(var f : TypedFile); [INTERNPROC: In_Reset_TypedFile];
  61. Procedure Rewrite(var f : TypedFile); [INTERNPROC: In_Rewrite_TypedFile];
  62. {****************************************************************************
  63. Include processor specific routines
  64. ****************************************************************************}
  65. {$ifdef i386}
  66. {$ifdef SYSPROCDEFINED}
  67. {$Error Can't determine processor type !}
  68. {$endif}
  69. {$define ENDIAN_LITTLE}
  70. {$i i386.inc} { Case dependent, don't change }
  71. {$endif i386}
  72. {$ifdef m68k}
  73. {$ifdef SYSPROCDEFINED}
  74. {$Error Can't determine processor type !}
  75. {$endif}
  76. {$define ENDIAN_BIG}
  77. {$i m68k.inc} { Case dependent, don't change }
  78. {$define SYSPROCDEFINED}
  79. {$endif m68k}
  80. {$ifdef x86_64}
  81. {$ifdef SYSPROCDEFINED}
  82. {$Error Can't determine processor type !}
  83. {$endif}
  84. {$define ENDIAN_LITTLE}
  85. {$i x86_64.inc} { Case dependent, don't change }
  86. {$define SYSPROCDEFINED}
  87. {$endif x86_64}
  88. {$ifdef powerpc}
  89. {$ifdef SYSPROCDEFINED}
  90. {$Error Can't determine processor type !}
  91. {$endif}
  92. {$define ENDIAN_BIG}
  93. {$i powerpc.inc} { Case dependent, don't change }
  94. {$define SYSPROCDEFINED}
  95. {$endif powerpc}
  96. {$ifdef alpha}
  97. {$ifdef SYSPROCDEFINED}
  98. {$Error Can't determine processor type !}
  99. {$endif}
  100. {$define ENDIAN_BIG}
  101. {$i alpha.inc} { Case dependent, don't change }
  102. {$define SYSPROCDEFINED}
  103. {$endif alpha}
  104. {$ifdef iA64}
  105. {$ifdef SYSPROCDEFINED}
  106. {$Error Can't determine processor type !}
  107. {$endif}
  108. {$define ENDIAN_LITTLE}
  109. {$i ia64.inc} { Case dependent, don't change }
  110. {$define SYSPROCDEFINED}
  111. {$endif iA64}
  112. { Include generic pascal only routines which are not defined in the processor
  113. specific include file }
  114. {$I generic.inc}
  115. {****************************************************************************
  116. Set Handling
  117. ****************************************************************************}
  118. { Include set support which is processor specific}
  119. {$i set.inc}
  120. { Include generic pascal routines for sets if the processor }
  121. { specific routines are not available. }
  122. {$i genset.inc}
  123. {****************************************************************************
  124. Math Routines
  125. ****************************************************************************}
  126. function Hi(b : byte): byte;
  127. begin
  128. Hi := b shr 4
  129. end;
  130. function Lo(b : byte): byte;
  131. begin
  132. Lo := b and $0f
  133. end;
  134. Function swap (X : Word) : Word;[internconst:in_const_swap_word];
  135. Begin
  136. swap:=(X and $ff) shl 8 + (X shr 8)
  137. End;
  138. Function Swap (X : Integer) : Integer;[internconst:in_const_swap_word];
  139. Begin
  140. swap:=(X and $ff) shl 8 + (X shr 8)
  141. End;
  142. Function swap (X : Longint) : Longint;[internconst:in_const_swap_long];
  143. Begin
  144. Swap:=(X and $ffff) shl 16 + (X shr 16)
  145. End;
  146. Function Swap (X : Cardinal) : Cardinal;[internconst:in_const_swap_long];
  147. Begin
  148. Swap:=(X and $ffff) shl 16 + (X shr 16)
  149. End;
  150. Function Swap (X : QWord) : QWord;
  151. Begin
  152. Swap:=(X and $ffffffff) shl 32 + (X shr 32);
  153. End;
  154. Function swap (X : Int64) : Int64;
  155. Begin
  156. Swap:=(X and $ffffffff) shl 32 + (X shr 32);
  157. End;
  158. operator := (b:real48) d:double;
  159. begin
  160. D:=real2double(b);
  161. end;
  162. {$ifdef SUPPORT_EXTENDED}
  163. operator := (b:real48) e:extended;
  164. begin
  165. e:=real2double(b);
  166. end;
  167. {$endif SUPPORT_EXTENDED}
  168. { Include processor specific routines }
  169. {$I math.inc}
  170. { Include generic version }
  171. {$I genmath.inc}
  172. {****************************************************************************
  173. Subroutines for String handling
  174. ****************************************************************************}
  175. { Needs to be before RTTI handling }
  176. {$i sstrings.inc}
  177. { requires sstrings.inc for initval }
  178. {$I int64.inc}
  179. {Requires int64.inc, since that contains the VAL functions for int64 and qword}
  180. {$i astrings.inc}
  181. {$ifdef HASWIDESTRING}
  182. {$i wstrings.inc}
  183. {$endif HASWIDESTRING}
  184. {$i aliases.inc}
  185. {*****************************************************************************
  186. Dynamic Array support
  187. *****************************************************************************}
  188. {$i dynarr.inc}
  189. {*****************************************************************************
  190. Object Pascal support
  191. *****************************************************************************}
  192. {$i objpas.inc}
  193. {*****************************************************************************
  194. Variant support
  195. *****************************************************************************}
  196. {$ifdef HASVARIANT}
  197. {$i variant.inc}
  198. {$endif HASVARIANT}
  199. {****************************************************************************
  200. Run-Time Type Information (RTTI)
  201. ****************************************************************************}
  202. {$i rtti.inc}
  203. {****************************************************************************
  204. Random function routines
  205. This implements a very long cycle random number generator by combining
  206. three independant generators. The technique was described in the March
  207. 1987 issue of Byte.
  208. Taken and modified with permission from the PCQ Pascal rtl code.
  209. ****************************************************************************}
  210. {$R-}
  211. {$Q-}
  212. Procedure NewSeed;Forward;
  213. Function Random : Extended;
  214. begin
  215. if (InitialSeed) OR (RandSeed <> OldRandSeed) then
  216. Begin
  217. { This is a pretty complicated affair }
  218. { Initially we must call NewSeed when RandSeed is initalized }
  219. { We must also call NewSeed each time RandSeed is reinitialized }
  220. { DO NOT CHANGE THE ORDER OF DECLARATIONS IN THIS BLOCK }
  221. { UNLESS YOU WANT RANDON TO CRASH OF COURSE (CEC) }
  222. InitialSeed:=FALSE;
  223. OldRandSeed:=RandSeed;
  224. NewSeed;
  225. end;
  226. Inc(RandSeed);
  227. RandSeed := (RandSeed * 706) mod 500009;
  228. OldRandSeed:=RandSeed;
  229. INC(Seed2);
  230. Seed2 := (Seed2 * 774) MOD 600011;
  231. INC(Seed3);
  232. Seed3 := (Seed3 * 871) MOD 765241;
  233. Random :=
  234. frac(RandSeed/500009.0 +
  235. Seed2/600011.0 +
  236. Seed3/765241.0);
  237. end;
  238. Function internRandom(l : Cardinal) : Cardinal;
  239. begin
  240. if (InitialSeed) OR (RandSeed <> OldRandSeed) then
  241. Begin
  242. { This is a pretty complicated affair }
  243. { Initially we must call NewSeed when RandSeed is initalized }
  244. { We must also call NewSeed each time RandSeed is reinitialized }
  245. { DO NOT CHANGE THE ORDER OF DECLARATIONS IN THIS BLOCK }
  246. { UNLESS YOU WANT RANDOM TO CRASH OF COURSE (CEC) }
  247. InitialSeed:=FALSE;
  248. OldRandSeed:=RandSeed;
  249. NewSeed;
  250. end;
  251. Inc(RandSeed);
  252. RandSeed := (RandSeed * 998) mod 1000003;
  253. OldRandSeed:=RandSeed;
  254. if l<>0 then
  255. begin
  256. internRandom := RandSeed mod l;
  257. end
  258. else internRandom:=0;
  259. end;
  260. function random(l:cardinal): cardinal;
  261. begin
  262. random := trunc(random()*l);
  263. end;
  264. function random(l:longint): longint;
  265. begin
  266. random := trunc(random()*l);
  267. end;
  268. Procedure NewSeed;
  269. begin
  270. randseed := randseed mod 1000003;
  271. Seed2 := (internRandom(65000) * internRandom(65000)) mod 600011;
  272. Seed3 := (internRandom(65000) * internRandom(65000)) mod 765241;
  273. end;
  274. {****************************************************************************
  275. Memory Management
  276. ****************************************************************************}
  277. Function Ptr(sel,off : Longint) : farpointer;[internconst:in_const_ptr];
  278. Begin
  279. ptr:=farpointer((sel shl 4)+off);
  280. End;
  281. Function CSeg : Word;
  282. Begin
  283. Cseg:=0;
  284. End;
  285. Function DSeg : Word;
  286. Begin
  287. Dseg:=0;
  288. End;
  289. Function SSeg : Word;
  290. Begin
  291. Sseg:=0;
  292. End;
  293. {*****************************************************************************
  294. Directory support.
  295. *****************************************************************************}
  296. Procedure getdir(drivenr:byte;Var dir:ansistring);
  297. { this is needed to also allow ansistrings, the shortstring version is
  298. OS dependent }
  299. var
  300. s : shortstring;
  301. begin
  302. getdir(drivenr,s);
  303. dir:=s;
  304. end;
  305. {$ifopt R+}
  306. {$define RangeCheckWasOn}
  307. {$R-}
  308. {$endif opt R+}
  309. {$ifopt I+}
  310. {$define IOCheckWasOn}
  311. {$I-}
  312. {$endif opt I+}
  313. {$ifopt Q+}
  314. {$define OverflowCheckWasOn}
  315. {$Q-}
  316. {$endif opt Q+}
  317. {*****************************************************************************
  318. Miscellaneous
  319. *****************************************************************************}
  320. procedure fpc_rangeerror;[public,alias:'FPC_RANGEERROR']; {$ifdef hascompilerproc} compilerproc; {$endif}
  321. begin
  322. HandleErrorFrame(201,get_frame);
  323. end;
  324. procedure fpc_overflow;[public,alias:'FPC_OVERFLOW']; {$ifdef hascompilerproc} compilerproc; {$endif}
  325. begin
  326. HandleErrorFrame(215,get_frame);
  327. end;
  328. procedure fpc_iocheck(addr : longint);[saveregisters,public,alias:'FPC_IOCHECK']; {$ifdef hascompilerproc} compilerproc; {$endif}
  329. var
  330. l : longint;
  331. begin
  332. if InOutRes<>0 then
  333. begin
  334. l:=InOutRes;
  335. InOutRes:=0;
  336. HandleErrorFrame(l,get_frame);
  337. end;
  338. end;
  339. Function IOResult:Word;
  340. Begin
  341. IOResult:=InOutRes;
  342. InOutRes:=0;
  343. End;
  344. procedure fillchar(var x;count : longint;value : boolean);
  345. begin
  346. fillchar(x,count,byte(value));
  347. end;
  348. procedure fillchar(var x;count : longint;value : char);
  349. begin
  350. fillchar(x,count,byte(value));
  351. end;
  352. {*****************************************************************************
  353. Stack check code
  354. *****************************************************************************}
  355. {$IFNDEF NO_GENERIC_STACK_CHECK}
  356. {$IFOPT S+}
  357. {$DEFINE STACKCHECK}
  358. {$ENDIF}
  359. {$S-}
  360. procedure fpc_stackcheck(stack_size:longint);[saveregisters,public,alias:'FPC_STACKCHECK'];
  361. var
  362. c: cardinal;
  363. begin
  364. { Avoid recursive calls when called from the exit routines }
  365. if StackError then
  366. exit;
  367. c := cardinal(Sptr) - cardinal(stack_size) - STACK_MARGIN;
  368. if (c <= cardinal(StackBottom)) then
  369. begin
  370. StackError:=true;
  371. HandleError(202);
  372. end;
  373. end;
  374. {$IFDEF STACKCHECK}
  375. {$S+}
  376. {$ENDIF}
  377. {$UNDEF STACKCHECK}
  378. {$ENDIF NO_GENERIC_STACK_CHECK}
  379. {*****************************************************************************
  380. Initialization / Finalization
  381. *****************************************************************************}
  382. const
  383. maxunits=1024; { See also files.pas of the compiler source }
  384. type
  385. TInitFinalRec=record
  386. InitProc,
  387. FinalProc : TProcedure;
  388. end;
  389. TInitFinalTable=record
  390. TableCount,
  391. InitCount : longint;
  392. Procs : array[1..maxunits] of TInitFinalRec;
  393. end;
  394. var
  395. InitFinalTable : TInitFinalTable;external name 'INITFINAL';
  396. procedure fpc_InitializeUnits;[public,alias:'FPC_INITIALIZEUNITS']; {$ifdef hascompilerproc} compilerproc; {$endif}
  397. var
  398. i : longint;
  399. begin
  400. with InitFinalTable do
  401. begin
  402. for i:=1to TableCount do
  403. begin
  404. if assigned(Procs[i].InitProc) then
  405. Procs[i].InitProc();
  406. InitCount:=i;
  407. end;
  408. end;
  409. end;
  410. procedure FinalizeUnits;[public,alias:'FPC_FINALIZEUNITS'];
  411. begin
  412. with InitFinalTable do
  413. begin
  414. while (InitCount>0) do
  415. begin
  416. // we've to decrement the cound before calling the final. code
  417. // else a halt in the final. code leads to a endless loop
  418. dec(InitCount);
  419. if assigned(Procs[InitCount+1].FinalProc) then
  420. Procs[InitCount+1].FinalProc();
  421. end;
  422. end;
  423. end;
  424. {*****************************************************************************
  425. Error / Exit / ExitProc
  426. *****************************************************************************}
  427. Procedure system_exit;forward;
  428. Procedure InternalExit;
  429. var
  430. current_exit : Procedure;
  431. Begin
  432. while exitProc<>nil Do
  433. Begin
  434. InOutRes:=0;
  435. current_exit:=tProcedure(exitProc);
  436. exitProc:=nil;
  437. current_exit();
  438. End;
  439. { Finalize units }
  440. FinalizeUnits;
  441. { Show runtime error and exit }
  442. If erroraddr<>nil Then
  443. Begin
  444. Writeln(stdout,'Runtime error ',Errorcode,' at 0x',hexstr(Longint(Erroraddr),8));
  445. { to get a nice symify }
  446. Writeln(stdout,BackTraceStrFunc(Longint(Erroraddr)));
  447. dump_stack(stdout,ErrorBase);
  448. Writeln(stdout,'');
  449. End;
  450. End;
  451. Procedure do_exit;[Public,Alias:'FPC_DO_EXIT'];
  452. begin
  453. InternalExit;
  454. System_exit;
  455. end;
  456. Procedure lib_exit;saveregisters;[Public,Alias:'FPC_LIB_EXIT'];
  457. begin
  458. InternalExit;
  459. end;
  460. Procedure Halt(ErrNum: Byte);
  461. Begin
  462. ExitCode:=Errnum;
  463. Do_Exit;
  464. end;
  465. function SysBackTraceStr (Addr: longint): ShortString;
  466. begin
  467. SysBackTraceStr:=' 0x'+HexStr(addr,8);
  468. end;
  469. Procedure HandleErrorAddrFrame (Errno : longint;addr,frame : longint);[public,alias:'FPC_BREAK_ERROR'];
  470. begin
  471. If pointer(ErrorProc)<>Nil then
  472. ErrorProc(Errno,pointer(addr),pointer(frame));
  473. errorcode:=Errno;
  474. exitcode:=Errno;
  475. erroraddr:=pointer(addr);
  476. errorbase:=frame;
  477. halt(errorcode);
  478. end;
  479. Procedure HandleErrorFrame (Errno : longint;frame : longint);
  480. {
  481. Procedure to handle internal errors, i.e. not user-invoked errors
  482. Internal function should ALWAYS call HandleError instead of RunError.
  483. Can be used for exception handlers to specify the frame
  484. }
  485. begin
  486. HandleErrorAddrFrame(Errno,get_caller_addr(frame),get_caller_frame(frame));
  487. end;
  488. Procedure HandleError (Errno : longint);[public,alias : 'FPC_HANDLEERROR'];
  489. {
  490. Procedure to handle internal errors, i.e. not user-invoked errors
  491. Internal function should ALWAYS call HandleError instead of RunError.
  492. }
  493. begin
  494. HandleErrorFrame(Errno,get_frame);
  495. end;
  496. procedure runerror(w : word);[alias: 'FPC_RUNERROR'];
  497. begin
  498. errorcode:=w;
  499. exitcode:=w;
  500. erroraddr:=pointer(get_caller_addr(get_frame));
  501. errorbase:=get_caller_frame(get_frame);
  502. halt(errorcode);
  503. end;
  504. Procedure RunError;
  505. Begin
  506. RunError (0);
  507. End;
  508. Procedure Halt;
  509. Begin
  510. Halt(0);
  511. End;
  512. function do_isdevice(handle:longint):boolean;forward;
  513. Procedure dump_stack(var f : text;bp : Longint);
  514. var
  515. i, prevbp : Longint;
  516. is_dev : boolean;
  517. caller_addr : longint;
  518. Begin
  519. prevbp:=bp-1;
  520. i:=0;
  521. is_dev:=do_isdevice(textrec(f).Handle);
  522. while bp > prevbp Do
  523. Begin
  524. caller_addr := get_caller_addr(bp);
  525. if caller_addr <> 0 then
  526. Writeln(f,BackTraceStrFunc(caller_addr));
  527. Inc(i);
  528. If ((i>max_frame_dump) and is_dev) or (i>256) Then
  529. exit;
  530. prevbp:=bp;
  531. bp:=get_caller_frame(bp);
  532. End;
  533. End;
  534. Type
  535. PExitProcInfo = ^TExitProcInfo;
  536. TExitProcInfo = Record
  537. Next : PExitProcInfo;
  538. SaveExit : Pointer;
  539. Proc : TProcedure;
  540. End;
  541. const
  542. ExitProcList: PExitProcInfo = nil;
  543. Procedure DoExitProc;
  544. var
  545. P : PExitProcInfo;
  546. Proc : TProcedure;
  547. Begin
  548. P:=ExitProcList;
  549. ExitProcList:=P^.Next;
  550. ExitProc:=P^.SaveExit;
  551. Proc:=P^.Proc;
  552. DisPose(P);
  553. Proc();
  554. End;
  555. Procedure AddExitProc(Proc: TProcedure);
  556. var
  557. P : PExitProcInfo;
  558. Begin
  559. New(P);
  560. P^.Next:=ExitProcList;
  561. P^.SaveExit:=ExitProc;
  562. P^.Proc:=Proc;
  563. ExitProcList:=P;
  564. ExitProc:=@DoExitProc;
  565. End;
  566. {*****************************************************************************
  567. Abstract/Assert support.
  568. *****************************************************************************}
  569. procedure AbstractError;[public,alias : 'FPC_ABSTRACTERROR'];
  570. begin
  571. If pointer(AbstractErrorProc)<>nil then
  572. AbstractErrorProc();
  573. HandleErrorFrame(211,get_frame);
  574. end;
  575. {$ifdef hascompilerproc}
  576. { alias for internal usage in the compiler }
  577. procedure fpc_AbstractErrorIntern; compilerproc; external name 'FPC_ABSTRACTERROR';
  578. {$endif hascompilerproc}
  579. Procedure fpc_assert(Const Msg,FName:Shortstring;LineNo,ErrorAddr:Longint); [SaveRegisters,Public,Alias : 'FPC_ASSERT']; {$ifdef hascompilerproc} compilerproc; {$endif}
  580. begin
  581. if pointer(AssertErrorProc)<>nil then
  582. AssertErrorProc(Msg,FName,LineNo,ErrorAddr)
  583. else
  584. HandleErrorFrame(227,get_frame);
  585. end;
  586. Procedure SysAssert(Const Msg,FName:Shortstring;LineNo,ErrorAddr:Longint);
  587. begin
  588. If msg='' then
  589. write(stderr,'Assertion failed')
  590. else
  591. write(stderr,msg);
  592. Writeln(stderr,' (',FName,', line ',LineNo,').');
  593. Writeln(stderr,'');
  594. end;
  595. {*****************************************************************************
  596. SetJmp/LongJmp support.
  597. *****************************************************************************}
  598. {$i setjump.inc}
  599. {$ifdef IOCheckWasOn}
  600. {$I+}
  601. {$endif}
  602. {$ifdef RangeCheckWasOn}
  603. {$R+}
  604. {$endif}
  605. {$ifdef OverflowCheckWasOn}
  606. {$Q+}
  607. {$endif}
  608. {
  609. $Log$
  610. Revision 1.32 2002-07-28 20:43:48 florian
  611. * several fixes for linux/powerpc
  612. * several fixes to MT
  613. Revision 1.31 2002/07/26 22:46:06 florian
  614. * interface of system unit for Linux/PowerPC compiles
  615. Revision 1.30 2002/07/26 16:42:00 florian
  616. * endian directive for PowerPC fixed
  617. Revision 1.29 2002/07/04 20:40:09 florian
  618. + some x86-64 support added
  619. Revision 1.28 2002/04/21 15:51:50 carl
  620. * StackError is now a typed constant
  621. + $S can be used under unix
  622. Revision 1.27 2002/04/15 19:38:40 peter
  623. * stackcheck protected against infinite recursive after stack error
  624. * stackcheck requires saveregisters, because it can be called from
  625. iocheck and then will destroy the result of the original function
  626. Revision 1.26 2002/04/15 18:51:20 carl
  627. + generic stack checking can be overriden
  628. Revision 1.25 2002/04/12 17:37:36 carl
  629. + generic stack checking
  630. Revision 1.24 2001/12/13 20:23:19 michael
  631. + Added double2real function from main branch
  632. Revision 1.23 2001/11/19 02:40:24 carl
  633. + don't print stack information if previous frame = 0
  634. Revision 1.22 2001/08/19 21:02:01 florian
  635. * fixed and added a lot of stuff to get the Jedi DX( headers
  636. compiled
  637. Revision 1.21 2001/08/01 15:00:10 jonas
  638. + "compproc" helpers
  639. * renamed several helpers so that their name is the same as their
  640. "public alias", which should facilitate the conversion of processor
  641. specific code in the code generator to processor independent code
  642. * some small fixes to the val_ansistring and val_widestring helpers
  643. (always immediately exit if the source string is longer than 255
  644. chars)
  645. * fixed fpc_dynarray_high and fpc_dynarray_length if the dynarray is
  646. still nil (used to crash, now return resp -1 and 0)
  647. Revision 1.20 2001/07/30 21:38:55 peter
  648. * m68k updates merged
  649. Revision 1.19 2001/07/29 14:05:55 peter
  650. * include lowmath for m68k (merged)
  651. Revision 1.18 2001/07/29 13:49:15 peter
  652. * m68k updates merged
  653. Revision 1.17 2001/07/09 21:15:41 peter
  654. * Length made internal
  655. * Add array support for Length
  656. Revision 1.16 2001/07/08 21:00:18 peter
  657. * various widestring updates, it works now mostly without charset
  658. mapping supported
  659. Revision 1.15 2001/06/13 18:32:05 peter
  660. * big endian updates (merged)
  661. Revision 1.14 2001/06/03 15:15:58 peter
  662. * lib_exit added
  663. Revision 1.13 2001/05/09 19:57:07 peter
  664. *** empty log message ***
  665. Revision 1.12 2001/04/13 18:06:28 peter
  666. * removed rtllite define
  667. Revision 1.11 2000/12/16 15:56:19 jonas
  668. - removed all ifdef cardinalmulfix code
  669. Revision 1.10 2000/11/13 14:47:46 jonas
  670. * support for range checking when converting from 64bit to something
  671. smaller (32bit, 16bit, 8bit)
  672. * fixed range checking between longint/cardinal and for array indexing
  673. with cardinal (values > $7fffffff were considered negative)
  674. Revision 1.9 2000/11/11 16:12:01 peter
  675. * ptr returns farpointer
  676. Revision 1.8 2000/11/06 21:35:59 peter
  677. * removed some warnings
  678. Revision 1.7 2000/11/04 17:52:46 florian
  679. * fixed linker errors
  680. Revision 1.6 2000/10/13 12:04:03 peter
  681. * FPC_BREAK_ERROR added
  682. Revision 1.5 2000/08/13 17:55:14 michael
  683. + Added some delphi compatibility types
  684. Revision 1.4 2000/08/09 19:31:18 marco
  685. * fixes for val(int64 or qword) to ansistring
  686. Revision 1.3 2000/07/14 10:33:10 michael
  687. + Conditionals fixed
  688. Revision 1.2 2000/07/13 11:33:45 michael
  689. + removed logs
  690. }