25
25
Unit {$ifdef VER1_0}Syslinux{$else}System{$endif};
30
{$define posixworkaround}
31
29
{$define FPC_IS_SYSTEM}
48
function geterrnolocation: Plibcint; cdecl;external clib name'__errno_location';
50
function geterrno:libcint; [public, alias: 'FPC_SYS_GETERRNO'];
53
geterrno:=geterrnolocation^;
56
procedure seterrno(err:libcint); [public, alias: 'FPC_SYS_SETERRNO'];
58
geterrnolocation^:=err;
70
function geterrno:longint; [public, alias: 'FPC_SYS_GETERRNO'];
76
procedure seterrno(err:longint); [public, alias: 'FPC_SYS_SETERRNO'];
85
{ OS dependant parts }
87
{$I errno.inc} // error numbers
88
{$I bunxtype.inc} // c-types, unix base types, unix
91
{*****************************************************************************
92
Extra cdecl declarations for FPC_USE_LIBC for this os
93
*****************************************************************************}
96
Function fpReadLink(name,linkname:pchar;maxlen:cint):cint; cdecl; external name 'readlink';
97
function fpgetcwd(buf:pchar;_size:size_t):pchar; cdecl; external name 'getcwd';
101
{$I ossysc.inc} // base syscalls
102
{$I osmain.inc} // base wrappers *nix RTL (derivatives)
104
{ more OS independant parts}
109
{*****************************************************************************
110
UnTyped File Handling
111
*****************************************************************************}
115
{*****************************************************************************
117
*****************************************************************************}
41
{*****************************************************************************
42
Misc. System Dependent Functions
43
*****************************************************************************}
45
procedure haltproc(e:longint);cdecl;external name '_haltproc';
47
procedure System_exit;
53
Function ParamCount: Longint;
59
function BackPos(c:char; const s: shortstring): integer;
63
for i:=length(s) downto 0 do
64
if s[i] = c then break;
72
{ variable where full path and filename and executable is stored }
73
{ is setup by the startup of the system unit. }
75
execpathstr : shortstring;
77
function paramstr(l: longint) : string;
79
{ stricly conforming POSIX applications }
80
{ have the executing filename as argv[0] }
83
paramstr := execpathstr;
86
paramstr:=strpas(argv[l]);
91
randseed:=longint(Fptime(nil));
95
{*****************************************************************************
96
SystemUnit Initialization
97
*****************************************************************************}
99
function reenable_signal(sig : longint) : boolean;
104
fillchar(e,sizeof(e),#0);
105
{ set is 1 based PM }
110
fpsigprocmask(SIG_UNBLOCK,@e,nil);
111
reenable_signal:=geterrno=0;
115
// signal handler is arch dependant due to processorexception to language
116
// exception translation
123
Procedure InstallSignals;
125
{ Initialize the sigaction structure }
126
{ all flags and information set to zero }
127
FillChar(act, sizeof(SigActionRec),0);
128
{ initialize handler }
129
act.sa_handler := SigActionHandler(@SignalToRunError);
130
act.sa_flags:=SA_SIGINFO
135
FpSigAction(SIGFPE,@act,nil);
136
FpSigAction(SIGSEGV,@act,nil);
137
FpSigAction(SIGBUS,@act,nil);
138
FpSigAction(SIGILL,@act,nil);
141
procedure SetupCmdLine;
151
reallocmem(cmdline,size+bufsize);
152
move(buf^,cmdline[size],bufsize);
164
len:=strlen(argv[i]);
165
if len>ARG_MAX-2 then
169
if argv[i][j]=' ' then
174
if bufsize+len>=ARG_MAX-2 then
181
move(argv[i]^,buf[bufsize],len);
196
FreeMem(buf,ARG_MAX);
122
200
procedure SysInitStdIO;
124
202
OpenStdIO(Input,fmInput,StdInputHandle);
125
203
OpenStdIO(Output,fmOutput,StdOutputHandle);
204
OpenStdIO(ErrOutput,fmOutput,StdErrorHandle);
126
205
OpenStdIO(StdOut,fmOutput,StdOutputHandle);
127
206
OpenStdIO(StdErr,fmOutput,StdErrorHandle);
152
230
IsLibrary := FALSE;
153
231
StackLength := InitialStkLen;
154
232
StackBottom := Sptr - StackLength;
155
{ Set up signals handlers }
233
{ Set up signals handlers }
159
237
SysInitExceptions;
163
{ Setup stdin, stdout and stderr }
241
{ Setup stdin, stdout and stderr }
167
(* This should be changed to a real value during *)
168
(* thread driver initialization if appropriate. *)
170
247
{$ifdef HASVARIANT}
171
248
initvariantmanager;
172
249
{$endif HASVARIANT}
250
{$ifdef HASWIDESTRING}
251
initwidestringmanager;
252
{$endif HASWIDESTRING}
176
256
$Log: system.pp,v $
177
Revision 1.14 2004/01/20 23:09:14 hajny
178
* ExecuteProcess fixes, ProcessID and ThreadID added
180
Revision 1.13 2004/01/01 14:16:55 marco
181
* getcwd missed cdecl
183
Revision 1.12 2003/12/31 20:20:57 marco
184
* small additions for getcwd what we need for FPC_USE_LIBC
186
Revision 1.11 2003/12/30 16:26:10 marco
187
* some more fixes. Testing on idefix
189
Revision 1.10 2003/12/30 15:43:20 marco
190
* linux now compiles with FPC_USE_LIBC
192
Revision 1.9 2003/12/30 12:36:56 marco
195
Revision 1.8 2003/09/14 20:15:01 marco
196
* Unix reform stage two. Remove all calls from Unix that exist in Baseunix.
198
Revision 1.7 2003/04/30 22:11:06 florian
199
+ for a lot of x86-64 dependend files mostly dummies added
201
Revision 1.6 2002/12/27 18:36:16 peter
202
* Setup ExecPathStr for ParamStr(0)
204
Revision 1.5 2002/12/18 20:42:29 peter
205
* initial stacklen setup
207
Revision 1.3 2002/12/18 16:44:09 marco
210
Revision 1.7 2002/11/12 14:57:48 marco
211
* Ugly hack to temporarily be able to use system.pp for Linux too
213
Revision 1.6 2002/10/27 11:58:30 marco
214
* Modifications from Saturday.
216
Revision 1.5 2002/10/26 18:27:51 marco
217
* First series POSIX calls commits. Including getcwd.
219
Revision 1.4 2002/10/18 12:19:58 marco
220
* Fixes to get the generic *BSD RTL compiling again + fixes for thread
221
support. Still problems left in fexpand. (inoutres?) Therefore fixed
222
sysposix not yet commited
224
Revision 1.3 2002/10/13 09:25:39 florian
225
+ call to initvariantmanager inserted
227
Revision 1.2 2002/09/07 16:01:17 peter
228
* old logs removed and tabs fixed
230
Revision 1.1 2002/08/19 12:29:11 marco
231
* First working POSIX *BSD system unit.
257
Revision 1.25 2005/04/24 21:19:22 peter
258
* unblock signal in signalhandler, remove the sigprocmask call
261
Revision 1.24 2005/02/14 17:13:30 peter
264
Revision 1.23 2005/02/13 21:47:56 peter
265
* include file cleanup part 2
267
Revision 1.22 2005/02/06 11:20:52 peter
268
* threading in system unit
269
* removed systhrds unit
271
Revision 1.21 2005/02/01 20:22:49 florian
272
* improved widestring infrastructure manager