linsysca.inc 20 KB

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