2
This file is part of the Free Pascal run time library.
3
Copyright (c) 2002 by Marco van de Voort
5
Calls needed for the baseunix unit, but not for system.
6
Some calls that can be used for both Linux and *BSD will be
7
moved to a /unix/ includedfile later.
9
See the file COPYING.FPC, included in this distribution,
10
for details about the copyright.
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
**********************************************************************}
18
Function fpKill(Pid:pid_t;Sig:cint):cint;
20
Send signal 'sig' to a process, or a group of processes.
21
If Pid > 0 then the signal is sent to pid
22
pid=-1 to all processes except process 1
23
pid < -1 to process group -pid
24
Return value is zero, except for case three, where the return value
25
is the number of processes to which the signal was sent.
29
fpkill:=do_syscall(syscall_nr_kill,TSysParam(pid),TSysParam(sig));
34
Function fpSigPending(var nset: TSigSet):cint;
36
Allows examination of pending signals. The signal mask of pending
37
signals is set in SSet
40
fpsigpending:=do_syscall(syscall_nr_rt_sigpending,TSysParam(@nset));
43
function fpsigsuspend(const sigmask:TSigSet):cint;
45
Set the signal mask with Mask, and suspend the program until a signal
50
fpsigsuspend:= do_syscall(syscall_nr_rt_sigsuspend,TSysParam(@sigmask));
63
Function SetITimer(Which : Longint;Const value : ItimerVal; var VarOValue:ItimerVal):Longint;
66
SetItimer:=Do_Syscall(syscall_nr_setitimer,Which,TSysParam(@Value),TSysParam(@varovalue));
69
Function GetITimer(Which : Longint;Var value : ItimerVal):Longint;
72
GetItimer:=Do_Syscall(syscall_nr_getItimer,Which,TSysParam(@value));
75
Function fpalarm(Seconds: cuint):cuint;
77
Var it,oitv : Itimerval;
81
// register struct itimerval *itp = ⁢
83
it.it_interval.tv_sec:=0;
84
it.it_interval.tv_usec:=0;
85
it.it_value.tv_usec:=0;
86
it.it_value.tv_sec:=seconds;
87
If SetITimer(ITIMER_REAL,it,oitv)<0 Then
88
Exit(0); // different from *BSD!
90
retval:= oitv.it_value.tv_usec;
96
// The following versions are for internal use _ONLY_
97
// This because it works for the first 32 signals _ONLY_, but that
98
// is enough since they are depreciated, and for legacy applications
101
function sigblock(mask:cuint):cint;
103
var nset,oset: TSigSet;
107
// fpsigaddset(nset,mask); needs _mask_
109
sigblock:= fpsigprocmask(SIG_BLOCK,@nset,@oset); // SIG_BLOCK=1
114
function sigpause(sigmask:cint):cint;
121
sigpause:= fpsigsuspend(nset);
124
function fppause:cint;
127
fppause:=sigpause(sigblock(cuint(0)));
130
function fpsleep(seconds:cuint):cuint;
131
{see comments in libc}
133
var time_to_sleep,time_remaining : timespec;
139
time_to_sleep.tv_sec := seconds;
140
time_to_sleep.tv_nsec := 0;
142
fpsigaddset (nset,SIGCHLD);
143
if fpsigprocmask(SIG_BLOCK,@nset,@oset)=-1 Then
145
if fpsigismember(oset,SIGCHLD)<>0 Then
148
fpsigaddset (nset,SIGCHLD);
149
if fpsigaction(SIGCHLD,NIL,@oact)<0 Then
152
fpsigprocmask(SIG_SETMASK,@oset,NIL);
156
if oact.sa_handler=SigActionhandler(SIG_IGN) Then
158
fpsleep:=fpnanosleep(@time_to_sleep, @time_remaining);
160
fpsigprocmask(SIG_SETMASK,@oset,NIL);
165
fpsigprocmask(SIG_SETMASK,@oset,NIL);
166
fpsleep:=fpnanosleep(@time_to_sleep, @time_remaining)
170
fpsleep:=fpnanosleep(@time_to_sleep, @time_remaining);
172
if time_remaining.tv_nsec>=500000000 Then
176
function fpuname(var name:utsname):cint; [public,alias:'FPC_SYSC_UNAME'];
179
fpuname:=Do_Syscall(syscall_nr_uname,TSysParam(@name));
182
Function fpGetDomainName(Name:PChar; NameLen:size_t):cint;
188
if fpuname(srec)<0 Then
190
tsize:=strlen(@srec.domain[0]);
191
if tsize>(namelen-1) Then
193
move(srec.domain[0],name[0],tsize);
198
function fpGetHostName(Name:PChar; NameLen:size_t):cint;
204
if fpuname(srec)<0 Then
206
tsize:=strlen(@srec.nodename[0]);
207
if tsize>(namelen-1) Then
209
move(srec.nodename[0],name[0],tsize);
216
function fpwait(var stat_loc:cint): pid_t;
218
Waits until a child with PID Pid exits, or returns if it is exited already.
219
Any resources used by the child are freed.
220
The exit status is reported in the adress referred to by Status. It should
224
begin // actually a wait4() call with 4th arg 0.
225
fpWait:=do_syscall(syscall_nr_Wait4,WAIT_ANY,TSysParam(@Stat_loc),0,0);
228
//function fpgetpid : pid_t;
231
// fpgetpid:=do_syscall(syscall_nr_getpid);
234
function fpgetppid : pid_t;
237
fpgetppid:=do_syscall(syscall_nr_getppid);
240
function fpgetuid : uid_t;
243
fpgetuid:=do_syscall(syscall_nr_getuid);
246
function fpgeteuid : uid_t;
249
fpgeteuid:=do_syscall(syscall_nr_geteuid);
252
function fpgetgid : gid_t;
255
fpgetgid:=do_syscall(syscall_nr_getgid);
258
function fpgetegid : gid_t;
261
fpgetegid:=do_syscall(syscall_nr_getegid);
264
function fpsetuid(uid : uid_t): cint;
267
fpsetuid:=do_syscall(syscall_nr_setuid,uid);
270
function fpsetgid(gid : gid_t): cint;
273
fpsetgid:=do_syscall(syscall_nr_setgid,gid);
276
// type tgrparr=array[0..0] of gid_t;
278
function fpgetgroups(gidsetsize : cint; var grouplist:tgrparr): cint;
281
fpgetgroups:=do_syscall(syscall_nr_getgroups,gidsetsize,TSysParam(@grouplist));
284
function fpgetpgrp : pid_t;
287
fpgetpgrp:=do_syscall(syscall_nr_getpgrp);
290
function fpsetsid : pid_t;
293
fpsetsid:=do_syscall(syscall_nr_setsid);
296
Function fpumask(cmask:mode_t):mode_t;
298
Sets file creation mask to (Mask and 0777 (octal) ), and returns the
302
fpumask:=Do_syscall(syscall_nr_umask,cmask);
305
Function fplink(existing:pchar;newone:pchar):cint;
307
Proceduces a hard link from new to old.
308
In effect, new will be the same file as old.
311
fpLink:=Do_Syscall(syscall_nr_link,TSysParam(existing),TSysParam(newone));
314
Function fpmkfifo(path:pchar;mode:mode_t):cint;
318
fpmkfifo:=do_syscall(syscall_nr_mknod,TSysParam(path),TSysParam(mode or S_IFIFO),TSysParam(0));
321
Function fpchmod(path:pchar;mode:mode_t):cint;
324
fpchmod:=do_syscall(syscall_nr_chmod,TSysParam(path),TSysParam(mode));
327
Function fpchown(path:pchar;owner:uid_t;group:gid_t):cint;
330
fpChOwn:=do_syscall(syscall_nr_chown,TSysParam(path),TSysParam(owner),TSysParam(group));
333
Function fpUtime(path:pchar;times:putimbuf):cint;
336
fputime:=do_syscall(syscall_nr_utime,TSysParam(path),TSysParam(times));
340
{$ifndef FPC_BASEUNIX_HAS_FPPIPE}
341
Function fppipe(var fildes : tfildes):cint;
344
fppipe:=do_syscall(syscall_nr_pipe,TSysParam(@fildes));
346
{$endif FPC_BASEUNIX_HAS_FPPIPE}
349
function fpfcntl(fildes:cint;Cmd:cint;Arg:cint):cint;
352
fpfcntl:=do_syscall(syscall_nr_fcntl,fildes,cmd,arg);
355
function fpfcntl(fildes:cint;Cmd:cint;var Arg:flock):cint;
358
fpfcntl:=do_syscall(syscall_nr_fcntl,fildes,cmd,TSysParam(@arg));
361
function fpfcntl(fildes:cint;Cmd:cint):cint;
364
fpfcntl:=do_syscall(syscall_nr_fcntl,fildes,cmd);
367
function fpexecve(path:pchar;argv:ppchar;envp:ppchar):cint;
370
fpexecve:=do_syscall(syscall_nr_Execve,TSysParam(path),TSysParam(argv),TSysParam(envp));
373
function fpexecv(path:pchar;argv:ppchar):cint;
376
fpexecv:=do_syscall(syscall_nr_Execve,TSysParam(path),TSysParam(argv),TSysParam(envp));
379
function fptimes(var buffer : tms):clock_t;
381
fptimes:=Do_syscall(syscall_nr_times,TSysParam(@buffer));
384
Function fpSelect(N:cint;readfds,writefds,exceptfds:pfdSet;TimeOut:PTimeVal):cint;
386
Select checks whether the file descriptor sets in readfs/writefs/exceptfs
392
{$define bunxfunc_fpselect_implemented}
393
fpSelect:=do_syscall(syscall_nr_select,n,tsysparam(readfds),tsysparam(writefds),tsysparam(exceptfds),tsysparam(timeout));
395
{$define bunxfunc_fpselect_implemented}
396
fpSelect:=do_syscall(syscall_nr__newselect,n,tsysparam(readfds),tsysparam(writefds),tsysparam(exceptfds),tsysparam(timeout));
398
{$ifndef bunxfunc_fpselect_implemented}
399
{$error Implement fpselect}
400
{$endif bunxfunc_fpselect_implemented}
403
Function fpLstat(path:pchar;Info:pstat):cint;
405
Get all information on a link (the link itself), and return it in info.
415
TSysParam(path),TSysParam(info));
418
Function fpLstat(Filename: ansistring;Info:pstat):cint;
420
Get all information on a link (the link itself), and return it in info.
430
TSysParam(pchar(filename)),TSysParam(info));
434
function fpNice(N:cint):cint;
436
Set process priority. A positive N means a lower priority.
437
A negative N increases priority.
439
Doesn't exist in BSD. Linux emu uses setpriority in a construct as below:
448
oldprio:=fpGetPriority(Prio_Process,0);
449
fpNice:=fpSetPriority(Prio_Process,0,oldprio+N);
451
fpNice:=fpGetPriority(Prio_Process,0);
453
fpNice:=do_syscall(Syscall_nr_nice,N);
457
Function fpGetPriority(Which,Who:cint):cint;
459
Get Priority of process, process group, or user.
460
Which : selects what kind of priority is used.
461
can be one of the following predefined Constants :
465
Who : depending on which, this is , respectively :
469
Errors are reported in linuxerror _only_. (priority can be negative)
472
if (which<prio_process) or (which>prio_user) then
474
{ We can save an interrupt here }
476
fpsetErrno(ESysEinval);
479
fpGetPriority:=do_syscall(syscall_nr_GetPriority,which,who);
482
Function fpSetPriority(Which,Who,What:cint):cint;
484
Set Priority of process, process group, or user.
485
Which : selects what kind of priority is used.
486
can be one of the following predefined Constants :
490
Who : depending on value of which, this is, respectively :
494
what : A number between -20 and 20. -20 is most favorable, 20 least.
498
if ((which<prio_process) or (which>prio_user)) or ((what<-20) or (what>20)) then
499
fpseterrno(ESyseinval) { We can save an interrupt here }
502
fpSetPriority:=do_syscall(Syscall_nr_Setpriority,which,who,what);
507
Function fpSymlink(oldname,newname:pchar):cint;
509
We need this for erase
513
fpsymlink:=do_syscall(syscall_nr_symlink,TSysParam(oldname),TSysParam(newname));
516
function Fppread(fd: cint; buf: pchar; nbytes : size_t; offset:Toff): ssize_t; [public, alias : 'FPC_SYSC_PREAD'];
521
Fppread:=do_syscall(syscall_nr_pread64,Fd,TSysParam(buf),nbytes,TSysParam(OffSet));
523
Fppread:=do_syscall(syscall_nr_pread,Fd,TSysParam(buf),nbytes,
524
{$ifdef FPC_BIG_ENDIAN} hi(offset),lo(offset){$endif}
525
{$ifdef FPC_LITTLE_ENDIAN} lo(offset),hi(offset){$endif}
530
function Fppwrite(fd: cint;buf:pchar; nbytes : size_t; offset:Toff): ssize_t; [public, alias : 'FPC_SYSC_PWRITE'];
534
Fppwrite:=do_syscall(syscall_nr_pwrite64,Fd,TSysParam(buf),nbytes,TSysParam(OffSet));
536
Fppwrite:=do_syscall(syscall_nr_pwrite,Fd,TSysParam(buf),nbytes,
537
{$ifdef FPC_BIG_ENDIAN} hi(offset),lo(offset){$endif}
538
{$ifdef FPC_LITTLE_ENDIAN} lo(offset),hi(offset){$endif}
543
function Fpreadv(fd: cint; const iov : piovec; iovcnt : cint):ssize_t; [public, alias : 'FPC_SYSC_READV'];
546
Fpreadv:=do_syscall(syscall_nr_readv,Fd,TSysParam(iov),iovcnt);
549
function Fpwritev(fd: cint; const iov : piovec; iovcnt : cint):ssize_t; [public, alias : 'FPC_SYSC_WRITEV'];
552
Fpwritev:=do_syscall(syscall_nr_writev,Fd,TSysParam(iov),iovcnt);