system.pp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time librar~y.
  4. Copyright (c) 2000 by Marco van de Voort
  5. member of the Free Pascal development team.
  6. System unit for the *BSD's.
  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. { These things are set in the makefile, }
  14. { But you can override them here.}
  15. { If you use an aout system, set the conditional AOUT}
  16. { $Define AOUT}
  17. Unit {$ifdef VER1_0}SysBSD{$else}System{$endif};
  18. Interface
  19. {$define FPC_USE_SIGPROCMASK}
  20. {$define FPC_USE_SIGALTSTACK}
  21. {$ifndef FPC_USE_LIBC}
  22. {$define FPC_USE_SYSCALL}
  23. {$endif}
  24. {$define FPC_IS_SYSTEM}
  25. {$I sysunixh.inc}
  26. CONST SIGSTKSZ = 40960;
  27. Implementation
  28. {$ifdef FPC_USE_LIBC}
  29. const clib = 'c';
  30. type libcint=longint;
  31. plibcint=^libcint;
  32. {$ifdef FreeBSD} // tested on x86
  33. function geterrnolocation: Plibcint; cdecl;external clib name '__error';
  34. {$else}
  35. {$ifdef NetBSD} // from a sparc dump.
  36. function geterrnolocation: Plibcint; cdecl;external clib name '__errno';
  37. {$else}
  38. {$ifdef Darwin}
  39. function geterrnolocation: Plibcint; cdecl;external clib name '__error';
  40. {$else}
  41. {$endif}
  42. {$endif}
  43. {$endif}
  44. function geterrno:libcint; [public, alias: 'FPC_SYS_GETERRNO'];
  45. begin
  46. geterrno:=geterrnolocation^;
  47. end;
  48. procedure seterrno(err:libcint); [public, alias: 'FPC_SYS_SETERRNO'];
  49. begin
  50. geterrnolocation^:=err;
  51. end;
  52. {$else}
  53. {$ifdef ver1_0}
  54. Var
  55. {$else}
  56. threadvar
  57. {$endif}
  58. Errno : longint;
  59. function geterrno:longint; [public, alias: 'FPC_SYS_GETERRNO'];
  60. begin
  61. GetErrno:=Errno;
  62. end;
  63. procedure seterrno(err:longint); [public, alias: 'FPC_SYS_SETERRNO'];
  64. begin
  65. Errno:=err;
  66. end;
  67. {$endif}
  68. { OS independant parts}
  69. {$I system.inc}
  70. { OS dependant parts }
  71. {$I errno.inc}
  72. {$I bunxtype.inc}
  73. {$I ossysc.inc}
  74. {$I osmain.inc}
  75. {$I text.inc}
  76. {$I heap.inc}
  77. {*****************************************************************************
  78. UnTyped File Handling
  79. *****************************************************************************}
  80. {$i file.inc}
  81. {*****************************************************************************
  82. Typed File Handling
  83. *****************************************************************************}
  84. {$i typefile.inc}
  85. procedure SysInitStdIO;
  86. begin
  87. OpenStdIO(Input,fmInput,StdInputHandle);
  88. OpenStdIO(Output,fmOutput,StdOutputHandle);
  89. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  90. OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  91. end;
  92. {$ifdef FPC_USE_LIBC}
  93. { can also be used with other BSD's if they use the system's crtX instead of prtX }
  94. {$ifdef Darwin}
  95. procedure pascalmain; external name 'PASCALMAIN';
  96. { Main entry point in C style, needed to capture program parameters. }
  97. procedure main(argcparam: Longint; argvparam: ppchar; envpparam: ppchar); cdecl; [public];
  98. begin
  99. argc:= argcparam;
  100. argv:= argvparam;
  101. envp:= envpparam;
  102. pascalmain; {run the pascal main program}
  103. end;
  104. {$endif Darwin}
  105. {$endif FPC_USE_LIBC}
  106. Begin
  107. IsConsole := TRUE;
  108. IsLibrary := FALSE;
  109. StackBottom := Sptr - StackLength;
  110. { Set up signals handlers }
  111. InstallSignals;
  112. { Setup heap }
  113. InitHeap;
  114. SysInitExceptions;
  115. { Arguments }
  116. SetupCmdLine;
  117. { Setup stdin, stdout and stderr }
  118. SysInitStdIO;
  119. { Reset IO Error }
  120. InOutRes:=0;
  121. (* This should be changed to a real value during *)
  122. (* thread driver initialization if appropriate. *)
  123. ThreadID := 1;
  124. {$ifdef HASVARIANT}
  125. initvariantmanager;
  126. {$endif HASVARIANT}
  127. End.
  128. {
  129. $Log$
  130. Revision 1.13 2004-01-20 23:09:14 hajny
  131. * ExecuteProcess fixes, ProcessID and ThreadID added
  132. Revision 1.12 2004/01/04 20:32:05 jonas
  133. + geterrnolocation for Darwin
  134. + C-style main for Darwin (generic, can be used for anything)
  135. Revision 1.11 2003/12/30 12:26:21 marco
  136. * FPC_USE_LIBC
  137. Revision 1.10 2003/10/26 17:01:04 marco
  138. * moved sigprocmask to system
  139. Revision 1.9 2003/10/26 16:42:22 marco
  140. * texception4 fix merge
  141. Revision 1.8 2003/01/05 19:01:28 marco
  142. * FreeBSD compiles now with baseunix mods.
  143. Revision 1.7 2002/11/12 14:57:48 marco
  144. * Ugly hack to temporarily be able to use system.pp for Linux too
  145. Revision 1.6 2002/10/27 11:58:30 marco
  146. * Modifications from Saturday.
  147. Revision 1.5 2002/10/26 18:27:51 marco
  148. * First series POSIX calls commits. Including getcwd.
  149. Revision 1.4 2002/10/18 12:19:58 marco
  150. * Fixes to get the generic *BSD RTL compiling again + fixes for thread
  151. support. Still problems left in fexpand. (inoutres?) Therefore fixed
  152. sysposix not yet commited
  153. Revision 1.3 2002/10/13 09:25:39 florian
  154. + call to initvariantmanager inserted
  155. Revision 1.2 2002/09/07 16:01:17 peter
  156. * old logs removed and tabs fixed
  157. Revision 1.1 2002/08/19 12:29:11 marco
  158. * First working POSIX *BSD system unit.
  159. }