unixsysc.inc 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by Michael Van Canneyt,
  5. member of the Free Pascal development team.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY;without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. Function Fork:longint;
  13. {
  14. This function issues the 'fork' System call. the program is duplicated in memory
  15. and Execution continues in parent and child process.
  16. In the parent process, fork returns the PID of the child. In the child process,
  17. zero is returned.
  18. A negative value indicates that an error has occurred, the error is returned in
  19. LinuxError.
  20. }
  21. var
  22. regs:SysCallregs;
  23. begin
  24. Fork:=SysCall(SysCall_nr_fork,regs);
  25. LinuxError:=Errno;
  26. End;
  27. Procedure Execve(path:pathstr;args:ppchar;ep:ppchar);
  28. {
  29. Replaces the current program by the program specified in path,
  30. arguments in args are passed to Execve.
  31. environment specified in ep is passed on.
  32. }
  33. var
  34. regs:SysCallregs;
  35. begin
  36. path:=path+#0;
  37. regs.reg2:=longint(@path[1]);
  38. regs.reg3:=longint(args);
  39. regs.reg4:=longint(ep);
  40. SysCall(SysCall_nr_Execve,regs);
  41. { This only gets set when the call fails, otherwise we don't get here ! }
  42. Linuxerror:=errno;
  43. end;
  44. Procedure Execve(path:pchar;args:ppchar;ep:ppchar);
  45. {
  46. Replaces the current program by the program specified in path,
  47. arguments in args are passed to Execve.
  48. environment specified in ep is passed on.
  49. }
  50. var
  51. regs:SysCallregs;
  52. begin
  53. regs.reg2:=longint(path);
  54. regs.reg3:=longint(args);
  55. regs.reg4:=longint(ep);
  56. SysCall(SysCall_nr_Execve,regs);
  57. { This only gets set when the call fails, otherwise we don't get here ! }
  58. Linuxerror:=errno;
  59. end;
  60. Procedure ExitProcess(val:longint);
  61. var
  62. regs : SysCallregs;
  63. begin
  64. regs.reg2:=val;
  65. SysCall(SysCall_nr_exit,regs);
  66. end;
  67. Function WaitPid(Pid:longint;Status:pointer;Options:Longint):Longint;
  68. {
  69. Waits until a child with PID Pid exits, or returns if it is exited already.
  70. Any resources used by the child are freed.
  71. The exit status is reported in the adress referred to by Status. It should
  72. be a longint.
  73. }
  74. var
  75. regs : SysCallregs;
  76. begin
  77. regs.reg2:=pid;
  78. regs.reg3:=longint(status);
  79. regs.reg4:=options;
  80. WaitPid:=SysCall(SysCall_nr_waitpid,regs);
  81. LinuxError:=errno;
  82. end;
  83. Procedure GetTimeOfDay(var tv:timeval);
  84. {
  85. Get the number of seconds since 00:00, January 1 1970, GMT
  86. the time NOT corrected any way
  87. }
  88. var
  89. regs : SysCallregs;
  90. begin
  91. regs.reg2:=longint(@tv);
  92. regs.reg3:=0;
  93. SysCall(SysCall_nr_gettimeofday,regs);
  94. LinuxError:=Errno;
  95. end;
  96. Function GetPriority(Which,Who:Integer):integer;
  97. {
  98. Get Priority of process, process group, or user.
  99. Which : selects what kind of priority is used.
  100. can be one of the following predefined Constants :
  101. Prio_User.
  102. Prio_PGrp.
  103. Prio_Process.
  104. Who : depending on which, this is , respectively :
  105. Uid
  106. Pid
  107. Process Group id
  108. Errors are reported in linuxerror _only_. (priority can be negative)
  109. }
  110. var
  111. sr : Syscallregs;
  112. begin
  113. errno:=0;
  114. if (which<prio_process) or (which>prio_user) then
  115. begin
  116. { We can save an interrupt here }
  117. getpriority:=0;
  118. linuxerror:=Sys_einval;
  119. end
  120. else
  121. begin
  122. sr.reg2:=which;
  123. sr.reg3:=who;
  124. getpriority:=SysCall(Syscall_nr_getpriority,sr);
  125. linuxerror:=errno;
  126. end;
  127. end;
  128. Procedure SetPriority(Which:Integer;Who:Integer;What:Integer);
  129. {
  130. Set Priority of process, process group, or user.
  131. Which : selects what kind of priority is used.
  132. can be one of the following predefined Constants :
  133. Prio_User.
  134. Prio_PGrp.
  135. Prio_Process.
  136. Who : depending on value of which, this is, respectively :
  137. Uid
  138. Pid
  139. Process Group id
  140. what : A number between -20 and 20. -20 is most favorable, 20 least.
  141. 0 is the default.
  142. }
  143. var
  144. sr : Syscallregs;
  145. begin
  146. errno:=0;
  147. if ((which<prio_process) or (which>prio_user)) or ((what<-20) or (what>20)) then
  148. linuxerror:=Sys_einval { We can save an interrupt here }
  149. else
  150. begin
  151. sr.reg2:=which;
  152. sr.reg3:=who;
  153. sr.reg4:=what;
  154. SysCall(Syscall_nr_setpriority,sr);
  155. linuxerror:=errno;
  156. end;
  157. end;
  158. Procedure Nice(N:integer);
  159. {
  160. Set process priority. A positive N means a lower priority.
  161. A negative N decreases priority.
  162. }
  163. var
  164. sr : Syscallregs;
  165. begin
  166. sr.reg2:=n;
  167. SysCall(Syscall_nr_nice,sr);
  168. linuxerror:=errno;
  169. end;
  170. Function GetPid:LongInt;
  171. {
  172. Get Process ID.
  173. }
  174. var
  175. regs : SysCallregs;
  176. begin
  177. GetPid:=SysCall(SysCall_nr_getpid,regs);
  178. linuxerror:=errno;
  179. end;
  180. Function GetPPid:LongInt;
  181. {
  182. Get Process ID of parent process.
  183. }
  184. var
  185. regs : SysCallregs;
  186. begin
  187. GetPpid:=SysCall(SysCall_nr_getppid,regs);
  188. linuxerror:=errno;
  189. end;
  190. Function GetUid:Longint;
  191. {
  192. Get User ID.
  193. }
  194. var
  195. regs : SysCallregs;
  196. begin
  197. GetUid:=SysCall(SysCall_nr_getuid,regs);
  198. Linuxerror:=errno;
  199. end;
  200. Function GetEUid:Longint;
  201. {
  202. Get _effective_ User ID.
  203. }
  204. var
  205. regs : SysCallregs;
  206. begin
  207. GetEuid:=SysCall(SysCall_nr_geteuid,regs);
  208. Linuxerror:=errno;
  209. end;
  210. Function GetGid:Longint;
  211. {
  212. Get Group ID.
  213. }
  214. var
  215. regs : SysCallregs;
  216. begin
  217. Getgid:=SysCall(SysCall_nr_getgid,regs);
  218. Linuxerror:=errno;
  219. end;
  220. Function GetEGid:Longint;
  221. {
  222. Get _effective_ Group ID.
  223. }
  224. var
  225. regs : SysCallregs;
  226. begin
  227. GetEgid:=SysCall(SysCall_nr_getegid,regs);
  228. Linuxerror:=errno;
  229. end;
  230. Function GetTimeOfDay: longint;
  231. {
  232. Get the number of seconds since 00:00, January 1 1970, GMT
  233. the time NOT corrected any way
  234. }
  235. var
  236. regs : SysCallregs;
  237. tv : timeval;
  238. begin
  239. regs.reg2:=longint(@tv);
  240. regs.reg3:=0;
  241. SysCall(SysCall_nr_gettimeofday,regs);
  242. LinuxError:=Errno;
  243. GetTimeOfDay:=tv.sec;
  244. end;
  245. Function fdTruncate(fd,size:longint):boolean;
  246. var
  247. Regs : SysCallRegs;
  248. begin
  249. Regs.reg2:=fd;
  250. Regs.reg3:=size;
  251. fdTruncate:=(SysCall(Syscall_nr_ftruncate,regs)=0);
  252. LinuxError:=Errno;
  253. end;
  254. Function fdFlush (fd : Longint) : Boolean;
  255. var
  256. SR: SysCallRegs;
  257. begin
  258. SR.reg2 := fd;
  259. fdFlush := (SysCall(syscall_nr_fsync, SR)=0);
  260. LinuxError:=Errno;
  261. end;
  262. Function Fcntl(Fd:longint;Cmd:integer):integer;
  263. {
  264. Read or manipulate a file.(See also fcntl (2) )
  265. Possible values for Cmd are :
  266. F_GetFd,F_GetFl,F_GetOwn
  267. Errors are reported in Linuxerror;
  268. If Cmd is different from the allowed values, linuxerror=Sys_eninval.
  269. }
  270. var
  271. sr : Syscallregs;
  272. begin
  273. if (cmd in [F_GetFd,F_GetFl,F_GetOwn]) then
  274. begin
  275. sr.reg2:=Fd;
  276. sr.reg3:=cmd;
  277. Linuxerror:=SysCall(Syscall_nr_fcntl,sr);
  278. if linuxerror=-1 then
  279. begin
  280. linuxerror:=errno;
  281. fcntl:=0;
  282. end
  283. else
  284. begin
  285. fcntl:=linuxerror;
  286. linuxerror:=0;
  287. end;
  288. end
  289. else
  290. begin
  291. linuxerror:=Sys_einval;
  292. Fcntl:=0;
  293. end;
  294. end;
  295. Procedure Fcntl(Fd:longint;Cmd:Integer;Arg:Longint);
  296. {
  297. Read or manipulate a file. (See also fcntl (2) )
  298. Possible values for Cmd are :
  299. F_setFd,F_SetFl,F_GetLk,F_SetLk,F_SetLkW,F_SetOwn;
  300. Errors are reported in Linuxerror;
  301. If Cmd is different from the allowed values, linuxerror=Sys_eninval.
  302. F_DupFD is not allowed, due to the structure of Files in Pascal.
  303. }
  304. var
  305. sr : Syscallregs;
  306. begin
  307. if (cmd in [F_SetFd,F_SetFl,F_GetLk,F_SetLk,F_SetLkw,F_SetOwn]) then
  308. begin
  309. sr.reg2:=Fd;
  310. sr.reg3:=cmd;
  311. sr.reg4:=arg;
  312. SysCall(Syscall_nr_fcntl,sr);
  313. linuxerror:=errno;
  314. end
  315. else
  316. linuxerror:=Sys_einval;
  317. end;
  318. Function Chmod(path:pathstr;Newmode:longint):Boolean;
  319. {
  320. Changes the permissions of a file.
  321. }
  322. var
  323. sr : Syscallregs;
  324. begin
  325. path:=path+#0;
  326. sr.reg2:=longint(@(path[1]));
  327. sr.reg3:=newmode;
  328. Chmod:=(SysCall(Syscall_nr_chmod,sr)=0);
  329. linuxerror:=errno;
  330. end;
  331. Function Chown(path:pathstr;NewUid,NewGid:longint):boolean;
  332. {
  333. Change the owner and group of a file.
  334. A user can only change the group to a group of which he is a member.
  335. The super-user can change uid and gid of any file.
  336. }
  337. var
  338. sr : Syscallregs;
  339. begin
  340. path:=path+#0;
  341. sr.reg2:=longint(@(path[1]));
  342. sr.reg3:=newuid;
  343. sr.reg4:=newgid;
  344. ChOwn:=(Syscall(Syscall_nr_chown,sr)=0);
  345. linuxerror:=errno;
  346. end;
  347. Function Utime(path:pathstr;utim:utimebuf):boolean;
  348. var
  349. sr : Syscallregs;
  350. begin
  351. path:=path+#0;
  352. sr.reg2:=longint(@(path[1]));
  353. sr.reg3:=longint(@utim);
  354. Utime:=SysCall(Syscall_nr_utime,sr)=0;
  355. linuxerror:=errno;
  356. end;
  357. Function Flock (fd,mode : longint) : boolean;
  358. var
  359. sr : Syscallregs;
  360. begin
  361. sr.reg2:=fd;
  362. sr.reg3:=mode;
  363. flock:=Syscall(Syscall_nr_flock,sr)=0;
  364. LinuxError:=errno;
  365. end;
  366. Function Fstat(Fd:Longint;var Info:stat):Boolean;
  367. {
  368. Get all information on a file descriptor, and return it in info.
  369. }
  370. var
  371. regs : SysCallregs;
  372. begin
  373. regs.reg2:=Fd;
  374. regs.reg3:=longint(@Info);
  375. FStat:=(SysCall(SysCall_nr_fstat,regs)=0);
  376. LinuxError:=Errno;
  377. end;
  378. Function Lstat(Filename: PathStr;var Info:stat):Boolean;
  379. {
  380. Get all information on a link (the link itself), and return it in info.
  381. }
  382. var
  383. regs : SysCallregs;
  384. begin
  385. FileName:=FileName+#0;
  386. regs.reg2:=longint(@filename[1]);
  387. regs.reg3:=longint(@Info);
  388. LStat:=(SysCall(SysCall_nr_lstat,regs)=0);
  389. LinuxError:=Errno;
  390. end;
  391. Function StatFS(Path:Pathstr;Var Info:tstatfs):Boolean;
  392. {
  393. Get all information on a fileSystem, and return it in Info.
  394. Path is the name of a file/directory on the fileSystem you wish to
  395. investigate.
  396. }
  397. var
  398. regs : SysCallregs;
  399. begin
  400. path:=path+#0;
  401. regs.reg2:=longint(@path[1]);
  402. regs.reg3:=longint(@Info);
  403. StatFS:=(SysCall(SysCall_nr_statfs,regs)=0);
  404. LinuxError:=errno;
  405. end;
  406. Function StatFS(Fd:Longint;Var Info:tstatfs):Boolean;
  407. {
  408. Get all information on a fileSystem, and return it in Info.
  409. Fd is the file descriptor of a file/directory on the fileSystem
  410. you wish to investigate.
  411. }
  412. var
  413. regs : SysCallregs;
  414. begin
  415. regs.reg2:=Fd;
  416. regs.reg3:=longint(@Info);
  417. StatFS:=(SysCall(SysCall_nr_fstatfs,regs)=0);
  418. LinuxError:=errno;
  419. end;
  420. Function Link(OldPath,NewPath:pathstr):boolean;
  421. {
  422. Proceduces a hard link from new to old.
  423. In effect, new will be the same file as old.
  424. }
  425. var
  426. regs : SysCallregs;
  427. begin
  428. oldpath:=oldpath+#0;
  429. newpath:=newpath+#0;
  430. regs.reg2:=longint(@oldpath[1]);
  431. regs.reg3:=longint(@newpath[1]);
  432. Link:=SysCall(SysCall_nr_link,regs)=0;
  433. linuxerror:=errno;
  434. end;
  435. Function Umask(Mask:Integer):integer;
  436. {
  437. Sets file creation mask to (Mask and 0777 (octal) ), and returns the
  438. previous value.
  439. }
  440. var
  441. sr : Syscallregs;
  442. begin
  443. sr.reg2:=mask;
  444. Umask:=SysCall(Syscall_nr_umask,sr);
  445. linuxerror:=0;
  446. end;
  447. Function Access(Path:Pathstr ;mode:integer):boolean;
  448. {
  449. Test users access rights on the specified file.
  450. Mode is a mask xosisting of one or more of R_OK, W_OK, X_OK, F_OK.
  451. R,W,X stand for read,write and Execute access, simultaneously.
  452. F_OK checks whether the test would be allowed on the file.
  453. i.e. It checks the search permissions in all directory components
  454. of the path.
  455. The test is done with the real user-ID, instead of the effective.
  456. If access is denied, or an error occurred, false is returned.
  457. If access is granted, true is returned.
  458. Errors other than no access,are reported in linuxerror.
  459. }
  460. var
  461. sr : Syscallregs;
  462. begin
  463. path:=path+#0;
  464. sr.reg2:=longint(@(path[1]));
  465. sr.reg3:=mode;
  466. access:=(SysCall(Syscall_nr_access,sr)=0);
  467. linuxerror:=errno;
  468. end;
  469. Function Dup(oldfile:longint;var newfile:longint):Boolean;
  470. {
  471. Copies the filedescriptor oldfile to newfile
  472. }
  473. var
  474. sr : Syscallregs;
  475. begin
  476. sr.reg2:=oldfile;
  477. newfile:=Syscall(Syscall_nr_dup,sr);
  478. linuxerror:=errno;
  479. Dup:=(LinuxError=0);
  480. end;
  481. Function Dup2(oldfile,newfile:longint):Boolean;
  482. {
  483. Copies the filedescriptor oldfile to newfile
  484. }
  485. var
  486. sr : Syscallregs;
  487. begin
  488. sr.reg2:=oldfile;
  489. sr.reg3:=newfile;
  490. SysCall(Syscall_nr_dup2,sr);
  491. linuxerror:=errno;
  492. Dup2:=(LinuxError=0);
  493. end;
  494. Function Select(N:longint;readfds,writefds,exceptfds:PFDSet;TimeOut:PTimeVal):longint;
  495. {
  496. Select checks whether the file descriptor sets in readfs/writefs/exceptfs
  497. have changed.
  498. }
  499. Var
  500. SelectArray : Array[1..5] of longint;
  501. Sr : Syscallregs;
  502. begin
  503. SelectArray[1]:=n;
  504. SelectArray[2]:=longint(Readfds);
  505. Selectarray[3]:=longint(Writefds);
  506. selectarray[4]:=longint(exceptfds);
  507. Selectarray[5]:=longint(TimeOut);
  508. sr.reg2:=longint(@selectarray);
  509. Select:=SysCall(Syscall_nr_select,sr);
  510. LinuxError:=Errno;
  511. end;
  512. Function AssignPipe(var pipe_in,pipe_out:longint):boolean;
  513. {
  514. Sets up a pair of file variables, which act as a pipe. The first one can
  515. be read from, the second one can be written to.
  516. If the operation was unsuccesful, linuxerror is set.
  517. }
  518. var
  519. pip : tpipe;
  520. regs : SysCallregs;
  521. begin
  522. regs.reg2:=longint(@pip);
  523. SysCall(SysCall_nr_pipe,regs);
  524. pipe_in:=pip[1];
  525. pipe_out:=pip[2];
  526. linuxerror:=errno;
  527. AssignPipe:=(LinuxError=0);
  528. end;
  529. Function PClose(Var F:text) :longint;
  530. var
  531. sr : syscallregs;
  532. pl : ^longint;
  533. res : longint;
  534. begin
  535. sr.reg2:=Textrec(F).Handle;
  536. SysCall (syscall_nr_close,sr);
  537. { closed our side, Now wait for the other - this appears to be needed ?? }
  538. pl:=@(textrec(f).userdata[2]);
  539. waitpid(pl^,@res,0);
  540. pclose:=res shr 8;
  541. end;
  542. Function PClose(Var F:file) : longint;
  543. var
  544. sr : syscallregs;
  545. pl : ^longint;
  546. res : longint;
  547. begin
  548. sr.reg2:=FileRec(F).Handle;
  549. SysCall (Syscall_nr_close,sr);
  550. { closed our side, Now wait for the other - this appears to be needed ?? }
  551. pl:=@(filerec(f).userdata[2]);
  552. waitpid(pl^,@res,0);
  553. pclose:=res shr 8;
  554. end;
  555. Function Sysinfo(var Info:TSysinfo):Boolean;
  556. {
  557. Get system info
  558. }
  559. var
  560. regs : SysCallregs;
  561. Begin
  562. regs.reg2:=longint(@info);
  563. Sysinfo:=SysCall(SysCall_nr_Sysinfo,regs)=0;
  564. End;
  565. Function mkFifo(pathname:string;mode:longint):boolean;
  566. var
  567. regs : SysCallRegs;
  568. begin
  569. pathname:=pathname+#0;
  570. regs.reg2:=longint(@pathname[1]);
  571. regs.reg3:=mode or STAT_IFIFO;
  572. regs.reg4:=0;
  573. mkFifo:=(SysCall(syscall_nr_mknod,regs)=0);
  574. end;
  575. Function Uname(var unamerec:utsname):Boolean;
  576. {
  577. Get machine's names
  578. }
  579. var
  580. regs : SysCallregs;
  581. Begin
  582. regs.reg2:=longint(@unamerec);
  583. Uname:=SysCall(SysCall_nr_uname,regs)=0;
  584. LinuxError:=Errno;
  585. End;
  586. Function Kill(Pid:longint;Sig:longint):integer;
  587. {
  588. Send signal 'sig' to a process, or a group of processes.
  589. If Pid > 0 then the signal is sent to pid
  590. pid=-1 to all processes except process 1
  591. pid < -1 to process group -pid
  592. Return value is zero, except for case three, where the return value
  593. is the number of processes to which the signal was sent.
  594. }
  595. var
  596. regs : Syscallregs;
  597. begin
  598. regs.reg2:=Pid;
  599. regs.reg3:=Sig;
  600. kill:=SysCall(Syscall_nr_kill,regs);
  601. if kill<0 then
  602. Kill:=0;
  603. linuxerror:=errno;
  604. end;
  605. Procedure SigProcMask(How:longint;SSet,OldSSet:PSigSet);
  606. {
  607. Change the list of currently blocked signals.
  608. How determines which signals will be blocked :
  609. SigBlock : Add SSet to the current list of blocked signals
  610. SigUnBlock : Remove the signals in SSet from the list of blocked signals.
  611. SigSetMask : Set the list of blocked signals to SSet
  612. if OldSSet is non-null, the old set will be saved there.
  613. }
  614. Var
  615. sr : SyscallRegs;
  616. begin
  617. sr.reg2:=how;
  618. sr.reg3:=longint(SSet);
  619. sr.reg4:=longint(OldSSet);
  620. SysCall(Syscall_nr_sigprocmask,sr);
  621. linuxerror:=errno;
  622. end;
  623. Function SigPending:SigSet;
  624. {
  625. Allows examination of pending signals. The signal mask of pending
  626. signals is set in SSet
  627. }
  628. Var
  629. sr : SyscallRegs;
  630. dummy : Sigset;
  631. begin
  632. sr.reg2:=longint(@dummy);
  633. SysCall(Syscall_nr_sigpending,sr);
  634. linuxerror:=errno;
  635. Sigpending:=dummy;
  636. end;
  637. Procedure SigSuspend(Mask:Sigset);
  638. {
  639. Set the signal mask with Mask, and suspend the program until a signal
  640. is received.
  641. }
  642. Var
  643. sr : SyscallRegs;
  644. begin
  645. sr.reg2:=mask;
  646. SysCall(Syscall_nr_sigsuspend,sr);
  647. linuxerror:=errno;
  648. end;
  649. Function Signal(Signum:longint;Handler:SignalHandler):SignalHandler;
  650. {
  651. Install a new handler for signal Signum.
  652. The old signal handler is returned.
  653. This call does, in fact, the same as SigAction.
  654. }
  655. var
  656. sr : Syscallregs;
  657. begin
  658. sr.reg2:=signum;
  659. sr.reg3:=longint(handler);
  660. Linuxerror:=SysCall(Syscall_nr_signal,sr);
  661. If linuxerror=Sig_Err then
  662. begin
  663. Signal:=nil;
  664. Linuxerror:=errno;
  665. end
  666. else
  667. begin
  668. Signal:=signalhandler(Linuxerror);
  669. linuxerror:=0;
  670. end;
  671. end;
  672. Function Alarm(Sec : Longint) : longint;
  673. Var Sr : Syscallregs;
  674. begin
  675. sr.reg2:=Sec;
  676. Alarm:=Syscall(syscall_nr_alarm,sr);
  677. end;
  678. Procedure Pause;
  679. Var Sr : Syscallregs;
  680. begin
  681. syscall(syscall_nr_pause,sr);
  682. end;
  683. Function NanoSleep(const req : timespec;var rem : timespec) : longint;
  684. var Sr : Syscallregs;
  685. begin
  686. sr.reg2:=longint(@req);
  687. sr.reg3:=longint(@rem);
  688. NanoSleep:=Syscall(syscall_nr_nanosleep,sr);
  689. LinuxError:=Errno;
  690. end;
  691. Function IOCtl(Handle,Ndx: Longint;Data: Pointer):boolean;
  692. {
  693. Interface to Unix ioctl call.
  694. Performs various operations on the filedescriptor Handle.
  695. Ndx describes the operation to perform.
  696. Data points to data needed for the Ndx function. The structure of this
  697. data is function-dependent.
  698. }
  699. var
  700. sr: SysCallRegs;
  701. begin
  702. sr.reg2:=Handle;
  703. sr.reg3:=Ndx;
  704. sr.reg4:=Longint(Data);
  705. IOCtl:=(SysCall(Syscall_nr_ioctl,sr)=0);
  706. LinuxError:=Errno;
  707. end;
  708. function MMap(const m:tmmapargs):longint;
  709. Var
  710. Sr : Syscallregs;
  711. begin
  712. Sr.reg2:=longint(@m);
  713. MMap:=syscall(syscall_nr_mmap,sr);
  714. LinuxError:=Errno;
  715. end;
  716. function MUnMap (P : Pointer; Size : Longint) : Boolean;
  717. Var
  718. Sr : Syscallregs;
  719. begin
  720. Sr.reg2:=longint(P);
  721. sr.reg3:=Size;
  722. MUnMap:=syscall(syscall_nr_munmap,sr)=0;
  723. LinuxError:=Errno;
  724. end;
  725. {--------------------------------
  726. Port IO functions
  727. --------------------------------}
  728. Function IOperm (From,Num : Cardinal; Value : Longint) : boolean;
  729. {
  730. Set permissions on NUM ports starting with port FROM to VALUE
  731. this works ONLY as root.
  732. }
  733. Var
  734. Sr : Syscallregs;
  735. begin
  736. Sr.Reg2:=From;
  737. Sr.Reg3:=Num;
  738. Sr.Reg4:=Value;
  739. IOPerm:=Syscall(Syscall_nr_ioperm,sr)=0;
  740. LinuxError:=Errno;
  741. end;
  742. Function IoPL(Level : longint) : Boolean;
  743. Var
  744. Sr : Syscallregs;
  745. begin
  746. Sr.Reg2:=Level;
  747. IOPL:=Syscall(Syscall_nr_iopl,sr)=0;
  748. LinuxError:=Errno;
  749. end;
  750. {
  751. $Log$
  752. Revision 1.5 2001-10-14 13:33:20 peter
  753. * start of thread support for linux
  754. Revision 1.4 2001/07/15 11:57:16 peter
  755. * merged m68k updates
  756. Revision 1.3 2001/06/03 20:19:09 peter
  757. * FSStat to StatFS
  758. * StatFS structure to TStatFS
  759. Revision 1.2 2001/06/02 00:31:30 peter
  760. * merge unix updates from the 1.0 branch, mostly related to the
  761. solaris target
  762. Revision 1.6 2001/01/22 07:25:10 marco
  763. * IOPERM for FreeBSD. Port routines moved from unixsysc to Unix again .
  764. Revision 1.5 2000/12/28 20:50:04 peter
  765. * merged fixes from 1.0.x
  766. Revision 1.4 2000/10/26 22:51:12 peter
  767. * nano sleep (merged)
  768. Revision 1.3 2000/10/02 17:57:37 peter
  769. * removed warning (merged)
  770. Revision 1.2 2000/09/18 13:14:50 marco
  771. * Global Linux +bsd to (rtl/freebsd rtl/unix rtl/linux structure)
  772. Revision 1.4 2000/09/12 08:51:43 marco
  773. * fixed some small problems left from merging. (waitpid has now last param longint)
  774. Revision 1.3 2000/09/11 14:05:31 marco
  775. * FreeBSD support and removed old signalhandling
  776. Revision 1.2 2000/07/13 11:33:48 michael
  777. + removed logs
  778. }