1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670
|
{
This file is part of the Free Pascal run time library.
Copyright (c) 2002 by Marco van de Voort
Calls needed for the baseunix unit, but not for system.
Some calls that can be used for both Linux and *BSD will be
moved to a /unix/ includedfile later.
See the file COPYING.FPC, included in this distribution,
for details about the copyright.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
**********************************************************************}
Function fpKill(Pid:pid_t;Sig:cint):cint;
{
Send signal 'sig' to a process, or a group of processes.
If Pid > 0 then the signal is sent to pid
pid=-1 to all processes except process 1
pid < -1 to process group -pid
Return value is zero, except for case three, where the return value
is the number of processes to which the signal was sent.
}
begin
fpkill:=do_syscall(syscall_nr_kill,TSysParam(pid),TSysParam(sig));
// if kill<0 THEN
// Kill:=0;
end;
Function fpSigPending(var nset: TSigSet):cint;
{
Allows examination of pending signals. The signal mask of pending
signals is set in SSet
}
begin
fpsigpending:=do_syscall(syscall_nr_rt_sigpending,TSysParam(@nset));
end;
function fpsigsuspend(const sigmask:TSigSet):cint;
{
Set the signal mask with Mask, and suspend the program until a signal
is received.
}
begin
fpsigsuspend:= do_syscall(syscall_nr_rt_sigsuspend,TSysParam(@sigmask),TSysParam(8));
end;
function fpsigtimedwait(const sigset:TSigSet;info:Psiginfo;timeout:Ptimespec):cint;
begin
{Sizeof(Tsigset)=16 for Free Pascal, but the Linux kernel has a different idea,
it wants a Tsigset of 8 bytes. So we have to hardcode :( }
FpSigTimedWait:=do_syscall(syscall_nr_rt_sigtimedwait,
Tsysparam(@sigset),
Tsysparam(info),
Tsysparam(timeout),
Tsysparam(8 {sizeof(Tsigset)}));
end;
Type
ITimerVal= Record
It_Interval,
It_Value : TimeVal;
end;
Const ITimer_Real =0;
ITimer_Virtual =1;
ITimer_Prof =2;
Function SetITimer(Which : Longint;Const value : ItimerVal; var VarOValue:ItimerVal):Longint;
Begin
SetItimer:=Do_Syscall(syscall_nr_setitimer,Which,TSysParam(@Value),TSysParam(@varovalue));
End;
Function GetITimer(Which : Longint;Var value : ItimerVal):Longint;
Begin
GetItimer:=Do_Syscall(syscall_nr_getItimer,Which,TSysParam(@value));
End;
Function fpalarm(Seconds: cuint):cuint;
Var it,oitv : Itimerval;
retval : cuint;
Begin
// register struct itimerval *itp = ⁢
it.it_interval.tv_sec:=0;
it.it_interval.tv_usec:=0;
it.it_value.tv_usec:=0;
it.it_value.tv_sec:=seconds;
If SetITimer(ITIMER_REAL,it,oitv)<0 Then
Exit(0); // different from *BSD!
retval:= oitv.it_value.tv_usec;
if retval<>0 Then
inc(retval);
fpAlarm:=retval;
End;
// The following versions are for internal use _ONLY_
// This because it works for the first 32 signals _ONLY_, but that
// is enough since they are depreciated, and for legacy applications
// anyway.
function sigblock(mask:cuint):cint;
var nset,oset: TSigSet;
begin
fpsigemptyset(nset);
// fpsigaddset(nset,mask); needs _mask_
nset[0]:=mask;
sigblock:= fpsigprocmask(SIG_BLOCK,@nset,@oset); // SIG_BLOCK=1
if sigblock=0 Then
sigblock:=oset[0];
end;
function sigpause(sigmask:cint):cint;
var nset: TSigSet;
begin
fpsigemptyset(nset);
nset[0]:=sigmask;
sigpause:= fpsigsuspend(nset);
end;
function fppause:cint;
begin
fppause:=sigpause(sigblock(cuint(0)));
end;
function fpsleep(seconds:cuint):cuint;
{see comments in libc}
var time_to_sleep,time_remaining : timespec;
nset,oset : TSigSet;
oerrno : cint;
oact : sigactionrec;
begin
time_to_sleep.tv_sec := seconds;
time_to_sleep.tv_nsec := 0;
fpsigemptyset(nset);
fpsigaddset (nset,SIGCHLD);
if fpsigprocmask(SIG_BLOCK,@nset,@oset)=-1 Then
exit(cuint(-1));
if fpsigismember(oset,SIGCHLD)<>0 Then
Begin
fpsigemptyset(nset);
fpsigaddset (nset,SIGCHLD);
if fpsigaction(SIGCHLD,NIL,@oact)<0 Then
begin
oerrno:=fpgeterrno;
fpsigprocmask(SIG_SETMASK,@oset,NIL);
fpseterrno(oerrno);
exit(cuint(-1));
End;
if oact.sa_handler=SigActionhandler(SIG_IGN) Then
Begin
fpsleep:=fpnanosleep(@time_to_sleep, @time_remaining);
oerrno:=fpgeterrno;
fpsigprocmask(SIG_SETMASK,@oset,NIL);
fpseterrno(oerrno);
End
Else
Begin
fpsigprocmask(SIG_SETMASK,@oset,NIL);
fpsleep:=fpnanosleep(@time_to_sleep, @time_remaining)
End;
end
else
fpsleep:=fpnanosleep(@time_to_sleep, @time_remaining);
if fpsleep<>0 Then
if time_remaining.tv_nsec>=500000000 Then
inc(fpsleep);
End;
function fpuname(var name:utsname):cint; [public,alias:'FPC_SYSC_UNAME'];
begin
fpuname:=Do_Syscall(syscall_nr_uname,TSysParam(@name));
end;
Function fpGetDomainName(Name:PChar; NameLen:size_t):cint;
Var
srec : utsname;
tsize : size_t;
Begin
if fpuname(srec)<0 Then
exit(-1);
tsize:=strlen(@srec.domain[0]);
if tsize>(namelen-1) Then
tsize:=namelen-1;
move(srec.domain[0],name[0],tsize);
name[namelen-1]:=#0;
fpgetDomainName:=0;
End;
function fpGetHostName(Name:PChar; NameLen:size_t):cint;
Var
srec : utsname;
tsize : size_t;
begin
if fpuname(srec)<0 Then
exit(-1);
tsize:=strlen(@srec.nodename[0]);
if tsize>(namelen-1) Then
tsize:=namelen-1;
move(srec.nodename[0],name[0],tsize);
name[namelen-1]:=#0;
fpgethostName:=0;
End;
const WAIT_ANY = -1;
function fpwait(var stat_loc:cint): pid_t;
{
Waits until a child with PID Pid exits, or returns if it is exited already.
Any resources used by the child are freed.
The exit status is reported in the adress referred to by Status. It should
be a longint.
}
begin // actually a wait4() call with 4th arg 0.
fpWait:=do_syscall(syscall_nr_Wait4,WAIT_ANY,TSysParam(@Stat_loc),0,0);
end;
//function fpgetpid : pid_t;
// begin
// fpgetpid:=do_syscall(syscall_nr_getpid);
// end;
function fpgetppid : pid_t;
begin
fpgetppid:=do_syscall(syscall_nr_getppid);
end;
function fpgetuid : uid_t;
begin
fpgetuid:=do_syscall(syscall_nr_getuid);
end;
function fpgeteuid : uid_t;
begin
fpgeteuid:=do_syscall(syscall_nr_geteuid);
end;
function fpgetgid : gid_t;
begin
fpgetgid:=do_syscall(syscall_nr_getgid);
end;
function fpgetegid : gid_t;
begin
fpgetegid:=do_syscall(syscall_nr_getegid);
end;
function fpsetuid(uid : uid_t): cint;
begin
fpsetuid:=do_syscall(syscall_nr_setuid,uid);
end;
function fpsetgid(gid : gid_t): cint;
begin
fpsetgid:=do_syscall(syscall_nr_setgid,gid);
end;
// type tgrparr=array[0..0] of gid_t;
function fpgetgroups(gidsetsize : cint; var grouplist:tgrparr): cint;
begin
fpgetgroups:=do_syscall(syscall_nr_getgroups,gidsetsize,TSysParam(@grouplist));
end;
function fpgetpgrp : pid_t;
begin
{$if defined(generic_linux_syscalls)}
fpgetpgrp:=do_syscall(syscall_nr_getpgid,0);
{$else}
fpgetpgrp:=do_syscall(syscall_nr_getpgrp);
{$endif}
end;
function fpsetsid : pid_t;
begin
fpsetsid:=do_syscall(syscall_nr_setsid);
end;
function fpgetsid (pid:TPid): pid_t;
begin
fpgetsid:=do_syscall(syscall_nr_getsid,pid);
end;
Function fpumask(cmask:mode_t):mode_t;
{
Sets file creation mask to (Mask and 0777 (octal) ), and returns the
previous value.
}
begin
fpumask:=Do_syscall(syscall_nr_umask,cmask);
end;
Function fplink(existing:pchar;newone:pchar):cint;
{
Proceduces a hard link from new to old.
In effect, new will be the same file as old.
}
begin
{$if defined(generic_linux_syscalls)}
fpLink:=Do_Syscall(syscall_nr_linkat,AT_FDCWD,TSysParam(existing),AT_FDCWD,TSysParam(newone),0);
{$else}
fpLink:=Do_Syscall(syscall_nr_link,TSysParam(existing),TSysParam(newone));
{$endif}
end;
Function fpmkfifo(path:pchar;mode:mode_t):cint;
begin
{$if defined(generic_linux_syscalls)}
fpmkfifo:=do_syscall(syscall_nr_mknodat,AT_FDCWD,TSysParam(path),TSysParam(mode or S_IFIFO),TSysParam(0));
{$else}
fpmkfifo:=do_syscall(syscall_nr_mknod,TSysParam(path),TSysParam(mode or S_IFIFO),TSysParam(0));
{$endif}
end;
Function fpchmod(path:pchar;mode:mode_t):cint;
begin
{$if defined(generic_linux_syscalls)}
fpchmod:=do_syscall(syscall_nr_fchmodat,AT_FDCWD,TSysParam(path),TSysParam(mode),0);
{$else}
fpchmod:=do_syscall(syscall_nr_chmod,TSysParam(path),TSysParam(mode));
{$endif}
end;
Function fpchown(path:pchar;owner:uid_t;group:gid_t):cint;
begin
{$if defined(generic_linux_syscalls)}
fpChOwn:=do_syscall(syscall_nr_fchownat,AT_FDCWD,TSysParam(path),TSysParam(owner),TSysParam(group),0);
{$else}
fpChOwn:=do_syscall(syscall_nr_chown,TSysParam(path),TSysParam(owner),TSysParam(group));
{$endif}
end;
{$if defined(generic_linux_syscalls)}
Function fpUtime(path:pchar;times:putimbuf):cint;
var
tsa: Array[0..1] of timespec;
begin
tsa[0].tv_sec := times^.actime;
tsa[0].tv_nsec := 0;
tsa[1].tv_sec := times^.modtime;
tsa[1].tv_nsec := 0;
fputime:=do_syscall(syscall_nr_utimensat,AT_FDCWD,TSysParam(path),
TSysParam(@tsa),0);
end;
{$elseif not defined(NO_SYSCALL_UTIME)}
Function fpUtime(path:pchar;times:putimbuf):cint;
begin
fputime:=do_syscall(syscall_nr_utime,TSysParam(path),TSysParam(times));
end;
{$else}
Function fpUtime(path:pchar;times:putimbuf):cint;
var
tva: Array[0..1] of timeval;
begin
tva[0].tv_sec := times^.actime;
tva[0].tv_usec := 0;
tva[1].tv_sec := times^.modtime;
tva[1].tv_usec := 0;
fputime:=do_syscall(syscall_nr_utimes,TSysParam(path),TSysParam(@tva));
end;
{$endif}
{$ifndef FPC_BASEUNIX_HAS_FPPIPE}
Function fppipe(var fildes : tfildes):cint;
begin
{$if defined(generic_linux_syscalls)}
fppipe:=do_syscall(syscall_nr_pipe2,TSysParam(@fildes),0);
{$else}
fppipe:=do_syscall(syscall_nr_pipe,TSysParam(@fildes));
{$endif}
end;
{$endif FPC_BASEUNIX_HAS_FPPIPE}
function fpfcntl(fildes:cint;Cmd:cint;Arg:cint):cint;
begin
fpfcntl:=do_syscall(syscall_nr_fcntl,fildes,cmd,arg);
end;
function fpfcntl(fildes:cint;Cmd:cint;var Arg:flock):cint;
begin
fpfcntl:=do_syscall(syscall_nr_fcntl,fildes,cmd,TSysParam(@arg));
end;
function fpfcntl(fildes:cint;Cmd:cint):cint;
begin
fpfcntl:=do_syscall(syscall_nr_fcntl,fildes,cmd);
end;
function fpexecve(path:pchar;argv:ppchar;envp:ppchar):cint;
Begin
fpexecve:=do_syscall(syscall_nr_Execve,TSysParam(path),TSysParam(argv),TSysParam(envp));
End;
function fpexecv(path:pchar;argv:ppchar):cint;
Begin
fpexecv:=do_syscall(syscall_nr_Execve,TSysParam(path),TSysParam(argv),TSysParam(envp));
End;
function fptimes(var buffer : tms):clock_t;
begin
fptimes:=Do_syscall(syscall_nr_times,TSysParam(@buffer));
end;
Function fpSelect(N:cint;readfds,writefds,exceptfds:pfdSet;TimeOut:PTimeVal):cint;
{
Select checks whether the file descriptor sets in readfs/writefs/exceptfs
have changed.
}
{$if defined(generic_linux_syscalls)}
var ts : timespec;
begin
ts.tv_sec := timeout^.tv_sec;
ts.tv_nsec := timeout^.tv_usec * 1000;
fpSelect:=do_syscall(syscall_nr_pselect6,n,
tsysparam(readfds),tsysparam(writefds),
tsysparam(exceptfds),tsysparam(@ts),0);
end;
{$else}
begin
{$ifdef cpux86_64}
{$define bunxfunc_fpselect_implemented}
fpSelect:=do_syscall(syscall_nr_select,n,tsysparam(readfds),tsysparam(writefds),tsysparam(exceptfds),tsysparam(timeout));
{$else}
{$define bunxfunc_fpselect_implemented}
fpSelect:=do_syscall(syscall_nr__newselect,n,tsysparam(readfds),tsysparam(writefds),tsysparam(exceptfds),tsysparam(timeout));
{$endif}
{$ifndef bunxfunc_fpselect_implemented}
{$error Implement fpselect}
{$endif bunxfunc_fpselect_implemented}
end;
{$endif}
function fpPoll(fds: ppollfd; nfds: cuint; timeout: clong): cint;
{$if defined(generic_linux_syscalls)}
var ts : timespec;
begin
if timeout<0 then
fpPoll:=do_syscall(syscall_nr_ppoll,tsysparam(fds),tsysparam(nfds),0,0)
else
begin
ts.tv_sec := timeout div 1000;
ts.tv_nsec := (timeout mod 1000) * 1000000;
fpPoll:=do_syscall(syscall_nr_ppoll,tsysparam(fds),tsysparam(nfds),
tsysparam(@ts),0);
end
end;
{$else}
begin
fpPoll:=do_syscall(syscall_nr_poll,tsysparam(fds),tsysparam(nfds),tsysparam(timeout));
end;
{$endif}
Function fpLstat(path:pchar;Info:pstat):cint;
{
Get all information on a link (the link itself), and return it in info.
}
begin
{$if defined(generic_linux_syscalls)}
fpLStat:=do_syscall(syscall_nr_fstatat,AT_FDCWD,TSysParam(path),TSysParam(info),0)
{$else}
fpLStat:=do_syscall(
{$ifdef cpu64}
syscall_nr_lstat,
{$else}
syscall_nr_lstat64,
{$endif}
TSysParam(path),TSysParam(info));
{$endif}
end;
function fpNice(N:cint):cint;
{
Set process priority. A positive N means a lower priority.
A negative N increases priority.
Doesn't exist in BSD. Linux emu uses setpriority in a construct as below:
}
{$if defined(generic_linux_syscalls) or defined(cpux86_64)}
var
oldprio : cint;
{$endif}
begin
{$if defined(generic_linux_syscalls) or defined(cpux86_64)}
oldprio:=fpGetPriority(Prio_Process,0);
fpNice:=fpSetPriority(Prio_Process,0,oldprio+N);
if fpNice=0 then
fpNice:=fpGetPriority(Prio_Process,0);
{$else}
fpNice:=do_syscall(Syscall_nr_nice,N);
{$endif}
end;
Function fpGetPriority(Which,Who:cint):cint;
{
Get Priority of process, process group, or user.
Which : selects what kind of priority is used.
can be one of the following predefined Constants :
Prio_User.
Prio_PGrp.
Prio_Process.
Who : depending on which, this is , respectively :
Uid
Pid
Process Group id
Errors are reported in linuxerror _only_. (priority can be negative)
}
begin
if (which<prio_process) or (which>prio_user) then
begin
{ We can save an interrupt here }
fpgetpriority:=-1;
fpsetErrno(ESysEinval);
end
else
fpGetPriority:=do_syscall(syscall_nr_GetPriority,which,who);
end;
Function fpSetPriority(Which,Who,What:cint):cint;
{
Set Priority of process, process group, or user.
Which : selects what kind of priority is used.
can be one of the following predefined Constants :
Prio_User.
Prio_PGrp.
Prio_Process.
Who : depending on value of which, this is, respectively :
Uid
Pid
Process Group id
what : A number between -20 and 20. -20 is most favorable, 20 least.
0 is the default.
}
begin
if ((which<prio_process) or (which>prio_user)) or ((what<-20) or (what>20)) then
fpseterrno(ESyseinval) { We can save an interrupt here }
else
begin
fpSetPriority:=do_syscall(Syscall_nr_Setpriority,which,who,what);
end;
end;
Function fpSymlink(oldname,newname:pchar):cint;
{
We need this for erase
}
begin
{$if defined(generic_linux_syscalls)}
fpsymlink:=do_syscall(syscall_nr_symlinkat,TSysParam(oldname),AT_FDCWD,TSysParam(newname));
{$else}
fpsymlink:=do_syscall(syscall_nr_symlink,TSysParam(oldname),TSysParam(newname));
{$endif}
end;
function Fppread(fd: cint; buf: pchar; nbytes : size_t; offset:Toff): ssize_t; [public, alias : 'FPC_SYSC_PREAD'];
begin
{$ifdef CPU64}
Fppread:=do_syscall(syscall_nr_pread64,Fd,TSysParam(buf),nbytes,TSysParam(OffSet));
{$else}
{$if defined(CPUMIPS32) or defined(CPUMIPSEL32)}
Fppread:=do_syscall(syscall_nr_pread64,Fd,TSysParam(buf),nbytes,0, { align parameters as required with dummy }
{$ifdef FPC_BIG_ENDIAN} hi(offset),lo(offset){$endif}
{$ifdef FPC_LITTLE_ENDIAN} lo(offset),hi(offset){$endif}
);
{$else CPUMIPS32}
Fppread:=do_syscall(syscall_nr_pread,Fd,TSysParam(buf),nbytes,
{$ifdef FPC_ABI_EABI} 0, { align parameters as required with dummy } {$endif FPC_ABI_EABI}
{$ifdef FPC_BIG_ENDIAN} hi(offset),lo(offset){$endif}
{$ifdef FPC_LITTLE_ENDIAN} lo(offset),hi(offset){$endif}
);
{$endif CPUMIPS32}
{$endif}
end;
function Fppwrite(fd: cint;buf:pchar; nbytes : size_t; offset:Toff): ssize_t; [public, alias : 'FPC_SYSC_PWRITE'];
begin
{$ifdef CPU64}
Fppwrite:=do_syscall(syscall_nr_pwrite64,Fd,TSysParam(buf),nbytes,TSysParam(OffSet));
{$else}
{$if defined(CPUMIPS32) or defined(CPUMIPSEL32)}
Fppwrite:=do_syscall(syscall_nr_pwrite64,Fd,TSysParam(buf),nbytes,0, { align parameters as required with dummy }
{$ifdef FPC_BIG_ENDIAN} hi(offset),lo(offset){$endif}
{$ifdef FPC_LITTLE_ENDIAN} lo(offset),hi(offset){$endif}
);
{$else CPUMIPS32}
Fppwrite:=do_syscall(syscall_nr_pwrite,Fd,TSysParam(buf),nbytes,
{$ifdef FPC_ABI_EABI} 0, { align parameters as required with dummy } {$endif FPC_ABI_EABI}
{$ifdef FPC_BIG_ENDIAN} hi(offset),lo(offset){$endif}
{$ifdef FPC_LITTLE_ENDIAN} lo(offset),hi(offset){$endif}
);
{$endif CPUMIPS32}
{$endif}
end;
function Fpreadv(fd: cint; const iov : piovec; iovcnt : cint):ssize_t; [public, alias : 'FPC_SYSC_READV'];
begin
Fpreadv:=do_syscall(syscall_nr_readv,Fd,TSysParam(iov),iovcnt);
end;
function Fpwritev(fd: cint; const iov : piovec; iovcnt : cint):ssize_t; [public, alias : 'FPC_SYSC_WRITEV'];
begin
Fpwritev:=do_syscall(syscall_nr_writev,Fd,TSysParam(iov),iovcnt);
end;
|