system.inc 22 KB

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